Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d219487de | ||
|
|
056634f629 | ||
|
|
a108f5f48a | ||
|
|
d0f2354715 | ||
|
|
c0ef5009ea | ||
|
|
c49a187f2c | ||
|
|
f772e3c196 | ||
|
|
da0a0c2766 | ||
|
|
7081ce37a3 | ||
|
|
e88e9c2472 | ||
|
|
a7a368edcc | ||
|
|
8f3406e758 | ||
|
|
69b1396d13 | ||
|
|
4de5538488 | ||
|
|
bc7932c6d9 | ||
|
|
8116f9fb3b | ||
|
|
73df298c25 | ||
|
|
da91e39d2a | ||
|
|
60ee29a0a2 | ||
|
|
d2f0f067b3 | ||
|
|
0c0815e1b0 | ||
|
|
609d4e7182 | ||
|
|
5374d3eba5 | ||
|
|
9904f4aaca | ||
|
|
7506a870d5 | ||
|
|
3544f40e36 | ||
|
|
0dd7d6ef10 | ||
|
|
02ed5c5894 | ||
|
|
d1807c59a0 | ||
|
|
2af16b6f4d | ||
|
|
ca78e34c1b | ||
|
|
f5056049eb | ||
|
|
89667f38b5 | ||
|
|
6d8418880d | ||
|
|
46f8594201 | ||
|
|
9f55e4b051 | ||
|
|
445e61a9fe | ||
|
|
f2e054ade6 | ||
|
|
844fb2f055 | ||
|
|
6677d6d200 | ||
|
|
f3cfb737b0 | ||
|
|
5a883a0498 | ||
|
|
e512ed1021 | ||
|
|
9b02d74fb1 | ||
|
|
4ec73938b4 | ||
|
|
f38d20540f | ||
|
|
8ee317e8c4 | ||
|
|
302373e19c | ||
|
|
b33b3f7c7f | ||
|
|
af97716d28 | ||
|
|
0c5f5fcdba | ||
|
|
8ed16aee0b | ||
|
|
9971d2ae59 | ||
|
|
503bc5b542 | ||
|
|
c4a67297a7 | ||
|
|
859a78b188 | ||
|
|
f2e7ec59de | ||
|
|
f226b4d8bf | ||
|
|
aff82f4fe7 | ||
|
|
5aea307482 | ||
|
|
699743de16 | ||
|
|
aa0e7ba9af | ||
|
|
ff920b38a5 | ||
|
|
40bb300945 | ||
|
|
b6f0ae9e7f | ||
|
|
83498ce838 | ||
|
|
21855a3da9 | ||
|
|
d084586d55 | ||
|
|
c0217f3433 | ||
|
|
ff6848b49e | ||
|
|
ffd6aa805b | ||
|
|
02cfd020f7 | ||
|
|
41e2eb5baa | ||
|
|
3c93529995 | ||
|
|
0b73dbe0a8 | ||
|
|
707ad17538 | ||
|
|
b28e5b863f | ||
|
|
720aaba3b3 | ||
|
|
6b8fc41404 | ||
|
|
bb1424e868 | ||
|
|
328b3d4162 | ||
|
|
4df4740fa3 | ||
|
|
42d2ff48db | ||
|
|
e38e92c170 | ||
|
|
4e791e2334 | ||
|
|
25c583c9df | ||
|
|
9e7eef14e3 | ||
|
|
a430a5c3ef | ||
|
|
7bd6e7b7ab | ||
|
|
a8312ba3ff | ||
|
|
e1ddac766f | ||
|
|
d65aa2d7f0 | ||
|
|
0346f32c64 | ||
|
|
dfe4634d38 | ||
|
|
b68ffb3e81 | ||
|
|
ae43f86182 | ||
|
|
d200d4a48a | ||
|
|
bab63923ef | ||
|
|
be14484877 | ||
|
|
db96663439 | ||
|
|
efdf95b44b | ||
|
|
554374dbf9 | ||
|
|
0bc538f588 | ||
|
|
c0943cdfbc | ||
|
|
e5af86d72d | ||
|
|
1f6a03db80 | ||
|
|
5e5007e3a8 | ||
|
|
a9d40ae754 | ||
|
|
e9c4ee8563 | ||
|
|
4e50392f6e | ||
|
|
eeb8fa9c92 | ||
|
|
b9ca8ef337 | ||
|
|
edae652e52 | ||
|
|
4b01edd4be | ||
|
|
12941d38a3 | ||
|
|
8dde0e37ed | ||
|
|
0b3166e8e1 | ||
|
|
cc98c204a8 | ||
|
|
db2f8aefb2 | ||
|
|
29d702b0ab | ||
|
|
1d7dad1eee | ||
|
|
a322812cd8 | ||
|
|
0368bfedf2 | ||
|
|
c2c4667cc5 | ||
|
|
c6b2716b97 | ||
|
|
5a71a36608 | ||
|
|
c05e709be2 | ||
|
|
8cb4042a8d | ||
|
|
4825df37a8 | ||
|
|
59defeea6b | ||
|
|
548c3520a9 | ||
|
|
545568be9b | ||
|
|
dc10fdb69b | ||
|
|
a205d05f10 | ||
|
|
57d84f6bd4 | ||
|
|
8ccc5a70ff | ||
|
|
662877a3da | ||
|
|
1fe8ae791a | ||
|
|
fab7f1d485 | ||
|
|
f9aceeb296 | ||
|
|
d639caf245 | ||
|
|
30fc8252a4 | ||
|
|
8cb8522635 | ||
|
|
306b251863 | ||
|
|
eaa23f51fc | ||
|
|
86866c9dd2 | ||
|
|
c32ca98e09 | ||
|
|
6a9d7aff49 | ||
|
|
18acd2e26d | ||
|
|
991655a05f | ||
|
|
34b5b559a7 | ||
|
|
8e40f809c1 | ||
|
|
c1315b3512 | ||
|
|
c5461f2ea2 | ||
|
|
3179c56263 | ||
|
|
b932ca70c6 | ||
|
|
73ecdadeff | ||
|
|
734fb3114e | ||
|
|
a28a0cef72 | ||
|
|
3339e5179b | ||
|
|
3656a3fcc6 | ||
|
|
1824ca9186 | ||
|
|
61818d7b72 | ||
|
|
70c4501e74 | ||
|
|
c607e83079 | ||
|
|
363122c862 | ||
|
|
1f98e6be91 | ||
|
|
eed69eb8b1 | ||
|
|
6e37e2e50d | ||
|
|
4479b7ca95 | ||
|
|
8d3edc7cd1 | ||
|
|
8672dbe1e9 | ||
|
|
b2038e1a45 | ||
|
|
0f3bc68222 | ||
|
|
fe1a33ecfe | ||
|
|
22b90407d8 | ||
|
|
01a14c2b00 | ||
|
|
2bdae8d824 | ||
|
|
5becd549f3 | ||
|
|
fe5997addc | ||
|
|
1bd64b397f | ||
|
|
195f18659d | ||
|
|
d80085a67c | ||
|
|
478cc6b444 | ||
|
|
7b82971699 | ||
|
|
80884a8809 | ||
|
|
16a6b30cd2 | ||
|
|
1efefce08d | ||
|
|
d7f579b308 | ||
|
|
05a7750bd0 | ||
|
|
360fd6d2cc | ||
|
|
c60740092b | ||
|
|
5d494c8435 | ||
|
|
40a2e3a0d4 | ||
|
|
e32be83442 | ||
|
|
3592ee9f61 | ||
|
|
114ac54976 | ||
|
|
444227e44d | ||
|
|
8609c034c8 | ||
|
|
a51231535c | ||
|
|
5a0b9d8aae | ||
|
|
de5d539dac | ||
|
|
4f744ce4d5 | ||
|
|
ea69d4c0d5 | ||
|
|
9073044640 | ||
|
|
a5f857125c | ||
|
|
72bfffbb9f | ||
|
|
6579f7cc1c | ||
|
|
93cf7863b7 | ||
|
|
9fb7a79047 | ||
|
|
5943a1d092 | ||
|
|
c282d5e5bc | ||
|
|
5dac4aa208 | ||
|
|
0281e4e309 | ||
|
|
a50dda6377 | ||
|
|
029e5db6a8 | ||
|
|
f88f865130 | ||
|
|
2dc088cd80 | ||
|
|
829c82cb72 | ||
|
|
6d7ce28d48 | ||
|
|
b2d9da71ca | ||
|
|
a9ba54535c | ||
|
|
e4043736a4 | ||
|
|
84295ac833 | ||
|
|
9b93c799bd | ||
|
|
f64ffb27df | ||
|
|
531b99b0da | ||
|
|
b0edeb61d4 | ||
|
|
9952fcc5f7 | ||
|
|
5049f39989 | ||
|
|
196a143b96 | ||
|
|
a71d5ed8ff | ||
|
|
4f0c4ae303 | ||
|
|
17c01b888a | ||
|
|
95714b1242 | ||
|
|
8eb7d28222 | ||
|
|
87994b0de9 | ||
|
|
aa4ae35791 | ||
|
|
95f18df490 | ||
|
|
414c8e1200 | ||
|
|
14a923ecfb | ||
|
|
53c090b930 | ||
|
|
e94e69c0f5 | ||
|
|
6e51eb3b5b | ||
|
|
d617414612 | ||
|
|
885feb31b0 | ||
|
|
aeea09b6f3 | ||
|
|
22a68c2ec6 | ||
|
|
17688937c1 | ||
|
|
ea4f9f5451 | ||
|
|
b6e7be15f6 | ||
|
|
aa0249e991 | ||
|
|
e70ebd8c58 | ||
|
|
62e73027e5 | ||
|
|
009944af47 | ||
|
|
766fc73dbc | ||
|
|
db1fc3494f | ||
|
|
b9ba9db699 | ||
|
|
d59a730ed5 | ||
|
|
500f71356e | ||
|
|
c5e9e2f8e1 | ||
|
|
1c0b9a5852 | ||
|
|
dd037fc674 | ||
|
|
8f20ff4ffa | ||
|
|
34af1d19e4 | ||
|
|
b065db4b5b | ||
|
|
ee05ee2c5a | ||
|
|
0d994dd655 | ||
|
|
50e77d3ba8 | ||
|
|
8a35c08b36 | ||
|
|
531d9343b3 | ||
|
|
aa6f62486c | ||
|
|
9b62c58381 | ||
|
|
ca6ded98d4 | ||
|
|
ef42baef2a | ||
|
|
6d36487268 | ||
|
|
0a27981415 | ||
|
|
a979e30c9f | ||
|
|
cdbed8a07b | ||
|
|
d110eed130 | ||
|
|
93b67ecb29 | ||
|
|
8c776b7185 | ||
|
|
d78832282b | ||
|
|
ae3d07f476 | ||
|
|
3a0bfbde65 | ||
|
|
df108c95d6 | ||
|
|
834d302d5c | ||
|
|
d18859e17d | ||
|
|
b673f4ea10 | ||
|
|
fd4f734544 | ||
|
|
d3c186aa5f | ||
|
|
e3d3289d8d | ||
|
|
8bfa373da9 | ||
|
|
d954ff6981 | ||
|
|
c636cce7af | ||
|
|
658eab7ee7 | ||
|
|
b6b709d1a7 | ||
|
|
74ba580296 | ||
|
|
1ee95181d6 | ||
|
|
ec7828dc65 | ||
|
|
3ea08907c0 | ||
|
|
b63dbfdfa9 | ||
|
|
bdc13f43cb | ||
|
|
c13177b0b4 | ||
|
|
d8b61b8e55 | ||
|
|
a74d9d9ca8 | ||
|
|
db5dadab6e | ||
|
|
1849ad518a | ||
|
|
aced9c8289 | ||
|
|
4f498e6d56 | ||
|
|
3c71929fcf | ||
|
|
8923101152 | ||
|
|
d85d1111f0 | ||
|
|
03e8881e68 | ||
|
|
6d2ca76676 | ||
|
|
488eee94c9 | ||
|
|
16e3d3020e | ||
|
|
ac881c01d3 | ||
|
|
cf17437603 | ||
|
|
db356dcc53 | ||
|
|
561b273cb9 | ||
|
|
bdcc6d2964 | ||
|
|
989c9b9fde | ||
|
|
c3d005faba | ||
|
|
6c84f5f497 | ||
|
|
489ebd4339 | ||
|
|
933b910c21 | ||
|
|
c640189041 | ||
|
|
9b2287ab50 | ||
|
|
ae043ca6ce | ||
|
|
38f6eb000f | ||
|
|
8a372c1454 | ||
|
|
868b6df40f | ||
|
|
b54021e35f | ||
|
|
5b7efa9f1f | ||
|
|
f587b597b2 | ||
|
|
5289e70e29 | ||
|
|
13dd4cc16a | ||
|
|
d33f2c6ac9 | ||
|
|
c18d94a228 | ||
|
|
ca9aeee6d5 | ||
|
|
e92941d296 | ||
|
|
792899035d | ||
|
|
915109c761 | ||
|
|
8a4dcca002 | ||
|
|
0eee4e04ff | ||
|
|
15ebd6913a | ||
|
|
3347513e2b | ||
|
|
bbcef8eb09 | ||
|
|
16e5150bd0 | ||
|
|
1127925ada | ||
|
|
cd23312bce | ||
|
|
adf43c7c40 | ||
|
|
3d36361a8d | ||
|
|
dbfbe652d3 | ||
|
|
a87f5428da | ||
|
|
12c8bdf5cd | ||
|
|
7b1c576eb7 | ||
|
|
3ec85b6f52 | ||
|
|
a39b86edf0 | ||
|
|
cf83806759 | ||
|
|
304d78526e | ||
|
|
9acfd6bce9 | ||
|
|
515e419968 | ||
|
|
54a10bfd70 | ||
|
|
909e930a2b | ||
|
|
970ca14155 | ||
|
|
7a96f53efc | ||
|
|
023ef7d753 | ||
|
|
b679c7f322 | ||
|
|
ed8f2841ad | ||
|
|
f612caa518 | ||
|
|
056993cf2c | ||
|
|
a106d2f7f2 | ||
|
|
2a2633359a | ||
|
|
3c23b82edb | ||
|
|
daaa653331 | ||
|
|
8fccae365f | ||
|
|
d2ecfb4f14 | ||
|
|
c58c65147d | ||
|
|
b0c9b1179f | ||
|
|
44b780660f | ||
|
|
a1d817648b | ||
|
|
e02eebcc4a | ||
|
|
757adaf957 | ||
|
|
96f001d4c4 | ||
|
|
b775eb9d6a | ||
|
|
c204cb5df9 | ||
|
|
5dbd05151e | ||
|
|
19d4079272 | ||
|
|
b7c25c4494 | ||
|
|
33e64c1e06 | ||
|
|
fa4d9310b5 | ||
|
|
2e3ee38846 | ||
|
|
99f79cfc63 | ||
|
|
b7ebbc8a8b | ||
|
|
b25d8b01a0 | ||
|
|
4b9fdbad7b | ||
|
|
5ca2fcece1 | ||
|
|
8dee6466fd | ||
|
|
6ec10d6f6f | ||
|
|
fc8c6d9955 | ||
|
|
3a5565d508 | ||
|
|
1be4a8727f | ||
|
|
ae57a7a14e | ||
|
|
220047ffc7 | ||
|
|
7339892d04 | ||
|
|
eb48575598 | ||
|
|
a26831e111 | ||
|
|
75ad31f1c8 | ||
|
|
b334cdb7e8 | ||
|
|
1b5bd8a4c6 | ||
|
|
029b447dd6 | ||
|
|
15c13b891c | ||
|
|
db535ecfa6 | ||
|
|
6387db168b | ||
|
|
ce38dceac7 | ||
|
|
9a10a8d261 | ||
|
|
3eaf195d08 | ||
|
|
cb68b386c0 | ||
|
|
3d71436761 | ||
|
|
7046af553e | ||
|
|
12e9ef8857 | ||
|
|
e5f4fada09 | ||
|
|
7394aac8c5 | ||
|
|
f94f578a2e | ||
|
|
8d11271313 | ||
|
|
08927453c5 | ||
|
|
6e6f97a56a | ||
|
|
8d752087fa | ||
|
|
b5afb6587e | ||
|
|
f10937dea9 | ||
|
|
f4b24a18a9 | ||
|
|
7a864b319f | ||
|
|
91f42f99c1 | ||
|
|
40d64bffab | ||
|
|
e0e5b9e26a | ||
|
|
dd863c9219 | ||
|
|
d082e424be | ||
|
|
4eaddec411 | ||
|
|
14fab1f56c | ||
|
|
24d05f837a | ||
|
|
057125aa17 | ||
|
|
b5945ac395 | ||
|
|
4ab9cf1563 | ||
|
|
c0df8f7ccc | ||
|
|
b61a4f7a9f | ||
|
|
fa86a62356 | ||
|
|
6243c27b08 | ||
|
|
bf06767488 | ||
|
|
8e100ea4f2 | ||
|
|
143ab31813 | ||
|
|
dfe8ebfe1b | ||
|
|
84b47b37e2 | ||
|
|
3111e6c6e6 | ||
|
|
b6f792ac4c | ||
|
|
2723f3e96f | ||
|
|
bacc1146e1 | ||
|
|
1ab6cae96c | ||
|
|
57dbe3a256 | ||
|
|
e59b60fe0e | ||
|
|
deb34beb40 | ||
|
|
a43ed35eb7 | ||
|
|
adaf4fd380 | ||
|
|
566b3e679f | ||
|
|
90c42dc51d | ||
|
|
93877846fe | ||
|
|
0b6702c198 | ||
|
|
ef7b373d1f | ||
|
|
421802fd3c | ||
|
|
52c7f70023 | ||
|
|
4d024c25a2 | ||
|
|
7a9e561742 | ||
|
|
bfd1460ed1 | ||
|
|
3e068129bb | ||
|
|
6a6006d525 | ||
|
|
5d72609ac6 | ||
|
|
18e9aa59a9 | ||
|
|
8a00390750 | ||
|
|
2676abe4e7 | ||
|
|
8086087fb4 | ||
|
|
7c2344460f | ||
|
|
371df596a9 | ||
|
|
13731f5771 | ||
|
|
4dd5c778ac | ||
|
|
e44706852c | ||
|
|
79df1dc916 | ||
|
|
dafec31632 | ||
|
|
a9be3d913d | ||
|
|
c14d1833b1 | ||
|
|
7ce3e471a2 | ||
|
|
402dfebcf0 | ||
|
|
321b8cfc1b | ||
|
|
2035213246 | ||
|
|
1a490c5919 | ||
|
|
3e2ac93424 | ||
|
|
aaf1a718a5 | ||
|
|
18c29daf92 | ||
|
|
13b13b03e0 | ||
|
|
39c60f42fd | ||
|
|
01a809a5c7 | ||
|
|
f89a7e8853 | ||
|
|
9441582aa3 | ||
|
|
804dedf1c2 | ||
|
|
640b400eca | ||
|
|
b26d81ca08 | ||
|
|
fba350311f | ||
|
|
3b31716cef | ||
|
|
e2cec264a6 | ||
|
|
1224cf7011 | ||
|
|
467e5ee87f | ||
|
|
f9d5769f6f | ||
|
|
b9ae2cd16c | ||
|
|
b116730925 | ||
|
|
bfb119e62d | ||
|
|
e6bf0e28c5 | ||
|
|
3f7516f9a1 | ||
|
|
fda04ba15a | ||
|
|
944d069fa2 | ||
|
|
9c62207ae9 | ||
|
|
260f8c364b | ||
|
|
4428a1da07 | ||
|
|
da882d6f00 | ||
|
|
4a884233c1 | ||
|
|
c3a2d0641a | ||
|
|
82efff8ce5 | ||
|
|
e159faa013 | ||
|
|
1fe1738419 | ||
|
|
e4d6611027 | ||
|
|
719b30a04e | ||
|
|
2c416dcdb9 | ||
|
|
76541cd836 | ||
|
|
67728afd4f | ||
|
|
43ba216bfa | ||
|
|
06b5dbca23 | ||
|
|
7d027fcad0 | ||
|
|
5865e5adfd | ||
|
|
4e5480b5dd | ||
|
|
c4a41562f0 | ||
|
|
0e72c3ca84 | ||
|
|
15a20079dd | ||
|
|
3ccb4e5cea | ||
|
|
e4a88a32a0 | ||
|
|
cb4a104954 | ||
|
|
96946c1bb0 | ||
|
|
6e0ef96ccb | ||
|
|
cefdb0760e | ||
|
|
aeb5a74452 | ||
|
|
1d42c5c9eb | ||
|
|
9120a166c8 | ||
|
|
ab0f2aab15 | ||
|
|
cb8694139e | ||
|
|
dddb88581c | ||
|
|
dcad32bd09 | ||
|
|
47b85966d2 | ||
|
|
e0707e2bb1 | ||
|
|
56401904b2 | ||
|
|
4fdb2a17a5 | ||
|
|
b2941881a7 | ||
|
|
36d3da79a0 | ||
|
|
a3aebc4184 | ||
|
|
988ea2f733 | ||
|
|
ff8bc69591 | ||
|
|
99429c08cd | ||
|
|
857257a1be | ||
|
|
9dccd1ef98 | ||
|
|
556569d110 | ||
|
|
3367530733 | ||
|
|
407cb5f7c9 | ||
|
|
52aa1b99f2 | ||
|
|
e3a61d0ac0 | ||
|
|
372753735c | ||
|
|
bac88eede7 | ||
|
|
0cf489b2ac | ||
|
|
af618bc9db | ||
|
|
1f556792fd | ||
|
|
da70d07443 | ||
|
|
9e1910339b | ||
|
|
b7e67b1ab5 | ||
|
|
404beb2063 | ||
|
|
00da23e6b9 | ||
|
|
793a1a96d2 | ||
|
|
8f1c0eac92 | ||
|
|
2be7649178 | ||
|
|
813e9b7754 | ||
|
|
07114d50b9 | ||
|
|
93049a31e2 | ||
|
|
e5d449a6b2 | ||
|
|
e761d01cf7 | ||
|
|
a0ab1fd3b9 | ||
|
|
69495ed2b6 | ||
|
|
59669b90d4 | ||
|
|
69b41a20bf | ||
|
|
cf252c3ddd | ||
|
|
a1ac6c2dac | ||
|
|
ea0b09ebd6 | ||
|
|
f559751f4e | ||
|
|
3b60148315 | ||
|
|
8d2f2f7435 | ||
|
|
1133dff5ce | ||
|
|
2a4897e0c5 | ||
|
|
758ba7b049 | ||
|
|
fdc470b0c3 | ||
|
|
c747b60bb7 | ||
|
|
a321402556 | ||
|
|
2f7136f257 | ||
|
|
0d133c07c6 | ||
|
|
821d2afcf7 | ||
|
|
a9c0429302 | ||
|
|
4ab42f27f1 | ||
|
|
2695cfdaf0 | ||
|
|
2fc135724f | ||
|
|
0dd6ddf33c | ||
|
|
8a31725361 | ||
|
|
6c19afbf2b | ||
|
|
3d7daf406d | ||
|
|
a83ac83ed3 | ||
|
|
705fc1982e | ||
|
|
e33fd3634d | ||
|
|
02ae146214 | ||
|
|
b39502d801 | ||
|
|
613cea91a3 | ||
|
|
9a8148a179 | ||
|
|
fbf406dccd | ||
|
|
94ec0f15f6 | ||
|
|
ac30edffd6 | ||
|
|
b655454348 | ||
|
|
f53ed8c8e7 | ||
|
|
689aef910f | ||
|
|
f88d6fd844 | ||
|
|
a3e43ebe4e | ||
|
|
070626a046 | ||
|
|
76412d11a0 | ||
|
|
385fe73093 | ||
|
|
002e03b572 | ||
|
|
bb449254b4 | ||
|
|
4cf8c27ac4 | ||
|
|
119d3277a5 | ||
|
|
22ebad5b2f | ||
|
|
4ddc409129 | ||
|
|
3cce97de72 | ||
|
|
921293d39f | ||
|
|
3442c877f8 | ||
|
|
7b3e03b113 | ||
|
|
eddc1421b2 | ||
|
|
88720aadce | ||
|
|
33ab44a039 | ||
|
|
480c5c3eb6 | ||
|
|
1cf338b3e1 | ||
|
|
58839861b8 | ||
|
|
cc590a8b48 | ||
|
|
7ab9e92e15 | ||
|
|
b091fccaad | ||
|
|
0ce7034f01 | ||
|
|
ed3251e7a1 | ||
|
|
2cd3a5b204 | ||
|
|
8f7fdac10e | ||
|
|
abfc76dd5a | ||
|
|
fb5a6dbfd4 | ||
|
|
4a91ab73f9 | ||
|
|
14008da851 | ||
|
|
487002cb5a | ||
|
|
ebc140c6b2 | ||
|
|
72333feb34 | ||
|
|
5d25bbb27f | ||
|
|
61da4838ed | ||
|
|
89fd37e2b4 | ||
|
|
dc3f01468a | ||
|
|
7737849454 | ||
|
|
158379b8f0 | ||
|
|
59846a5864 | ||
|
|
ab11c96f4a | ||
|
|
822473b0cf | ||
|
|
4f40e81f62 | ||
|
|
45af4669a3 | ||
|
|
c7339226d1 | ||
|
|
b8d801acfd | ||
|
|
a7f16ff938 | ||
|
|
c09d235723 | ||
|
|
7513d95130 | ||
|
|
9275ac4d12 | ||
|
|
02c227b304 | ||
|
|
ed2b246494 | ||
|
|
5ddc0373b7 | ||
|
|
a280304776 | ||
|
|
510c7ea69c | ||
|
|
db803f9694 | ||
|
|
d15daa7ad2 | ||
|
|
6ecbc6f41d | ||
|
|
45ea333073 | ||
|
|
e6af56fd4b | ||
|
|
c1ad9209a0 | ||
|
|
7a3d1019af | ||
|
|
98d579fc8a | ||
|
|
2f65e7db48 | ||
|
|
bd2b7db5ab | ||
|
|
5d9497e387 | ||
|
|
469397f096 | ||
|
|
089e880b88 | ||
|
|
9e9bbb9f7b | ||
|
|
2febc01ff4 | ||
|
|
caeeabc735 | ||
|
|
d3b0739a53 | ||
|
|
3628d1d57d | ||
|
|
702fa6fe5c | ||
|
|
a237bac9dc | ||
|
|
98117dae0e | ||
|
|
62eea23a17 | ||
|
|
703fd9d675 | ||
|
|
07230a3d9e | ||
|
|
7fcbc149af | ||
|
|
d7a4193d11 | ||
|
|
9c0eb5f3a9 | ||
|
|
c7bcd29843 | ||
|
|
5dff482920 | ||
|
|
3d3286604a | ||
|
|
341b3c24a4 | ||
|
|
16ec16c6b8 | ||
|
|
416e8bbec6 | ||
|
|
f2260a6ca9 | ||
|
|
2a6e77731b | ||
|
|
635e4b512f | ||
|
|
729fcb4a11 | ||
|
|
60592fcef6 | ||
|
|
cd8df1c4b3 | ||
|
|
173706a43b | ||
|
|
71c13a89a8 | ||
|
|
7d434fe939 | ||
|
|
b49252f333 | ||
|
|
5fa7b95e19 | ||
|
|
1472e39bc8 | ||
|
|
4f7c7e1c4b | ||
|
|
6d40525286 | ||
|
|
7cc3611e4c | ||
|
|
5f29adbd9b | ||
|
|
e078f1f6fa | ||
|
|
4e5e5986cd | ||
|
|
2eb246ab0d | ||
|
|
fd6fd98fdc | ||
|
|
fe297a47b2 | ||
|
|
5d67d48436 | ||
|
|
794c2fa09d | ||
|
|
c5db25f076 | ||
|
|
6f1ad35492 | ||
|
|
5c4d498a99 | ||
|
|
2e3f69b478 | ||
|
|
8e720d1c60 | ||
|
|
5bd3b81099 | ||
|
|
4ea4c74783 | ||
|
|
d25e572ab2 | ||
|
|
f6f4faba27 | ||
|
|
25ba58ffa7 | ||
|
|
54968de248 | ||
|
|
5a52b088ea | ||
|
|
f67ab5bb16 | ||
|
|
9048253c9c | ||
|
|
f25c5a182d | ||
|
|
ecc90b376e | ||
|
|
1789c2361f | ||
|
|
416161e617 | ||
|
|
3836150e42 | ||
|
|
b62dc7e5c9 | ||
|
|
5c50f35570 | ||
|
|
2164f7ae9d | ||
|
|
b791bcefdb | ||
|
|
1e2d76885f | ||
|
|
f0dc66bf2b | ||
|
|
db572c8fea | ||
|
|
7bd0407e70 | ||
|
|
8c77da246c | ||
|
|
487d7956e9 | ||
|
|
e554687392 | ||
|
|
13d1780180 | ||
|
|
0d1e57d393 | ||
|
|
edf5a6f9e8 | ||
|
|
515a59c9de | ||
|
|
a645b61464 | ||
|
|
f6436bce33 | ||
|
|
c9da8742eb | ||
|
|
fd46fc679e | ||
|
|
2ab7c63853 | ||
|
|
fd86561c7f | ||
|
|
1e69cf2e13 | ||
|
|
e7ec8a2174 | ||
|
|
1fe19578c2 | ||
|
|
6e86b1001c | ||
|
|
80e14898be | ||
|
|
e02ce4f898 | ||
|
|
70ca2a0bb8 | ||
|
|
c67ac53447 | ||
|
|
1861d036b9 | ||
|
|
e06626e1b4 | ||
|
|
0c0579a9d3 | ||
|
|
c1c3c1ee16 | ||
|
|
3bcde9f67a | ||
|
|
1558a14a91 | ||
|
|
0335767afa | ||
|
|
6a51116844 | ||
|
|
d440c7c651 | ||
|
|
6bbc36501d | ||
|
|
b65105598a | ||
|
|
36ae3734fb | ||
|
|
ed6bf9f1bb | ||
|
|
a3469a172a | ||
|
|
cf8f809eec | ||
|
|
03890fd329 | ||
|
|
9c21e6dc8e | ||
|
|
fa07af2d82 | ||
|
|
f716c390b9 | ||
|
|
55c4504ed9 | ||
|
|
1838a57e53 | ||
|
|
e7df5d1160 | ||
|
|
bb3f6fe642 | ||
|
|
af0804fd6f | ||
|
|
c12a188196 | ||
|
|
13196941eb | ||
|
|
3110d2cc69 | ||
|
|
2e4439c9f4 | ||
|
|
fea86dc261 | ||
|
|
3b71f6fa0b | ||
|
|
5e122626d4 | ||
|
|
2812f30ac1 | ||
|
|
612614fa12 | ||
|
|
e7680ef80b | ||
|
|
8ea954d4cf | ||
|
|
fff0b4d670 | ||
|
|
5f7a3db441 | ||
|
|
823786f865 | ||
|
|
0661dac099 | ||
|
|
2078ba70bd | ||
|
|
03564b310f | ||
|
|
b16b3110f3 | ||
|
|
72610c03ff | ||
|
|
7a0348536c | ||
|
|
82cd67e3ad | ||
|
|
9d95046c5a | ||
|
|
21bd824bce | ||
|
|
82a78f227d | ||
|
|
908ec04c14 | ||
|
|
305a668799 | ||
|
|
63d918a428 | ||
|
|
029d2c9f33 | ||
|
|
2322999099 | ||
|
|
bd1f69aa6d | ||
|
|
5b1c694447 | ||
|
|
15df8f2a22 | ||
|
|
6542451cbc | ||
|
|
dff93002d0 | ||
|
|
84fbf75f0c | ||
|
|
ea9d114156 | ||
|
|
bd96b4850e | ||
|
|
8bc670b9be | ||
|
|
34b26107c6 | ||
|
|
15db3c9f66 | ||
|
|
4a565b929b | ||
|
|
074af5e8e0 | ||
|
|
a220dad1eb | ||
|
|
cd74792402 | ||
|
|
f1c2198514 | ||
|
|
fd9df5f6ae | ||
|
|
42455bc5e5 | ||
|
|
eec4cf8167 | ||
|
|
16948f451f | ||
|
|
26ef5b10a0 | ||
|
|
3ca7f81ad7 | ||
|
|
72dc1a6b46 | ||
|
|
0540479e09 | ||
|
|
7c30380ca6 | ||
|
|
ef9c3c1eb6 | ||
|
|
f0b381417d | ||
|
|
0bee33efc0 | ||
|
|
d630882f18 | ||
|
|
0721a69345 | ||
|
|
3c4bafd1ad | ||
|
|
097b941580 | ||
|
|
c66310fbe7 | ||
|
|
df4c59cbd6 | ||
|
|
0f7aa0ad49 | ||
|
|
2971fe0679 | ||
|
|
989ac071be | ||
|
|
8b4c5c1d25 | ||
|
|
b39502d806 | ||
|
|
aac384390b | ||
|
|
70d9614fb1 | ||
|
|
793adafe32 | ||
|
|
e521db78ce | ||
|
|
35d8f5a675 | ||
|
|
118ec1bc50 | ||
|
|
24163b2427 | ||
|
|
10506ad521 | ||
|
|
a67360c18a | ||
|
|
c4a92dc3d8 | ||
|
|
545a5324f0 | ||
|
|
abcd5d5839 | ||
|
|
978a4c6f5f | ||
|
|
9e4d9ee35d | ||
|
|
cc2963b765 | ||
|
|
93d51fe499 | ||
|
|
82bab12941 | ||
|
|
e9dba94dd5 | ||
|
|
01060c38c8 | ||
|
|
f5acb27c34 | ||
|
|
1807559987 | ||
|
|
69b2bfb0b9 | ||
|
|
d5d848acd8 | ||
|
|
b75c83901b | ||
|
|
339d2844a7 | ||
|
|
614d9fd7b3 | ||
|
|
0ac261e1bf | ||
|
|
9f6e03fd80 | ||
|
|
43c9f35f3c | ||
|
|
3978c4ae1e | ||
|
|
80093a1998 | ||
|
|
479834cea8 | ||
|
|
60b5f6bac2 | ||
|
|
41ea3ba987 | ||
|
|
6e39a70706 | ||
|
|
102d1f4186 | ||
|
|
09ff29bf3e | ||
|
|
1f2a3b164b | ||
|
|
e2256be4aa | ||
|
|
65d1106974 | ||
|
|
72465317f3 | ||
|
|
4edae9ef5a | ||
|
|
6faca50a19 | ||
|
|
d758fc2d20 | ||
|
|
f1bbac6583 | ||
|
|
a34a5d187b | ||
|
|
34d634a349 | ||
|
|
137b6bc690 | ||
|
|
d3566d896b | ||
|
|
e34c5f9b32 | ||
|
|
d79c4d92f5 | ||
|
|
9935f54080 | ||
|
|
9af2577c6e | ||
|
|
d04f401c90 | ||
|
|
a973a5db0d | ||
|
|
a2e5688ede | ||
|
|
5426aa82c1 | ||
|
|
cd4f3e86cb | ||
|
|
00efbb7244 | ||
|
|
d368e53b30 | ||
|
|
5b11827c56 | ||
|
|
4d3179fc35 | ||
|
|
d686c78fdf | ||
|
|
cf9276540c | ||
|
|
adfb9a2128 | ||
|
|
59fc123f7d | ||
|
|
ce2406992a | ||
|
|
5160f2b48d | ||
|
|
359d87440b | ||
|
|
87ed5d107d | ||
|
|
c0c4db95a4 | ||
|
|
8872adfd95 | ||
|
|
fac3ef15fa | ||
|
|
0587266e22 | ||
|
|
cb4bc16c69 | ||
|
|
c12bdcd042 | ||
|
|
19106f89a8 | ||
|
|
285522d820 | ||
|
|
904b14af19 | ||
|
|
0c78a23c76 | ||
|
|
992b72ee6f | ||
|
|
8bebbdac5d | ||
|
|
0323d4d2f6 | ||
|
|
cadf9ca63b | ||
|
|
b75432ea7c | ||
|
|
b18fb337b5 | ||
|
|
21bca02eee | ||
|
|
4fee82d3b7 | ||
|
|
c341e8ffdc | ||
|
|
1cd4a69854 | ||
|
|
4f953da0fe | ||
|
|
3b6c7acdbf | ||
|
|
2232d5265f | ||
|
|
b5cd7b7a40 | ||
|
|
dc8ff1ceab | ||
|
|
fa487ede6e | ||
|
|
889b5de9c6 | ||
|
|
7139993e15 | ||
|
|
f863871173 | ||
|
|
49e4f0a597 | ||
|
|
2f49ef0f62 | ||
|
|
93ce778c0d | ||
|
|
db82bd8123 | ||
|
|
0f5404fef8 | ||
|
|
5c675fe04a | ||
|
|
e0ee22a8df | ||
|
|
649f606a0e | ||
|
|
a46c776398 | ||
|
|
7d19c4bcd7 | ||
|
|
f59d8f9b05 | ||
|
|
a253e5d85a | ||
|
|
cd946bffaf | ||
|
|
21cb91e0c6 | ||
|
|
899737b558 | ||
|
|
01b3d91232 | ||
|
|
0ed772b054 | ||
|
|
1c6b47c5f2 | ||
|
|
710ddbdd38 | ||
|
|
c856439191 | ||
|
|
88c36fc287 | ||
|
|
7b1a7beedf | ||
|
|
55acb1dc60 | ||
|
|
b41d4715e3 | ||
|
|
b5c60b3180 | ||
|
|
09561e0877 | ||
|
|
c199d2d749 | ||
|
|
b3d6b82c66 | ||
|
|
59cdfcb19e | ||
|
|
20556276ac | ||
|
|
2a997404e3 | ||
|
|
c5163487fd | ||
|
|
ef207c3936 | ||
|
|
00fb71f2e9 | ||
|
|
e9d411222a | ||
|
|
1fd318d545 | ||
|
|
a1624dc649 | ||
|
|
9f39d1e33c | ||
|
|
98749ed3e0 | ||
|
|
44d2f6c548 | ||
|
|
0621efe674 | ||
|
|
326fc63f19 | ||
|
|
62814e5d67 | ||
|
|
9e72fad9e4 | ||
|
|
cac458cb00 | ||
|
|
6d69961d7a | ||
|
|
150c9de6fb | ||
|
|
6c51e6b711 | ||
|
|
de9df7d257 | ||
|
|
0208550ca3 | ||
|
|
1659c4b45a | ||
|
|
1984143c82 | ||
|
|
de77de84d9 | ||
|
|
be2484d807 | ||
|
|
2e990238d3 | ||
|
|
9dba69e8da | ||
|
|
95c0b409b9 | ||
|
|
40246d8493 | ||
|
|
ed5e5004e0 | ||
|
|
86f8898ee4 | ||
|
|
2fe733cc06 | ||
|
|
d3287b7cd7 | ||
|
|
5f266d6734 | ||
|
|
bda56d4f8d | ||
|
|
522b54838e | ||
|
|
399f04d0b4 | ||
|
|
5a778ad4e6 | ||
|
|
ca2d95ef4a | ||
|
|
52802063e4 | ||
|
|
077b88139a | ||
|
|
b1112239e3 | ||
|
|
73e32bea79 | ||
|
|
59ceea81cc | ||
|
|
315f45304f | ||
|
|
7d54261f51 | ||
|
|
21e2619a99 | ||
|
|
e1061e1970 | ||
|
|
92916578be | ||
|
|
4de936a5a0 | ||
|
|
1f1dbfbb89 | ||
|
|
01a9950d7c | ||
|
|
848962e351 | ||
|
|
af98694e48 | ||
|
|
a4e3f2006d | ||
|
|
6edf3ce8d4 | ||
|
|
efa75f5b80 | ||
|
|
49edc4b6b5 | ||
|
|
da3939f047 | ||
|
|
67b4d3b760 | ||
|
|
becf95a644 | ||
|
|
78a34e3b58 | ||
|
|
a350fcc254 | ||
|
|
f7edc8a366 | ||
|
|
0c5266429d | ||
|
|
13f3df529a | ||
|
|
db2b45a095 | ||
|
|
a0e496bf1c | ||
|
|
07a21247e6 | ||
|
|
4c444346d7 | ||
|
|
55946c93e3 | ||
|
|
657c268a80 | ||
|
|
726d9abec2 | ||
|
|
9d507a5bc7 | ||
|
|
5e168b1867 | ||
|
|
893deac57e | ||
|
|
5bbfc4e5cb | ||
|
|
1f8944ee88 | ||
|
|
45793ecbef | ||
|
|
950f6a79c5 | ||
|
|
84d32a70f9 | ||
|
|
47b8ba9bfa | ||
|
|
c92c85749e | ||
|
|
f9632955b0 | ||
|
|
62b908baf7 | ||
|
|
3f7cc4682b | ||
|
|
d234dd0e0b | ||
|
|
edaff80bd3 | ||
|
|
4aa9408358 | ||
|
|
d2ca8473f3 | ||
|
|
b53abb5f9f | ||
|
|
fb42675574 | ||
|
|
1d02fb9565 | ||
|
|
0be91191aa | ||
|
|
2af063ac88 | ||
|
|
8442fdfe0a | ||
|
|
239029e196 | ||
|
|
0fcf6dfe89 | ||
|
|
eb99af2735 | ||
|
|
16bfffe78f | ||
|
|
8b347bafbc | ||
|
|
83406479a7 | ||
|
|
9d2ff401fd | ||
|
|
e61556e43b | ||
|
|
8ad208600d | ||
|
|
2dda9c9804 | ||
|
|
610cabfdfa | ||
|
|
ca160d7d83 | ||
|
|
f47fe4a0e9 | ||
|
|
d2ebdf3958 | ||
|
|
ed10017db2 | ||
|
|
4225950928 | ||
|
|
78116d3f44 | ||
|
|
7f36f4bb67 | ||
|
|
c3bde29434 | ||
|
|
883f372638 | ||
|
|
e2fd9dad0b | ||
|
|
e304872e1c | ||
|
|
58b21c21d6 | ||
|
|
f27b639d01 | ||
|
|
a06c9568aa | ||
|
|
56f12dea4a | ||
|
|
9afcc470ef | ||
|
|
82aa5b76ea | ||
|
|
94080ba952 | ||
|
|
1f2a329553 | ||
|
|
4bce4a9489 | ||
|
|
4da270616d | ||
|
|
7abea94196 | ||
|
|
c996bee932 | ||
|
|
901f84bf34 | ||
|
|
0842e398c4 | ||
|
|
98f73dd57c | ||
|
|
ad9f4773b0 | ||
|
|
c0b3a1940f | ||
|
|
9edb0e2fc6 | ||
|
|
a7a928e663 | ||
|
|
9cd9c075e1 | ||
|
|
55d93a0e5f | ||
|
|
9a74a20884 | ||
|
|
a00a3440fc | ||
|
|
06e15a04e9 | ||
|
|
d4c1eba3f3 | ||
|
|
1328d1aaca | ||
|
|
3992d71910 | ||
|
|
9c4ae76a00 | ||
|
|
96e1d6e100 | ||
|
|
3a671cf48f | ||
|
|
3b9eae2e4f | ||
|
|
b0ebeaffb9 | ||
|
|
f50c25b906 | ||
|
|
ad50be45c6 | ||
|
|
1e5cf3a4de | ||
|
|
2b327a9ac9 | ||
|
|
0e431eb498 | ||
|
|
eaeb0ec5b1 | ||
|
|
b45795fac2 | ||
|
|
52f2f532a7 | ||
|
|
456c149f7b | ||
|
|
3e6f006811 | ||
|
|
5c8a6bc4d3 | ||
|
|
47b47ff255 | ||
|
|
bba3199dba | ||
|
|
953ef8c534 | ||
|
|
02ae7176f7 | ||
|
|
c76b174fd6 | ||
|
|
4483537b93 | ||
|
|
ec159e4f14 | ||
|
|
d52452dad7 | ||
|
|
1337612d3d | ||
|
|
51b8c9c70a | ||
|
|
dee8e8150e | ||
|
|
ae424d5da8 | ||
|
|
0363747d6e | ||
|
|
13150aca0d | ||
|
|
09ea3430a0 | ||
|
|
3772f8c3b3 | ||
|
|
0752fbf125 | ||
|
|
12c3b8112b | ||
|
|
436d21f33c | ||
|
|
4ee9dfa509 | ||
|
|
c18e8edd34 | ||
|
|
42e254c9c7 | ||
|
|
3785d5808f | ||
|
|
a1d56fe5d3 | ||
|
|
ab211610a1 | ||
|
|
f26440fa51 | ||
|
|
309c67a660 | ||
|
|
8e3c6054ad | ||
|
|
10efcc6397 | ||
|
|
fe0f0c56af | ||
|
|
f83656fe71 | ||
|
|
913498e039 | ||
|
|
09a492ee7f | ||
|
|
fb8838bfe4 | ||
|
|
a6755379f7 | ||
|
|
392e64da7c | ||
|
|
55ae00ecfe | ||
|
|
dd158000a1 | ||
|
|
0cc2cfc8ff | ||
|
|
c3107e3909 | ||
|
|
f4cf72a5b3 | ||
|
|
89a21f8099 | ||
|
|
01bac3fcd3 | ||
|
|
99357c3728 | ||
|
|
9f6ec87101 | ||
|
|
c3b46270cd | ||
|
|
8ea082daf0 | ||
|
|
da0ab9dda9 | ||
|
|
99c8101371 | ||
|
|
489bc2e74f | ||
|
|
61b8e02bfa | ||
|
|
5e21418e8d | ||
|
|
10823a5632 | ||
|
|
8c9bbd8c80 | ||
|
|
8d18529c6d | ||
|
|
03e336d078 | ||
|
|
828bba61de | ||
|
|
cb8adb6740 | ||
|
|
95dce0ae78 | ||
|
|
4ddd1b7774 | ||
|
|
b24c104a9d | ||
|
|
b485cd1663 | ||
|
|
f551ad2094 | ||
|
|
af2003bb03 | ||
|
|
c67fc20479 | ||
|
|
6b2a06f433 | ||
|
|
6013942919 | ||
|
|
71b6a478da | ||
|
|
6144186870 | ||
|
|
f3f8450081 | ||
|
|
a29dd1fa62 | ||
|
|
0890b6e3f9 | ||
|
|
1425ba630e | ||
|
|
2867a09450 | ||
|
|
e877148bf9 | ||
|
|
a7851523f0 | ||
|
|
33edc9600a | ||
|
|
0d26ed2a0f | ||
|
|
bff71319e9 | ||
|
|
1f7662adb7 | ||
|
|
05a74417ff | ||
|
|
3388707dba | ||
|
|
543b64ccd2 | ||
|
|
c096014871 | ||
|
|
17f6fbe033 | ||
|
|
d0265a9978 | ||
|
|
0a6c0a1eae | ||
|
|
1e0c09243a | ||
|
|
fdd495bfbb | ||
|
|
62b816878d | ||
|
|
a5919e627b | ||
|
|
2258e70a75 | ||
|
|
0670eff6de | ||
|
|
1d98ec9704 | ||
|
|
184820939d | ||
|
|
43ac4f0e0e | ||
|
|
ade6f3997a | ||
|
|
735c8cb917 | ||
|
|
86a03fd0bf | ||
|
|
c89f17ebbf | ||
|
|
d1d89d033e | ||
|
|
44576cc053 | ||
|
|
c6a4dfd163 | ||
|
|
758ed67eb9 | ||
|
|
1742f810c9 | ||
|
|
4c4659c9f7 | ||
|
|
533a79d4e2 | ||
|
|
f8683ebbc8 | ||
|
|
6374b09dcc | ||
|
|
f3c8a54cc5 | ||
|
|
191cdcf702 | ||
|
|
417bdd3c49 | ||
|
|
1fa0a23459 | ||
|
|
3d11ed92d4 | ||
|
|
58a935e408 | ||
|
|
2e445e664b | ||
|
|
4691817c88 | ||
|
|
c4b20acf1b | ||
|
|
36e6797c09 | ||
|
|
fc44629842 | ||
|
|
ba4b30228a | ||
|
|
904548521e | ||
|
|
8edf517b7a | ||
|
|
286b40ce80 | ||
|
|
f1c5942df9 | ||
|
|
2f0f501ead | ||
|
|
5dd07c36ef | ||
|
|
a209538fc6 | ||
|
|
560247c2cf | ||
|
|
7b9f7248ad | ||
|
|
252b43c048 | ||
|
|
747b8d0279 | ||
|
|
fed4b62d2d | ||
|
|
41d07fe314 | ||
|
|
c239aa8df6 | ||
|
|
f75fb80d54 | ||
|
|
20b8a5b0b1 | ||
|
|
5171d1154e | ||
|
|
0a68b8ecf9 | ||
|
|
c265268b02 | ||
|
|
bf8c866a74 | ||
|
|
3faf33eb5a | ||
|
|
7442e0f04e | ||
|
|
8fd7faf37a | ||
|
|
93b43d461d | ||
|
|
1c541bc045 | ||
|
|
d0ec9e76c1 | ||
|
|
597a0d08c5 | ||
|
|
6527644926 | ||
|
|
dec91cc76e | ||
|
|
2a9970705b | ||
|
|
694f5dcd21 | ||
|
|
8cdc5ab0af | ||
|
|
1c35d08a5c | ||
|
|
46d9322b50 | ||
|
|
2791c2259b | ||
|
|
f16c8b7663 | ||
|
|
fabd280efa | ||
|
|
7a89f942fe | ||
|
|
c48276de71 | ||
|
|
22cc8b8bbf | ||
|
|
d0119f351f | ||
|
|
d2da5ad9fa | ||
|
|
653f4ed419 | ||
|
|
7e09f7031c | ||
|
|
34e3c67254 | ||
|
|
3e098fa0cf | ||
|
|
18b335fe94 | ||
|
|
98a560bd8b | ||
|
|
e91483726e | ||
|
|
2846d01a44 | ||
|
|
2526dbb700 | ||
|
|
66e5dde0ad | ||
|
|
09171acc6e | ||
|
|
74733a4cca | ||
|
|
b936546392 | ||
|
|
79f2938b53 | ||
|
|
3f26e0fcbc | ||
|
|
75c65d74a6 | ||
|
|
f6011b63db | ||
|
|
2937fd08dc | ||
|
|
15183d293a | ||
|
|
266de1c1c2 | ||
|
|
231e38af57 | ||
|
|
5ed60e7130 | ||
|
|
cd5de2c2a1 | ||
|
|
39a7cdb63d | ||
|
|
1453535383 | ||
|
|
2534f23c24 | ||
|
|
d937e4ab81 | ||
|
|
741d7762d8 | ||
|
|
71bc95251c | ||
|
|
b4ec26a29f | ||
|
|
b5598ac423 | ||
|
|
215d24b99a | ||
|
|
9dc2752ac3 | ||
|
|
3e76046868 | ||
|
|
c28736bd01 | ||
|
|
820160d0f5 | ||
|
|
b30e44325e | ||
|
|
390ff68a6b | ||
|
|
7deec9cd6e | ||
|
|
2813ff8972 | ||
|
|
20678ba420 | ||
|
|
86f3d5c290 | ||
|
|
371ba0a93f | ||
|
|
1652922199 | ||
|
|
e6df660522 | ||
|
|
efe67d2092 | ||
|
|
4e6c3add5b | ||
|
|
852510c93a | ||
|
|
3c3d29739a | ||
|
|
b6a717d361 | ||
|
|
9d03385a13 | ||
|
|
eda1fb29c6 | ||
|
|
44b8ff8cd2 | ||
|
|
7cf277b6a7 | ||
|
|
df6b4b07cd | ||
|
|
2f19b7658c | ||
|
|
0b5f039337 | ||
|
|
54b0dd46f8 | ||
|
|
d6b763e62d | ||
|
|
dbeff56ffa | ||
|
|
b72e5b9172 | ||
|
|
eb9fc4487c | ||
|
|
c4c2d8cabd | ||
|
|
14a2e3f8fd | ||
|
|
776480d6cf | ||
|
|
1a15b563b8 | ||
|
|
cc65b6826d | ||
|
|
a6ac4600d3 | ||
|
|
3fb84d03bb | ||
|
|
97d777bba0 | ||
|
|
375c54d6ff | ||
|
|
e30ae2b88e | ||
|
|
8bce6bb544 | ||
|
|
c44e32936f | ||
|
|
b233030bdc | ||
|
|
007ae985c8 | ||
|
|
f256316b0b | ||
|
|
0868b45fa3 | ||
|
|
053fe4d701 | ||
|
|
832b18a4d4 | ||
|
|
51da573e57 | ||
|
|
9165032c54 | ||
|
|
be37ca4d62 | ||
|
|
21253a2f1f | ||
|
|
eab526a051 | ||
|
|
a51d3e1860 | ||
|
|
4bf485b2e2 | ||
|
|
3a6541269a | ||
|
|
a8b93bd81a | ||
|
|
7b00ec9fcf | ||
|
|
ca426ff68c | ||
|
|
3c7d7339f0 | ||
|
|
9e8cdacc68 | ||
|
|
955457f22f | ||
|
|
fc8656e05b | ||
|
|
0d6c3c7e33 | ||
|
|
9b93be7e23 | ||
|
|
9fe918e2f0 | ||
|
|
153fa3abb5 | ||
|
|
3b89bba93c | ||
|
|
6684e9b5de | ||
|
|
bfe2c11548 | ||
|
|
f98c506a3f | ||
|
|
56f76bceae | ||
|
|
b1a1c86155 | ||
|
|
727ae0693a | ||
|
|
4370597587 | ||
|
|
5faa12a79e | ||
|
|
4f4a0ef273 | ||
|
|
7169a6a875 | ||
|
|
0495513059 | ||
|
|
97392a9630 | ||
|
|
494791cdd2 | ||
|
|
2ed5444bbc | ||
|
|
044b8bf44c | ||
|
|
a4a80f7282 | ||
|
|
e7a33a1d39 | ||
|
|
6dbc4214e5 | ||
|
|
aca481388e | ||
|
|
7987bf1671 | ||
|
|
89eb7990aa | ||
|
|
56db2a73c2 | ||
|
|
99d320e6a2 | ||
|
|
6b57dcf052 | ||
|
|
c0c0984c5c | ||
|
|
8fc4c946d7 | ||
|
|
ab19097521 | ||
|
|
859dbea0bc | ||
|
|
12a45c39ed | ||
|
|
db58c107d8 | ||
|
|
f9a4e30dea | ||
|
|
d7e170fb9d | ||
|
|
d9f4f0a4ec | ||
|
|
22e09b0879 | ||
|
|
af477c56b1 | ||
|
|
4aacb36b3f | ||
|
|
dd63370d20 | ||
|
|
9d72796a67 | ||
|
|
dd091b9bb2 | ||
|
|
3c7748e5be | ||
|
|
2d203199a7 | ||
|
|
6473ea571c | ||
|
|
2bcd317a4c | ||
|
|
0ddca82c86 | ||
|
|
d5645083f3 | ||
|
|
e0bba53df1 | ||
|
|
223fc0a514 | ||
|
|
625d30f3a8 | ||
|
|
6388cc7032 | ||
|
|
96a0907eee | ||
|
|
066de435d3 | ||
|
|
4ec6ea0f84 | ||
|
|
a7f8ff5212 | ||
|
|
215abbf2f7 | ||
|
|
c005d4d387 | ||
|
|
fd38371eeb | ||
|
|
3c46312929 | ||
|
|
55850f6d3c | ||
|
|
790bb5d1b7 | ||
|
|
c51e8fd9d1 | ||
|
|
60714fbf58 | ||
|
|
f040805d09 | ||
|
|
c35138e7e3 | ||
|
|
91f7d86fd4 | ||
|
|
97ebdf7ae6 | ||
|
|
4ce1cf5eec | ||
|
|
0a6434fbf3 | ||
|
|
4669c5d489 | ||
|
|
f17fbaff49 |
No files matched your search
@@ -10,7 +10,7 @@ orbs:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
docker:
|
docker:
|
||||||
- image: cimg/node:20.18.0
|
- image: cimg/node:26.4
|
||||||
- image: mongo:4.4
|
- image: mongo:4.4
|
||||||
|
|
||||||
working_directory: ~/homebrewery
|
working_directory: ~/homebrewery
|
||||||
@@ -27,7 +27,7 @@ jobs:
|
|||||||
# fallback to using the latest cache if no exact match is found
|
# fallback to using the latest cache if no exact match is found
|
||||||
- v1-dependencies-
|
- v1-dependencies-
|
||||||
|
|
||||||
- run: sudo npm install -g npm@10.8.2
|
- run: sudo npm install -g npm@11.17.0
|
||||||
- node/install-packages:
|
- node/install-packages:
|
||||||
app-dir: ~/homebrewery
|
app-dir: ~/homebrewery
|
||||||
cache-path: node_modules
|
cache-path: node_modules
|
||||||
@@ -45,7 +45,7 @@ jobs:
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
docker:
|
docker:
|
||||||
- image: cimg/node:20.17.0
|
- image: cimg/node:26.4
|
||||||
|
|
||||||
working_directory: ~/homebrewery
|
working_directory: ~/homebrewery
|
||||||
parallelism: 1
|
parallelism: 1
|
||||||
@@ -82,6 +82,9 @@ jobs:
|
|||||||
- run:
|
- run:
|
||||||
name: Test - HTML sanitization
|
name: Test - HTML sanitization
|
||||||
command: npm run test:safehtml
|
command: npm run test:safehtml
|
||||||
|
- run:
|
||||||
|
name: Test - Helpers
|
||||||
|
command: npm run test:helpers
|
||||||
- run:
|
- run:
|
||||||
name: Test - Coverage
|
name: Test - Coverage
|
||||||
command: npm run test:coverage
|
command: npm run test:coverage
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ updates:
|
|||||||
interval: daily
|
interval: daily
|
||||||
open-pull-requests-limit: 99
|
open-pull-requests-limit: 99
|
||||||
groups:
|
groups:
|
||||||
|
eslint-bundle:
|
||||||
|
patterns: ["*eslint*"]
|
||||||
|
update-types: ["patch", "minor", "major"]
|
||||||
dev-dependencies:
|
dev-dependencies:
|
||||||
dependency-type: "development"
|
dependency-type: "development"
|
||||||
patterns: ["*"]
|
patterns: ["*"]
|
||||||
@@ -66,10 +69,6 @@ updates:
|
|||||||
- dependency-name: "@babel/preset-react"
|
- dependency-name: "@babel/preset-react"
|
||||||
versions:
|
versions:
|
||||||
- 7.13.13
|
- 7.13.13
|
||||||
- dependency-name: codemirror
|
|
||||||
versions:
|
|
||||||
- 5.59.3
|
|
||||||
- 5.60.0
|
|
||||||
- dependency-name: classnames
|
- dependency-name: classnames
|
||||||
versions:
|
versions:
|
||||||
- 2.3.0
|
- 2.3.0
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ storage
|
|||||||
build/*
|
build/*
|
||||||
config/local.*
|
config/local.*
|
||||||
config/docker.*
|
config/docker.*
|
||||||
|
config/dev.*
|
||||||
|
|
||||||
todo.md
|
todo.md
|
||||||
startDB.bat
|
startDB.bat
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
FROM node:22-alpine
|
FROM node:26.4.0-alpine
|
||||||
RUN apk --no-cache add git
|
RUN apk --no-cache add git
|
||||||
|
|
||||||
ENV NODE_ENV=docker
|
ENV NODE_ENV=docker
|
||||||
|
|||||||
+194
-3
@@ -83,12 +83,203 @@ pre {
|
|||||||
.page .exampleTable td,th {
|
.page .exampleTable td,th {
|
||||||
border:1px dashed #00000030;
|
border:1px dashed #00000030;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.page .df {
|
||||||
|
font-size: 2em;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## changelog
|
## changelog
|
||||||
For a full record of development, visit our [Github Page](https://github.com/naturalcrit/homebrewery).
|
For a full record of development, visit our [Github Page](https://github.com/naturalcrit/homebrewery).
|
||||||
|
|
||||||
### Friday 11/14/2025 - v13.20.0
|
### Tuesday 10/20/2026 - v3.24.2
|
||||||
|
{{taskList
|
||||||
|
##### G-Ambatte
|
||||||
|
* [x] Hotfix for memory leak on server
|
||||||
|
|
||||||
|
Fixes issue [#5090](https://github.com/naturalcrit/homebrewery/issues/5090)
|
||||||
|
|
||||||
|
##### Calculuschild
|
||||||
|
* [x] Fix brew variables not working across pages
|
||||||
|
|
||||||
|
* [x] Allow brew variable definitions to be on adjacent lines (no blank line required anymore)
|
||||||
|
|
||||||
|
##### 5e-Cleric
|
||||||
|
* [x] Partial rollout of some site UI changes (includes alternate views and darkmode in {{openSans **BREWS** :fas_beer_mug_empty:}} page, and changes to {{openSans **VAULT** :fas_dungeon:}})
|
||||||
|
|
||||||
|
##### Abquintic, Calculuschild, 5e-Cleric
|
||||||
|
* [x] Multiple background fixes and code cleanups
|
||||||
|
}}
|
||||||
|
|
||||||
|
|
||||||
|
### Tuesday 9/29/2026 - v3.24.1
|
||||||
|
{{taskList
|
||||||
|
##### calculuschild
|
||||||
|
* [x] Small hotfix for broken images thrashing the server
|
||||||
|
}}
|
||||||
|
|
||||||
|
### Tuesday 9/29/2026 - v3.24.0
|
||||||
|
{{taskList
|
||||||
|
##### calculuschild
|
||||||
|
* [x] Add a periodic warning to /new page if work has never been saved
|
||||||
|
* [x] Small fix to variable hoisting logic
|
||||||
|
|
||||||
|
Fixes issue [#31](https://github.com/naturalcrit/marked-variables/issues/31)
|
||||||
|
|
||||||
|
##### Ericscheid
|
||||||
|
* [x] Enable "fancy drop caps" on any paragraph, by placing `{drop-cap}` on the line below.
|
||||||
|
|
||||||
|
Fixes issue [#5024](https://github.com/naturalcrit/homebrewery/issues/5024)
|
||||||
|
|
||||||
|
* [x] Prevent crash if `<script>` tag in brew text
|
||||||
|
|
||||||
|
Fixes issue [#546](https://github.com/naturalcrit/homebrewery/issues/546)
|
||||||
|
|
||||||
|
##### G-Ambatte
|
||||||
|
* [x] Add compatibility with Markdeep Ascii art diagrams. See [example brew](https://homebrewery.naturalcrit.com/share/TsZ5Iak3bapb)
|
||||||
|
|
||||||
|
* [x] Fix stray hyphens in PDF output titles
|
||||||
|
|
||||||
|
Fixes issue [#5069](https://github.com/naturalcrit/homebrewery/issues/5069)
|
||||||
|
|
||||||
|
##### 5e-Cleric
|
||||||
|
* [x] Fix Google Drive files that can't be deleted
|
||||||
|
|
||||||
|
Fixes issue [#5020](https://github.com/naturalcrit/homebrewery/issues/5020)
|
||||||
|
|
||||||
|
* [x] Prevent co-authors moving brews between Google and Homebrewery storage.
|
||||||
|
|
||||||
|
Fixes issue [#4862](https://github.com/naturalcrit/homebrewery/issues/4862)
|
||||||
|
|
||||||
|
* [x] Fix cursor position for hotkeys, and other tweaks
|
||||||
|
|
||||||
|
Fixes issues [#4758](https://github.com/naturalcrit/homebrewery/issues/4758), [#4790](https://github.com/naturalcrit/homebrewery/issues/4790), [#4809](https://github.com/naturalcrit/homebrewery/issues/4809)
|
||||||
|
|
||||||
|
##### 5e-Cleric, G-Ambatte
|
||||||
|
* [x] Share pages update live when file contents change
|
||||||
|
|
||||||
|
##### Abquintic, Calculuschild, G-Ambatte, Gazook89, 5e-Cleric, Ericscheid
|
||||||
|
* [x] Multiple background fixes and code cleanups
|
||||||
|
}}
|
||||||
|
|
||||||
|
### Monday 9/07/2026 - v3.23.0
|
||||||
|
{{taskList
|
||||||
|
##### firstmatekidd (new contributor!)
|
||||||
|
* [x] Add nav buttons to tab order for accesibility
|
||||||
|
* [x] Add title to brewRenderer iframe for accessibility
|
||||||
|
* [x] Add aria labels to toolbars
|
||||||
|
|
||||||
|
Partially fixes issue [#3032](https://github.com/naturalcrit/homebrewery/issues/3032)
|
||||||
|
|
||||||
|
##### ReinaSweet (new contributor!)
|
||||||
|
* [x] Added security to prevent scripts running in brews
|
||||||
|
|
||||||
|
##### Gazook89
|
||||||
|
* [x] Lazy load brew images for faster first load
|
||||||
|
* [x] Fix snippet menus getting cut off behind divider bar
|
||||||
|
|
||||||
|
Fixes issue [#3840](https://github.com/naturalcrit/homebrewery/issues/3840)
|
||||||
|
|
||||||
|
##### Abquintic
|
||||||
|
* [x] Fix variables not hoisting in later pages
|
||||||
|
|
||||||
|
##### 5e-Cleric
|
||||||
|
* [x] Add image preview when hovering over image syntax
|
||||||
|
|
||||||
|
Fixes issue [#2037](https://github.com/naturalcrit/homebrewery/issues/2037)
|
||||||
|
|
||||||
|
* [x] Remember editor theme across tabs, and new {{openSans **SETTINGS :fas_gear:**}} tab with editor settings
|
||||||
|
|
||||||
|
Fixes issue [#4858](https://github.com/naturalcrit/homebrewery/issues/4858)
|
||||||
|
|
||||||
|
* [x] Add ability to remove co-authors if you are the owner
|
||||||
|
|
||||||
|
Fixes part of issue [#4101](https://github.com/naturalcrit/homebrewery/issues/4101)
|
||||||
|
|
||||||
|
##### G-Ambatte
|
||||||
|
* [x] Fix editor panel shrinking when opening dev tools
|
||||||
|
|
||||||
|
Fixes issue [#4866](https://github.com/naturalcrit/homebrewery/issues/4866)
|
||||||
|
|
||||||
|
* [x] Added security to prevent scripts running in brews
|
||||||
|
|
||||||
|
Fixes issue [#4904](https://github.com/naturalcrit/homebrewery/issues/4904)
|
||||||
|
|
||||||
|
##### Abquintic, G-Ambatte, Gazook89, 5e-Cleric
|
||||||
|
* [x] Multiple background fixes and code cleanups
|
||||||
|
}}
|
||||||
|
|
||||||
|
\page
|
||||||
|
|
||||||
|
### Wednesday 5/13/2026 - v3.22.1
|
||||||
|
{{taskList
|
||||||
|
##### Frederlk (new Contributor!)
|
||||||
|
* [x] Add "share current page" to {{openSans **SHARE :fas_share_nodes:**}} menu
|
||||||
|
|
||||||
|
##### Calculuschild, 5e-Cleric
|
||||||
|
* [x] Fix brews triggering unneeded save when loaded
|
||||||
|
|
||||||
|
##### G-Ambatte
|
||||||
|
* [x] Fix brews with `$` in text getting out of sync on save
|
||||||
|
|
||||||
|
##### 5e-Cleric, Gazook89
|
||||||
|
* [x] Fix various issues with Codemirror 6
|
||||||
|
|
||||||
|
Fixes issues [#4771](https://github.com/naturalcrit/homebrewery/issues/4771), [#4783](https://github.com/naturalcrit/homebrewery/issues/4783)
|
||||||
|
}}
|
||||||
|
|
||||||
|
### Saturday 4/04/2026 - v3.21.0
|
||||||
|
|
||||||
|
{{taskList
|
||||||
|
##### Gazook89
|
||||||
|
* [x] Allow custom {{openSans **:fas_table_list: SNIPPETS**}} dropdown to be inserted mid-line
|
||||||
|
|
||||||
|
##### abquintic
|
||||||
|
* [x] Move example snippet images out of imgur (for folks without imgur access)
|
||||||
|
|
||||||
|
##### 5e-Cleric
|
||||||
|
* [x] Add auto-suggest to tag entry input box
|
||||||
|
* [x] Added tooltips to the {{openSans :fas_circle_info: **Properties**}} menu
|
||||||
|
* [x] Removed {{openSans **SYSTEMS**}} checkboxes from {{openSans :fas_circle_info: **Properties**}} menu; instead {{openSans **TAGS**}} should be used for this purpose
|
||||||
|
* [x] Replace all AI-generated art with public domain art
|
||||||
|
* [x] Major backend refactor to use Vite
|
||||||
|
|
||||||
|
##### A1Asriel (new contributor!)
|
||||||
|
* [x] Add fix for column breaks on Firefox
|
||||||
|
|
||||||
|
Fixes issues [#543](https://github.com/naturalcrit/homebrewery/issues/543), [#2473](https://github.com/naturalcrit/homebrewery/issues/2473), [#3712](https://github.com/naturalcrit/homebrewery/issues/3712)
|
||||||
|
|
||||||
|
##### G-Ambatte, abquintic, 5e-Cleric
|
||||||
|
* [x] Multiple other backend fixes and refactors
|
||||||
|
}}
|
||||||
|
|
||||||
|
|
||||||
|
### Friday 1/11/2026 - v3.20.1
|
||||||
|
|
||||||
|
{{taskList
|
||||||
|
##### calculuschild
|
||||||
|
* [x] Add D100 "ball" dice icons `:d100:` :df_d100_05:
|
||||||
|
|
||||||
|
##### G-Ambatte
|
||||||
|
* [x] Fix transparent edge on back cover image
|
||||||
|
|
||||||
|
Fixes issue [#4551](https://github.com/naturalcrit/homebrewery/issues/4551)
|
||||||
|
|
||||||
|
* [x] Fix "Out of sync" error when document contains extended unicode characters
|
||||||
|
|
||||||
|
Fixes issue [#4583](https://github.com/naturalcrit/homebrewery/issues/4583)
|
||||||
|
|
||||||
|
##### 5e-Cleric
|
||||||
|
* [x] Fix page count error on Vault
|
||||||
|
|
||||||
|
* [x] Fix cover page footnote set to all-caps
|
||||||
|
|
||||||
|
Fixes issue [#4559](https://github.com/naturalcrit/homebrewery/issues/4559)
|
||||||
|
}}
|
||||||
|
|
||||||
|
### Friday 11/14/2025 - v3.20.0
|
||||||
|
|
||||||
{{taskList
|
{{taskList
|
||||||
##### calculuschild
|
##### calculuschild
|
||||||
@@ -101,7 +292,7 @@ For a full record of development, visit our [Github Page](https://github.com/nat
|
|||||||
##### G-Ambatte
|
##### G-Ambatte
|
||||||
* [x] Fix default save location failing on new documents
|
* [x] Fix default save location failing on new documents
|
||||||
|
|
||||||
Fixes issue [#4437](https://github.com/naturalcrit/homebrewery/issues/3175)
|
Fixes issue [#4437](https://github.com/naturalcrit/homebrewery/issues/4437)
|
||||||
* [x] Fix usernames with special symbols unable to open userpage
|
* [x] Fix usernames with special symbols unable to open userpage
|
||||||
|
|
||||||
Fixes issue [#807](https://github.com/naturalcrit/homebrewery/issues/807)
|
Fixes issue [#807](https://github.com/naturalcrit/homebrewery/issues/807)
|
||||||
@@ -260,7 +451,7 @@ Fixes issue [#1729](https://github.com/naturalcrit/homebrewery/issues/1729)
|
|||||||
Fixes issue [#4079](https://github.com/naturalcrit/homebrewery/issues/4079)
|
Fixes issue [#4079](https://github.com/naturalcrit/homebrewery/issues/4079)
|
||||||
|
|
||||||
##### Calculuschild
|
##### Calculuschild
|
||||||
* [x] `꞉꞉꞉꞉` now produces `<br>` instead of a `<div>`
|
* [x] `꞉꞉꞉꞉` now produces `<br>` instead of a `<div>`
|
||||||
* [x] Fix typos in tables freezing the editor
|
* [x] Fix typos in tables freezing the editor
|
||||||
|
|
||||||
Fixes issue [#4059](https://github.com/naturalcrit/homebrewery/issues/4059)
|
Fixes issue [#4059](https://github.com/naturalcrit/homebrewery/issues/4059)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import './admin.less';
|
import './admin.less';
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
const BrewUtils = require('./brewUtils/brewUtils.jsx');
|
import BrewUtils from './brewUtils/brewUtils.jsx';
|
||||||
const NotificationUtils = require('./notificationUtils/notificationUtils.jsx');
|
import NotificationUtils from './notificationUtils/notificationUtils.jsx';
|
||||||
import AuthorUtils from './authorUtils/authorUtils.jsx';
|
import AuthorUtils from './authorUtils/authorUtils.jsx';
|
||||||
import LockTools from './lockTools/lockTools.jsx';
|
import LockTools from './lockTools/lockTools.jsx';
|
||||||
|
|
||||||
@@ -49,4 +49,4 @@ const Admin = ()=>{
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Admin;
|
export default Admin;
|
||||||
+10
-8
@@ -1,11 +1,9 @@
|
|||||||
@import 'naturalcrit/styles/reset.less';
|
@import '@sharedStyles/reset.less';
|
||||||
@import 'naturalcrit/styles/elements.less';
|
@import '@sharedStyles/elements.less';
|
||||||
@import 'naturalcrit/styles/animations.less';
|
@import '@sharedStyles/animations.less';
|
||||||
@import 'naturalcrit/styles/colors.less';
|
@import '@sharedStyles/colors.less';
|
||||||
@import 'naturalcrit/styles/tooltip.less';
|
@import '@sharedStyles/tooltip.less';
|
||||||
@import './themes/fonts/iconFonts/fontAwesome.less';
|
@import '@themes/fonts/iconFonts/fontAwesome.less';
|
||||||
|
|
||||||
@import 'font-awesome/css/font-awesome.css';
|
|
||||||
|
|
||||||
html,body, #reactContainer, .naturalCrit { min-height : 100%; }
|
html,body, #reactContainer, .naturalCrit { min-height : 100%; }
|
||||||
|
|
||||||
@@ -109,9 +107,13 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
th, td {
|
th, td {
|
||||||
|
max-width : 50ch;
|
||||||
padding : 5px 10px;
|
padding : 5px 10px;
|
||||||
|
overflow : hidden;
|
||||||
|
text-overflow : ellipsis;
|
||||||
vertical-align : middle;
|
vertical-align : middle;
|
||||||
text-align : center;
|
text-align : center;
|
||||||
|
white-space : nowrap;
|
||||||
border-right : 1px solid;
|
border-right : 1px solid;
|
||||||
|
|
||||||
&:last-child { border-right : none; }
|
&:last-child { border-right : none; }
|
||||||
|
|||||||
@@ -84,4 +84,4 @@ const authorLookup = ()=>{
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = authorLookup;
|
export default authorLookup;
|
||||||
@@ -10,4 +10,4 @@ const authorUtils = ()=>{
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = authorUtils;
|
export default authorUtils;
|
||||||
@@ -1,72 +1,176 @@
|
|||||||
const React = require('react');
|
import React, { useState } from 'react';
|
||||||
const createClass = require('create-react-class');
|
import request from 'superagent';
|
||||||
|
import Moment from 'moment';
|
||||||
|
|
||||||
const request = require('superagent');
|
const BrewCleanup = ({})=>{
|
||||||
|
const [junkBrewCollection, setJunkBrewCollection] = useState([]);
|
||||||
|
const [lostBrewCollection, setLostBrewCollection] = useState([]);
|
||||||
|
const [pendingJunk, setPendingJunk] = useState(false);
|
||||||
|
const [pendingLost, setPendingLost] = useState(false);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
const BrewCleanup = createClass({
|
const find = async (type)=>{
|
||||||
displayName : 'BrewCleanup',
|
|
||||||
getDefaultProps(){
|
|
||||||
return {};
|
|
||||||
},
|
|
||||||
getInitialState() {
|
|
||||||
return {
|
|
||||||
count : 0,
|
|
||||||
|
|
||||||
pending : false,
|
|
||||||
primed : false,
|
|
||||||
err : null
|
|
||||||
};
|
|
||||||
},
|
|
||||||
prime(){
|
|
||||||
this.setState({ pending: true });
|
|
||||||
|
|
||||||
request.get('/admin/cleanup')
|
if(type === 'junk') try {
|
||||||
.then((res)=>this.setState({ count: res.body.count, primed: true }))
|
setPendingJunk(true);
|
||||||
.catch((err)=>this.setState({ error: err }))
|
const res = await request.get('/admin/cleanupJunk');
|
||||||
.finally(()=>this.setState({ pending: false }));
|
|
||||||
},
|
|
||||||
cleanup(){
|
|
||||||
this.setState({ pending: true });
|
|
||||||
|
|
||||||
request.post('/admin/cleanup')
|
setJunkBrewCollection(res.body.brewCollection);
|
||||||
.then((res)=>this.setState({ count: res.body.count }))
|
} catch (err) {
|
||||||
.catch((err)=>this.setState({ error: err }))
|
setError(err);
|
||||||
.finally(()=>this.setState({ pending: false, primed: false }));
|
} finally {
|
||||||
},
|
setPendingJunk(false);
|
||||||
renderPrimed(){
|
|
||||||
if(!this.state.primed) return;
|
|
||||||
|
|
||||||
if(!this.state.count){
|
|
||||||
return <div className='result noBrews'>No Matching Brews found.</div>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(type === 'lost') try {
|
||||||
|
setPendingLost(true);
|
||||||
|
const res = await request.get('/admin/cleanupLost');
|
||||||
|
|
||||||
|
setLostBrewCollection(res.body.brewCollection);
|
||||||
|
} catch (err) {
|
||||||
|
setError(err);
|
||||||
|
} finally {
|
||||||
|
setPendingLost(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const cleanup = async (type)=>{
|
||||||
|
|
||||||
|
if(type === 'junk') try {
|
||||||
|
setPendingJunk(true);
|
||||||
|
console.log('deleting junk');
|
||||||
|
const res = await request.post('/admin/cleanupJunk');
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
setError(err);
|
||||||
|
} finally {
|
||||||
|
setPendingJunk(false);
|
||||||
|
setJunkBrewCollection([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(type === 'lost') try {
|
||||||
|
setPendingLost(true);
|
||||||
|
const res = await request.post('/admin/cleanupLost');
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
setError(err);
|
||||||
|
} finally {
|
||||||
|
setPendingLost(false);
|
||||||
|
setLostBrewCollection([]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderBrewList = (type)=>{
|
||||||
|
const brewList = type === 'lost' ? lostBrewCollection : junkBrewCollection;
|
||||||
|
|
||||||
|
if(!brewList || brewList.length === 0) {
|
||||||
|
return <>
|
||||||
|
<h3>{`Results - No brews found` }</h3>
|
||||||
|
<table className='resultsTable'>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Title</th>
|
||||||
|
<th>Last Update</th>
|
||||||
|
<th>last viewed</th>
|
||||||
|
<th>Storage</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td colSpan={4}><strong>"No brews found"</strong></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</>;
|
||||||
|
}
|
||||||
|
console.log(type);
|
||||||
|
console.log(brewList);
|
||||||
|
return <>
|
||||||
|
<h3>{`Results - ${brewList.length} brews` }</h3>
|
||||||
|
<table className='resultsTable'>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Title</th>
|
||||||
|
<th>Last Update</th>
|
||||||
|
<th>last viewed</th>
|
||||||
|
<th>Storage</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{brewList
|
||||||
|
.sort((a, b)=>{ // Sort brews from most recently updated
|
||||||
|
if(a.lastViewed > b.lastViewed) return -1;
|
||||||
|
return 1;
|
||||||
|
})
|
||||||
|
.map((brew, idx)=>{
|
||||||
|
return <tr key={idx}>
|
||||||
|
<td><strong>{brew.title || 'No Title'}</strong></td>
|
||||||
|
<td style={{ width: '200px' }}>{Moment(brew.updatedAt).fromNow()}</td>
|
||||||
|
<td>{brew.lastViewed ? Moment(brew.lastViewed).fromNow() : 'No last viewed date'}</td>
|
||||||
|
<td>{brew.googleId ? 'Google' : 'Homebrewery'}</td>
|
||||||
|
</tr>;
|
||||||
|
})}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</>;
|
||||||
|
};
|
||||||
|
const renderFound = (type)=>{
|
||||||
|
const deleteButton = !(type === 'junk' && junkBrewCollection.length === 0 || type === 'lost' && lostBrewCollection.length === 0);
|
||||||
|
|
||||||
return <div className='result'>
|
return <div className='result'>
|
||||||
<button onClick={this.cleanup} className='remove'>
|
{deleteButton && <button onClick={()=>cleanup(type)} className='remove'>
|
||||||
{this.state.pending
|
{pendingLost && type === 'lost' || pendingJunk && type === 'junk'
|
||||||
? <i className='fas fa-spin fa-spinner' />
|
? <i className='fas fa-spin fa-spinner' />
|
||||||
: <span><i className='fas fa-times' /> Remove</span>
|
: <span><i className='fas fa-times' /> Remove</span>
|
||||||
}
|
}
|
||||||
</button>
|
</button>
|
||||||
<span>Found {this.state.count} Brews that could be removed. </span>
|
}
|
||||||
|
{renderBrewList(type)}
|
||||||
</div>;
|
</div>;
|
||||||
},
|
};
|
||||||
render(){
|
const renderJunkBrewCleanup = ()=>{
|
||||||
return <div className='brewUtil brewCleanup'>
|
return <div className='junk'>
|
||||||
<h2> Brew Cleanup </h2>
|
<h3> Junk brews</h3>
|
||||||
<p>Removes very short brews to tidy up the database</p>
|
<p>Queries unauthored brews that have not been viewed or <br/>updated in 30 days and are shorter than 140 bytes (up to 300)</p>
|
||||||
|
|
||||||
<button onClick={this.prime} className='query'>
|
<button onClick={()=>find('junk')} className='query'>
|
||||||
{this.state.pending
|
{pendingJunk
|
||||||
? <i className='fas fa-spin fa-spinner' />
|
? <i className='fas fa-spin fa-spinner' />
|
||||||
: 'Query Brews'
|
: 'Query Brews'
|
||||||
}
|
}
|
||||||
</button>
|
</button>
|
||||||
{this.renderPrimed()}
|
{renderFound('junk')}
|
||||||
|
|
||||||
{this.state.error
|
{error && <div className='error noBrews'>{error.toString()}</div>}
|
||||||
&& <div className='error noBrews'>{this.state.error.toString()}</div>
|
|
||||||
}
|
|
||||||
</div>;
|
</div>;
|
||||||
}
|
};
|
||||||
});
|
const renderLostBrewCleanup = ()=>{
|
||||||
|
return <div className='lost'>
|
||||||
|
<h3> Lost brews</h3>
|
||||||
|
<p>Queries unauthored brews that have not been <br/>updated or viewed for 2 years (up to 500)</p>
|
||||||
|
|
||||||
module.exports = BrewCleanup;
|
<button onClick={()=>find('lost')} className='query'>
|
||||||
|
{pendingLost
|
||||||
|
? <i className='fas fa-spin fa-spinner' />
|
||||||
|
: 'Query Brews'
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
{renderFound('lost')}
|
||||||
|
|
||||||
|
{error && <div className='error noBrews'>{error.toString()}</div>}
|
||||||
|
</div>;
|
||||||
|
};
|
||||||
|
|
||||||
|
return <div className='brewUtil brewCleanup'>
|
||||||
|
<h2> Brew Cleanup </h2>
|
||||||
|
{renderJunkBrewCleanup()}
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
{renderLostBrewCleanup()}
|
||||||
|
|
||||||
|
</div>;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export default BrewCleanup;
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
const React = require('react');
|
import React from 'react';
|
||||||
const createClass = require('create-react-class');
|
import createReactClass from 'create-react-class';
|
||||||
const request = require('superagent');
|
import request from 'superagent';
|
||||||
|
|
||||||
const BrewCompress = createClass({
|
const BrewCompress = createReactClass({
|
||||||
displayName : 'BrewCompress',
|
displayName : 'BrewCompress',
|
||||||
getDefaultProps(){
|
getDefaultProps(){
|
||||||
return {};
|
return {};
|
||||||
@@ -85,4 +85,4 @@ const BrewCompress = createClass({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = BrewCompress;
|
export default BrewCompress;
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
const React = require('react');
|
import React from 'react';
|
||||||
const createClass = require('create-react-class');
|
import createReactClass from 'create-react-class';
|
||||||
const cx = require('classnames');
|
import request from 'superagent';
|
||||||
|
import cx from 'classnames';
|
||||||
|
|
||||||
const request = require('superagent');
|
import Moment from 'moment';
|
||||||
const Moment = require('moment');
|
|
||||||
|
|
||||||
|
const BrewLookup = createReactClass({
|
||||||
const BrewLookup = createClass({
|
|
||||||
getDefaultProps() {
|
getDefaultProps() {
|
||||||
return {};
|
return {};
|
||||||
},
|
},
|
||||||
@@ -110,4 +109,4 @@ const BrewLookup = createClass({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = BrewLookup;
|
export default BrewLookup;
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
const React = require('react');
|
import React from 'react';
|
||||||
const createClass = require('create-react-class');
|
import './brewUtils.less';
|
||||||
require('./brewUtils.less');
|
|
||||||
|
|
||||||
const BrewCleanup = require('./brewCleanup/brewCleanup.jsx');
|
import BrewCleanup from './brewCleanup/brewCleanup.jsx';
|
||||||
const BrewLookup = require('./brewLookup/brewLookup.jsx');
|
import BrewLookup from './brewLookup/brewLookup.jsx';
|
||||||
const BrewCompress = require ('./brewCompress/brewCompress.jsx');
|
import BrewCompress from './brewCompress/brewCompress.jsx';
|
||||||
const Stats = require('./stats/stats.jsx');
|
import Stats from './stats/stats.jsx';
|
||||||
|
|
||||||
const BrewUtils = createClass({
|
const BrewUtils = ()=>{
|
||||||
render : function(){
|
return (
|
||||||
return <>
|
<>
|
||||||
<Stats />
|
<Stats />
|
||||||
<hr />
|
<hr />
|
||||||
<BrewLookup />
|
<BrewLookup />
|
||||||
@@ -17,8 +16,7 @@ const BrewUtils = createClass({
|
|||||||
<BrewCleanup />
|
<BrewCleanup />
|
||||||
<hr />
|
<hr />
|
||||||
<BrewCompress />
|
<BrewCompress />
|
||||||
</>;
|
</>
|
||||||
}
|
);
|
||||||
});
|
};
|
||||||
|
export default BrewUtils;
|
||||||
module.exports = BrewUtils;
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@import '@sharedStyles/colors.less';
|
||||||
|
|
||||||
.brewUtil {
|
.brewUtil {
|
||||||
.result {
|
.result {
|
||||||
margin-top : 20px;
|
margin-top : 20px;
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
const React = require('react');
|
import React from 'react';
|
||||||
const createClass = require('create-react-class');
|
import createReactClass from 'create-react-class';
|
||||||
|
import request from 'superagent';
|
||||||
|
|
||||||
const request = require('superagent');
|
const Stats = createReactClass({
|
||||||
|
|
||||||
const Stats = createClass({
|
|
||||||
displayName : 'Stats',
|
displayName : 'Stats',
|
||||||
getDefaultProps(){
|
getDefaultProps(){
|
||||||
return {};
|
return {};
|
||||||
@@ -43,4 +42,4 @@ const Stats = createClass({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = Stats;
|
export default Stats;
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
/*eslint max-lines: ["warn", {"max": 500, "skipBlankLines": true, "skipComments": true}]*/
|
/*eslint max-lines: ["warn", {"max": 500, "skipBlankLines": true, "skipComments": true}]*/
|
||||||
require('./lockTools.less');
|
import './lockTools.less';
|
||||||
const React = require('react');
|
import React from 'react';
|
||||||
const createClass = require('create-react-class');
|
import createReactClass from 'create-react-class';
|
||||||
|
|
||||||
import request from '../../homebrew/utils/request-middleware.js';
|
import request from '../../homebrew/utils/request-middleware.js';
|
||||||
|
|
||||||
const LockTools = createClass({
|
const LockTools = createReactClass({
|
||||||
displayName : 'LockTools',
|
displayName : 'LockTools',
|
||||||
getInitialState : function() {
|
getInitialState : function() {
|
||||||
return {
|
return {
|
||||||
@@ -55,7 +55,7 @@ const LockTools = createClass({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const LockBrew = createClass({
|
const LockBrew = createReactClass({
|
||||||
displayName : 'LockBrew',
|
displayName : 'LockBrew',
|
||||||
getInitialState : function() {
|
getInitialState : function() {
|
||||||
// Default values
|
// Default values
|
||||||
@@ -183,7 +183,7 @@ const LockBrew = createClass({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const LockTable = createClass({
|
const LockTable = createReactClass({
|
||||||
displayName : 'LockTable',
|
displayName : 'LockTable',
|
||||||
getDefaultProps : function() {
|
getDefaultProps : function() {
|
||||||
return {
|
return {
|
||||||
@@ -273,7 +273,7 @@ const LockTable = createClass({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const LockLookup = createClass({
|
const LockLookup = createReactClass({
|
||||||
displayName : 'LockLookup',
|
displayName : 'LockLookup',
|
||||||
getDefaultProps : function() {
|
getDefaultProps : function() {
|
||||||
return {
|
return {
|
||||||
@@ -339,4 +339,4 @@ const LockLookup = createClass({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = LockTools;
|
export default LockTools;
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
margin-left : 10px;
|
margin-left : 10px;
|
||||||
}
|
}
|
||||||
&.checkbox {
|
&.checkbox {
|
||||||
line-height: 1.5em;
|
line-height : 1.5em;
|
||||||
input {
|
input {
|
||||||
width : 1.5em;
|
width : 1.5em;
|
||||||
height : 1.5em;
|
height : 1.5em;
|
||||||
@@ -26,9 +26,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.lockSuggestions {
|
.lockSuggestions {
|
||||||
|
columns : 2;
|
||||||
line-height : 1.2em;
|
line-height : 1.2em;
|
||||||
break-inside : avoid;
|
break-inside : avoid;
|
||||||
columns : 2;
|
|
||||||
h2 { column-span : all; }
|
h2 { column-span : all; }
|
||||||
h3 { margin-top : 0px; }
|
h3 { margin-top : 0px; }
|
||||||
b { font-weight : 600; }
|
b { font-weight : 600; }
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { createRoot } from 'react-dom/client';
|
||||||
|
import Admin from './admin.jsx';
|
||||||
|
import { bootstrapAnchorPositioningPolyfill } from '@components/anchorPositioningPolyfill.js';
|
||||||
|
|
||||||
|
const props = window.__INITIAL_PROPS__ || {};
|
||||||
|
|
||||||
|
createRoot(document.getElementById('reactRoot')).render(<Admin {...props} />);
|
||||||
|
bootstrapAnchorPositioningPolyfill();
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
require('./notificationAdd.less');
|
import './notificationAdd.less';
|
||||||
const React = require('react');
|
import React, { useState, useRef } from 'react';
|
||||||
const { useState, useRef } = require('react');
|
import request from 'superagent';
|
||||||
const request = require('superagent');
|
|
||||||
|
|
||||||
const NotificationAdd = ()=>{
|
const NotificationAdd = ()=>{
|
||||||
const [notificationResult, setNotificationResult] = useState(null);
|
const [notificationResult, setNotificationResult] = useState(null);
|
||||||
@@ -106,4 +105,4 @@ const NotificationAdd = ()=>{
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = NotificationAdd;
|
export default NotificationAdd;
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
require('./notificationLookup.less');
|
import './notificationLookup.less';
|
||||||
|
import React, { useState } from 'react';
|
||||||
const React = require('react');
|
import request from 'superagent';
|
||||||
const { useState } = require('react');
|
import Moment from 'moment';
|
||||||
const request = require('superagent');
|
|
||||||
const Moment = require('moment');
|
|
||||||
|
|
||||||
const NotificationDetail = ({ notification, onDelete })=>(
|
const NotificationDetail = ({ notification, onDelete })=>(
|
||||||
<>
|
<>
|
||||||
@@ -102,4 +100,4 @@ const NotificationLookup = ()=>{
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = NotificationLookup;
|
export default NotificationLookup;
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
const React = require('react');
|
import React from 'react';
|
||||||
|
import NotificationLookup from './notificationLookup/notificationLookup.jsx';
|
||||||
const NotificationLookup = require('./notificationLookup/notificationLookup.jsx');
|
import NotificationAdd from './notificationAdd/notificationAdd.jsx';
|
||||||
const NotificationAdd = require('./notificationAdd/notificationAdd.jsx');
|
|
||||||
|
|
||||||
const NotificationUtils = ()=>{
|
const NotificationUtils = ()=>{
|
||||||
return (
|
return (
|
||||||
@@ -12,4 +11,4 @@ const NotificationUtils = ()=>{
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = NotificationUtils;
|
export default NotificationUtils;
|
||||||
@@ -71,10 +71,14 @@ const Anchored = ({ children })=>{
|
|||||||
// forward ref for AnchoredTrigger
|
// forward ref for AnchoredTrigger
|
||||||
const AnchoredTrigger = forwardRef(({ toggleVisibility, visible, children, className, ...props }, ref)=>(
|
const AnchoredTrigger = forwardRef(({ toggleVisibility, visible, children, className, ...props }, ref)=>(
|
||||||
<button
|
<button
|
||||||
ref={ref}
|
ref={(el)=>{
|
||||||
|
// setAttribute bypasses React's style sanitization so the anchor polyfill can read it
|
||||||
|
el?.setAttribute('style', `anchor-name: --${props.id}`);
|
||||||
|
if(typeof ref === 'function') ref(el);
|
||||||
|
else if(ref) ref.current = el;
|
||||||
|
}}
|
||||||
className={`anchored-trigger${visible ? ' active' : ''} ${className}`}
|
className={`anchored-trigger${visible ? ' active' : ''} ${className}`}
|
||||||
onClick={toggleVisibility}
|
onClick={toggleVisibility}
|
||||||
style={{ anchorName: `--${props.id}` }} // setting anchor properties here allows greater recyclability.
|
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
@@ -84,9 +88,12 @@ const AnchoredTrigger = forwardRef(({ toggleVisibility, visible, children, class
|
|||||||
// forward ref for AnchoredBox
|
// forward ref for AnchoredBox
|
||||||
const AnchoredBox = forwardRef(({ visible, children, className, anchorId, ...props }, ref)=>(
|
const AnchoredBox = forwardRef(({ visible, children, className, anchorId, ...props }, ref)=>(
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
ref={(el)=>{
|
||||||
|
el?.setAttribute('style', `position-anchor: --${anchorId}`);
|
||||||
|
if(typeof ref === 'function') ref(el);
|
||||||
|
else if(ref) ref.current = el;
|
||||||
|
}}
|
||||||
className={`anchored-box${visible ? ' active' : ''} ${className}`}
|
className={`anchored-box${visible ? ' active' : ''} ${className}`}
|
||||||
style={{ positionAnchor: `--${anchorId}` }} // setting anchor properties here allows greater recyclability.
|
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
|
|
||||||
|
|
||||||
.anchored-box {
|
.anchored-box {
|
||||||
position : absolute;
|
position : absolute;
|
||||||
visibility : hidden;
|
inset-block-start : anchor(bottom);
|
||||||
justify-self : anchor-center;
|
visibility : hidden;
|
||||||
@supports (inset-block-start: anchor(bottom)) {
|
justify-self : anchor-center;
|
||||||
inset-block-start : anchor(bottom);
|
|
||||||
}
|
|
||||||
&.active { visibility : visible; }
|
&.active { visibility : visible; }
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
This file basically checks support for Anchor Positioning API in the browser,
|
||||||
|
and then loads the Oddbird polyfill if support is lacking.
|
||||||
|
*/
|
||||||
|
|
||||||
|
let polyfillPromise;
|
||||||
|
|
||||||
|
// look for `anchorName` in the computed styles
|
||||||
|
const supportsAnchorPositioning = ()=>'anchorName' in document.documentElement.style;
|
||||||
|
|
||||||
|
export const bootstrapAnchorPositioningPolyfill = ()=>{
|
||||||
|
if(supportsAnchorPositioning()) return Promise.resolve(false);
|
||||||
|
if(polyfillPromise) return polyfillPromise;
|
||||||
|
|
||||||
|
polyfillPromise = (async ()=>{
|
||||||
|
try {
|
||||||
|
const { default: polyfill } = await import('@oddbird/css-anchor-positioning/fn');
|
||||||
|
await polyfill();
|
||||||
|
return true;
|
||||||
|
} catch (error){
|
||||||
|
polyfillPromise = undefined;
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
return polyfillPromise;
|
||||||
|
};
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
import diceFont from 'themes/fonts/iconFonts/diceFont.js';
|
|
||||||
import elderberryInn from 'themes/fonts/iconFonts/elderberryInn.js';
|
|
||||||
import fontAwesome from 'themes/fonts/iconFonts/fontAwesome.js';
|
|
||||||
import gameIcons from 'themes/fonts/iconFonts/gameIcons.js';
|
|
||||||
|
|
||||||
const emojis = {
|
|
||||||
...diceFont,
|
|
||||||
...elderberryInn,
|
|
||||||
...fontAwesome,
|
|
||||||
...gameIcons
|
|
||||||
};
|
|
||||||
|
|
||||||
const showAutocompleteEmoji = function(CodeMirror, editor) {
|
|
||||||
CodeMirror.commands.autocomplete = function(editor) {
|
|
||||||
editor.showHint({
|
|
||||||
completeSingle : false,
|
|
||||||
hint : function(editor) {
|
|
||||||
const cursor = editor.getCursor();
|
|
||||||
const line = cursor.line;
|
|
||||||
const lineContent = editor.getLine(line);
|
|
||||||
const start = lineContent.lastIndexOf(':', cursor.ch - 1) + 1;
|
|
||||||
const end = cursor.ch;
|
|
||||||
const currentWord = lineContent.slice(start, end);
|
|
||||||
|
|
||||||
|
|
||||||
const list = Object.keys(emojis).filter(function(emoji) {
|
|
||||||
return emoji.toLowerCase().indexOf(currentWord.toLowerCase()) >= 0;
|
|
||||||
}).sort((a, b)=>{
|
|
||||||
const lowerA = a.replace(/\d+/g, function(match) { // Temporarily convert any numbers in emoji string
|
|
||||||
return match.padStart(4, '0'); // to 4-digits, left-padded with 0's, to aid in
|
|
||||||
}).toLowerCase(); // sorting numbers, i.e., "d6, d10, d20", not "d10, d20, d6"
|
|
||||||
const lowerB = b.replace(/\d+/g, function(match) { // Also make lowercase for case-insensitive alpha sorting
|
|
||||||
return match.padStart(4, '0');
|
|
||||||
}).toLowerCase();
|
|
||||||
|
|
||||||
if(lowerA < lowerB)
|
|
||||||
return -1;
|
|
||||||
return 1;
|
|
||||||
}).map(function(emoji) {
|
|
||||||
return {
|
|
||||||
text : `${emoji}:`, // Text to output to editor when option is selected
|
|
||||||
render : function(element, self, data) { // How to display the option in the dropdown
|
|
||||||
const div = document.createElement('div');
|
|
||||||
div.innerHTML = `<i class="emojiPreview ${emojis[emoji]}"></i> ${emoji}`;
|
|
||||||
element.appendChild(div);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
list : list.length ? list : [],
|
|
||||||
from : CodeMirror.Pos(line, start),
|
|
||||||
to : CodeMirror.Pos(line, end)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
editor.on('inputRead', function(instance, change) {
|
|
||||||
const cursor = editor.getCursor();
|
|
||||||
const line = editor.getLine(cursor.line);
|
|
||||||
|
|
||||||
// Get the text from the start of the line to the cursor
|
|
||||||
const textToCursor = line.slice(0, cursor.ch);
|
|
||||||
|
|
||||||
// Do not autosuggest emojis in curly span/div/injector properties
|
|
||||||
if(line.includes('{')) {
|
|
||||||
const curlyToCursor = textToCursor.slice(textToCursor.indexOf(`{`));
|
|
||||||
const curlySpanRegex = /{(?=((?:[:=](?:"[\w,\-()#%. ]*"|[\w\-()#%.]*)|[^"':={}\s]*)*))\1$/g;
|
|
||||||
|
|
||||||
if(curlySpanRegex.test(curlyToCursor))
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the text ends with ':xyz'
|
|
||||||
if(/:[^\s:]+$/.test(textToCursor)) {
|
|
||||||
CodeMirror.commands.autocomplete(editor);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
showAutocompleteEmoji
|
|
||||||
};
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
const autoCloseCurlyBraces = function(CodeMirror, cm, typingClosingBrace) {
|
|
||||||
const ranges = cm.listSelections(), replacements = [];
|
|
||||||
for (let i = 0; i < ranges.length; i++) {
|
|
||||||
if(!ranges[i].empty()) return CodeMirror.Pass;
|
|
||||||
const pos = ranges[i].head, line = cm.getLine(pos.line), tok = cm.getTokenAt(pos);
|
|
||||||
if(!typingClosingBrace && (tok.type == 'string' || tok.string.charAt(0) != '{' || tok.start != pos.ch - 1))
|
|
||||||
return CodeMirror.Pass;
|
|
||||||
else if(typingClosingBrace) {
|
|
||||||
let hasUnclosedBraces = false, index = -1;
|
|
||||||
do {
|
|
||||||
index = line.indexOf('{{', index + 1);
|
|
||||||
if(index !== -1 && line.indexOf('}}', index + 1) === -1) {
|
|
||||||
hasUnclosedBraces = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while (index !== -1);
|
|
||||||
if(!hasUnclosedBraces) return CodeMirror.Pass;
|
|
||||||
}
|
|
||||||
|
|
||||||
replacements[i] = typingClosingBrace ? {
|
|
||||||
text : '}}',
|
|
||||||
newPos : CodeMirror.Pos(pos.line, pos.ch + 2)
|
|
||||||
} : {
|
|
||||||
text : '{}}',
|
|
||||||
newPos : CodeMirror.Pos(pos.line, pos.ch + 1)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = ranges.length - 1; i >= 0; i--) {
|
|
||||||
const info = replacements[i];
|
|
||||||
cm.replaceRange(info.text, ranges[i].head, ranges[i].anchor, '+insert');
|
|
||||||
const sel = cm.listSelections().slice(0);
|
|
||||||
sel[i] = {
|
|
||||||
head : info.newPos,
|
|
||||||
anchor : info.newPos
|
|
||||||
};
|
|
||||||
cm.setSelections(sel);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
autoCloseCurlyBraces : function(CodeMirror, codeMirror) {
|
|
||||||
const map = { name: 'autoCloseCurlyBraces' };
|
|
||||||
map[`'{'`] = function(cm) { return autoCloseCurlyBraces(CodeMirror, cm); };
|
|
||||||
map[`'}'`] = function(cm) { return autoCloseCurlyBraces(CodeMirror, cm, true); };
|
|
||||||
codeMirror.addKeyMap(map);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,465 +1,442 @@
|
|||||||
/* eslint-disable max-lines */
|
/* eslint max-lines: ["error", { "max": 455 }] */
|
||||||
require('./codeEditor.less');
|
import './codeEditor.less';
|
||||||
const React = require('react');
|
import React, { useEffect, useRef, forwardRef, useImperativeHandle } from 'react';
|
||||||
const createClass = require('create-react-class');
|
|
||||||
const _ = require('lodash');
|
|
||||||
const closeTag = require('./close-tag');
|
|
||||||
const autoCompleteEmoji = require('./autocompleteEmoji');
|
|
||||||
|
|
||||||
let CodeMirror;
|
import {
|
||||||
if(typeof window !== 'undefined'){
|
EditorView,
|
||||||
CodeMirror = require('codemirror');
|
keymap,
|
||||||
|
lineNumbers,
|
||||||
|
highlightActiveLineGutter,
|
||||||
|
highlightActiveLine,
|
||||||
|
scrollPastEnd,
|
||||||
|
Decoration,
|
||||||
|
drawSelection,
|
||||||
|
dropCursor,
|
||||||
|
rectangularSelection,
|
||||||
|
crosshairCursor,
|
||||||
|
} from '@codemirror/view';
|
||||||
|
import { EditorState, Compartment, StateEffect, StateField } from '@codemirror/state';
|
||||||
|
import {
|
||||||
|
unfoldAll as unfoldAllCmd,
|
||||||
|
foldGutter,
|
||||||
|
foldKeymap,
|
||||||
|
foldEffect,
|
||||||
|
foldState,
|
||||||
|
syntaxHighlighting,
|
||||||
|
} from '@codemirror/language';
|
||||||
|
import { defaultKeymap, history, undo, redo, undoDepth, redoDepth } from '@codemirror/commands';
|
||||||
|
import { languages } from '@codemirror/language-data';
|
||||||
|
import { css } from '@codemirror/lang-css';
|
||||||
|
import { markdown, markdownLanguage } from '@codemirror/lang-markdown';
|
||||||
|
import { html } from '@codemirror/lang-html';
|
||||||
|
import { autocompleteEmoji } from './extensions/autocompleteEmoji.js';
|
||||||
|
import { searchKeymap, search } from '@codemirror/search';
|
||||||
|
import { closeBrackets } from '@codemirror/autocomplete';
|
||||||
|
|
||||||
//Language Modes
|
const autoCloseBrackets = closeBrackets({ brackets: ['()', '[]', '{{}}'] });
|
||||||
require('codemirror/mode/gfm/gfm.js'); //Github flavoured markdown
|
|
||||||
require('codemirror/mode/css/css.js');
|
|
||||||
require('codemirror/mode/javascript/javascript.js');
|
|
||||||
|
|
||||||
//Addons
|
import defaultCM5Theme from '@themes/codeMirror/default.js';
|
||||||
//Code folding
|
import darkbrewery from '@themes/codeMirror/darkbrewery.js';
|
||||||
require('codemirror/addon/fold/foldcode.js');
|
import cm5Themes from 'codemirror-5-themes';
|
||||||
require('codemirror/addon/fold/foldgutter.js');
|
|
||||||
//Search and replace
|
|
||||||
require('codemirror/addon/search/search.js');
|
|
||||||
require('codemirror/addon/search/searchcursor.js');
|
|
||||||
require('codemirror/addon/search/jump-to-line.js');
|
|
||||||
require('codemirror/addon/search/match-highlighter.js');
|
|
||||||
require('codemirror/addon/search/matchesonscrollbar.js');
|
|
||||||
require('codemirror/addon/dialog/dialog.js');
|
|
||||||
//Trailing space highlighting
|
|
||||||
// require('codemirror/addon/edit/trailingspace.js');
|
|
||||||
//Active line highlighting
|
|
||||||
// require('codemirror/addon/selection/active-line.js');
|
|
||||||
//Scroll past last line
|
|
||||||
require('codemirror/addon/scroll/scrollpastend.js');
|
|
||||||
//Auto-closing
|
|
||||||
//XML code folding is a requirement of the auto-closing tag feature and is not enabled
|
|
||||||
require('codemirror/addon/fold/xml-fold.js');
|
|
||||||
require('codemirror/addon/edit/closetag.js');
|
|
||||||
//Autocompletion
|
|
||||||
require('codemirror/addon/hint/show-hint.js');
|
|
||||||
|
|
||||||
const foldPagesCode = require('./fold-pages');
|
const themes = { default: defaultCM5Theme, ...cm5Themes, darkbrewery };
|
||||||
foldPagesCode.registerHomebreweryHelper(CodeMirror);
|
const themeCompartment = new Compartment();
|
||||||
const foldCSSCode = require('./fold-css');
|
const highlightCompartment = new Compartment();
|
||||||
foldCSSCode.registerHomebreweryHelper(CodeMirror);
|
const settingsCompartment = new Compartment();
|
||||||
}
|
|
||||||
|
|
||||||
const CodeEditor = createClass({
|
import { generalKeymap, markdownKeymap, cssKeymap, formatCSS } from './extensions/customKeyMaps.js';
|
||||||
displayName : 'CodeEditor',
|
import foldOnPages from './extensions/customFolding.js';
|
||||||
getDefaultProps : function() {
|
import { customHighlightStyle, customHighlightPlugin } from './extensions/customHighlight.js';
|
||||||
return {
|
import { legacyCustomHighlightStyle } from './extensions/legacyCustomHighlight.js';
|
||||||
language : '',
|
|
||||||
value : '',
|
const PAGEBREAK_REGEX_V3 = /^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m;
|
||||||
wrap : true,
|
|
||||||
onChange : ()=>{},
|
const setProgrammaticCursorLine = StateEffect.define();
|
||||||
enableFolding : true,
|
|
||||||
editorTheme : 'default'
|
const programmaticCursorLineField = StateField.define({
|
||||||
};
|
create() {
|
||||||
|
return Decoration.none;
|
||||||
},
|
},
|
||||||
|
update(decorations, transitionState) {
|
||||||
|
//deco is the decoratiions object
|
||||||
|
//tr is the transition state object, tr.effects is an array of stateEffects
|
||||||
|
//seems to be the easiest way of setting a class programatically only when called
|
||||||
|
for (const effects of transitionState.effects) {
|
||||||
|
if(effects.is(setProgrammaticCursorLine)) {
|
||||||
|
const pos = effects.value;
|
||||||
|
if(pos == null) return Decoration.none;
|
||||||
|
const line = transitionState.state.doc.lineAt(pos);
|
||||||
|
|
||||||
getInitialState : function() {
|
return Decoration.set([
|
||||||
return {
|
Decoration.line({
|
||||||
docs : {}
|
class : 'sourceMoveFlash'
|
||||||
};
|
}).range(line.from)
|
||||||
},
|
]);
|
||||||
|
|
||||||
editor : React.createRef(null),
|
|
||||||
|
|
||||||
componentDidMount : function() {
|
|
||||||
this.buildEditor();
|
|
||||||
const newDoc = CodeMirror.Doc(this.props.value, this.props.language);
|
|
||||||
this.codeMirror.swapDoc(newDoc);
|
|
||||||
},
|
|
||||||
|
|
||||||
componentDidUpdate : function(prevProps) {
|
|
||||||
if(prevProps.view !== this.props.view){ //view changed; swap documents
|
|
||||||
let newDoc;
|
|
||||||
|
|
||||||
if(!this.state.docs[this.props.view]) {
|
|
||||||
newDoc = CodeMirror.Doc(this.props.value, this.props.language);
|
|
||||||
} else {
|
|
||||||
newDoc = this.state.docs[this.props.view];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldDoc = { [prevProps.view]: this.codeMirror.swapDoc(newDoc) };
|
|
||||||
|
|
||||||
this.setState((prevState)=>({
|
|
||||||
docs : _.merge({}, prevState.docs, oldDoc)
|
|
||||||
}));
|
|
||||||
|
|
||||||
this.props.rerenderParent();
|
|
||||||
} else if(this.codeMirror?.getValue() != this.props.value) { //update editor contents if brew.text is changed from outside
|
|
||||||
this.codeMirror.setValue(this.props.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.props.enableFolding) {
|
|
||||||
this.codeMirror.setOption('foldOptions', this.foldOptions(this.codeMirror));
|
|
||||||
} else {
|
|
||||||
this.codeMirror.setOption('foldOptions', false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(prevProps.editorTheme !== this.props.editorTheme){
|
|
||||||
this.codeMirror.setOption('theme', this.props.editorTheme);
|
|
||||||
}
|
}
|
||||||
|
return decorations;
|
||||||
},
|
},
|
||||||
|
provide : (decorationSet)=>EditorView.decorations.from(decorationSet)
|
||||||
buildEditor : function() {
|
|
||||||
this.codeMirror = CodeMirror(this.editor.current, {
|
|
||||||
lineNumbers : true,
|
|
||||||
lineWrapping : this.props.wrap,
|
|
||||||
indentWithTabs : false,
|
|
||||||
tabSize : 2,
|
|
||||||
smartIndent : false,
|
|
||||||
historyEventDelay : 250,
|
|
||||||
scrollPastEnd : true,
|
|
||||||
extraKeys : {
|
|
||||||
'Tab' : this.indent,
|
|
||||||
'Shift-Tab' : this.dedent,
|
|
||||||
'Ctrl-B' : this.makeBold,
|
|
||||||
'Cmd-B' : this.makeBold,
|
|
||||||
'Shift-Ctrl-=' : this.makeSuper,
|
|
||||||
'Shift-Cmd-=' : this.makeSuper,
|
|
||||||
'Ctrl-=' : this.makeSub,
|
|
||||||
'Cmd-=' : this.makeSub,
|
|
||||||
'Ctrl-I' : this.makeItalic,
|
|
||||||
'Cmd-I' : this.makeItalic,
|
|
||||||
'Ctrl-U' : this.makeUnderline,
|
|
||||||
'Cmd-U' : this.makeUnderline,
|
|
||||||
'Ctrl-.' : this.makeNbsp,
|
|
||||||
'Cmd-.' : this.makeNbsp,
|
|
||||||
'Shift-Ctrl-.' : this.makeSpace,
|
|
||||||
'Shift-Cmd-.' : this.makeSpace,
|
|
||||||
'Shift-Ctrl-,' : this.removeSpace,
|
|
||||||
'Shift-Cmd-,' : this.removeSpace,
|
|
||||||
'Ctrl-M' : this.makeSpan,
|
|
||||||
'Cmd-M' : this.makeSpan,
|
|
||||||
'Shift-Ctrl-M' : this.makeDiv,
|
|
||||||
'Shift-Cmd-M' : this.makeDiv,
|
|
||||||
'Ctrl-/' : this.makeComment,
|
|
||||||
'Cmd-/' : this.makeComment,
|
|
||||||
'Ctrl-K' : this.makeLink,
|
|
||||||
'Cmd-K' : this.makeLink,
|
|
||||||
'Ctrl-L' : ()=>this.makeList('UL'),
|
|
||||||
'Cmd-L' : ()=>this.makeList('UL'),
|
|
||||||
'Shift-Ctrl-L' : ()=>this.makeList('OL'),
|
|
||||||
'Shift-Cmd-L' : ()=>this.makeList('OL'),
|
|
||||||
'Shift-Ctrl-1' : ()=>this.makeHeader(1),
|
|
||||||
'Shift-Ctrl-2' : ()=>this.makeHeader(2),
|
|
||||||
'Shift-Ctrl-3' : ()=>this.makeHeader(3),
|
|
||||||
'Shift-Ctrl-4' : ()=>this.makeHeader(4),
|
|
||||||
'Shift-Ctrl-5' : ()=>this.makeHeader(5),
|
|
||||||
'Shift-Ctrl-6' : ()=>this.makeHeader(6),
|
|
||||||
'Shift-Cmd-1' : ()=>this.makeHeader(1),
|
|
||||||
'Shift-Cmd-2' : ()=>this.makeHeader(2),
|
|
||||||
'Shift-Cmd-3' : ()=>this.makeHeader(3),
|
|
||||||
'Shift-Cmd-4' : ()=>this.makeHeader(4),
|
|
||||||
'Shift-Cmd-5' : ()=>this.makeHeader(5),
|
|
||||||
'Shift-Cmd-6' : ()=>this.makeHeader(6),
|
|
||||||
'Shift-Ctrl-Enter' : this.newColumn,
|
|
||||||
'Shift-Cmd-Enter' : this.newColumn,
|
|
||||||
'Ctrl-Enter' : this.newPage,
|
|
||||||
'Cmd-Enter' : this.newPage,
|
|
||||||
'Ctrl-F' : 'findPersistent',
|
|
||||||
'Cmd-F' : 'findPersistent',
|
|
||||||
'Shift-Enter' : 'findPersistentPrevious',
|
|
||||||
'Ctrl-[' : this.foldAllCode,
|
|
||||||
'Cmd-[' : this.foldAllCode,
|
|
||||||
'Ctrl-]' : this.unfoldAllCode,
|
|
||||||
'Cmd-]' : this.unfoldAllCode
|
|
||||||
},
|
|
||||||
foldGutter : true,
|
|
||||||
foldOptions : this.foldOptions(this.codeMirror),
|
|
||||||
gutters : ['CodeMirror-linenumbers', 'CodeMirror-foldgutter'],
|
|
||||||
autoCloseTags : true,
|
|
||||||
styleActiveLine : true,
|
|
||||||
showTrailingSpace : false,
|
|
||||||
theme : this.props.editorTheme
|
|
||||||
// specialChars : / /,
|
|
||||||
// specialCharPlaceholder : function(char) {
|
|
||||||
// const el = document.createElement('span');
|
|
||||||
// el.className = 'cm-space';
|
|
||||||
// el.innerHTML = ' ';
|
|
||||||
// return el;
|
|
||||||
// }
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add custom behaviors (auto-close curlies and auto-complete emojis)
|
|
||||||
closeTag.autoCloseCurlyBraces(CodeMirror, this.codeMirror);
|
|
||||||
autoCompleteEmoji.showAutocompleteEmoji(CodeMirror, this.codeMirror);
|
|
||||||
|
|
||||||
// Note: codeMirror passes a copy of itself in this callback. cm === this.codeMirror. Either one works.
|
|
||||||
this.codeMirror.on('change', (cm)=>{this.props.onChange(cm.getValue());});
|
|
||||||
this.updateSize();
|
|
||||||
},
|
|
||||||
|
|
||||||
indent : function () {
|
|
||||||
const cm = this.codeMirror;
|
|
||||||
if(cm.somethingSelected()) {
|
|
||||||
cm.execCommand('indentMore');
|
|
||||||
} else {
|
|
||||||
cm.execCommand('insertSoftTab');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
dedent : function () {
|
|
||||||
this.codeMirror.execCommand('indentLess');
|
|
||||||
},
|
|
||||||
|
|
||||||
makeHeader : function (number) {
|
|
||||||
const selection = this.codeMirror.getSelection();
|
|
||||||
const header = Array(number).fill('#').join('');
|
|
||||||
this.codeMirror.replaceSelection(`${header} ${selection}`, 'around');
|
|
||||||
const cursor = this.codeMirror.getCursor();
|
|
||||||
this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch + selection.length + number + 1 });
|
|
||||||
},
|
|
||||||
|
|
||||||
makeBold : function() {
|
|
||||||
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 2) === '**' && selection.slice(-2) === '**';
|
|
||||||
this.codeMirror.replaceSelection(t ? selection.slice(2, -2) : `**${selection}**`, 'around');
|
|
||||||
if(selection.length === 0){
|
|
||||||
const cursor = this.codeMirror.getCursor();
|
|
||||||
this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - 2 });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
makeItalic : function() {
|
|
||||||
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 1) === '*' && selection.slice(-1) === '*';
|
|
||||||
this.codeMirror.replaceSelection(t ? selection.slice(1, -1) : `*${selection}*`, 'around');
|
|
||||||
if(selection.length === 0){
|
|
||||||
const cursor = this.codeMirror.getCursor();
|
|
||||||
this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - 1 });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
makeSuper : function() {
|
|
||||||
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 1) === '^' && selection.slice(-1) === '^';
|
|
||||||
this.codeMirror.replaceSelection(t ? selection.slice(1, -1) : `^${selection}^`, 'around');
|
|
||||||
if(selection.length === 0){
|
|
||||||
const cursor = this.codeMirror.getCursor();
|
|
||||||
this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - 1 });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
makeSub : function() {
|
|
||||||
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 2) === '^^' && selection.slice(-2) === '^^';
|
|
||||||
this.codeMirror.replaceSelection(t ? selection.slice(2, -2) : `^^${selection}^^`, 'around');
|
|
||||||
if(selection.length === 0){
|
|
||||||
const cursor = this.codeMirror.getCursor();
|
|
||||||
this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - 2 });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
makeNbsp : function() {
|
|
||||||
this.codeMirror.replaceSelection(' ', 'end');
|
|
||||||
},
|
|
||||||
|
|
||||||
makeSpace : function() {
|
|
||||||
const selection = this.codeMirror.getSelection();
|
|
||||||
const t = selection.slice(0, 8) === '{{width:' && selection.slice(0 -4) === '% }}';
|
|
||||||
if(t){
|
|
||||||
const percent = parseInt(selection.slice(8, -4)) + 10;
|
|
||||||
this.codeMirror.replaceSelection(percent < 90 ? `{{width:${percent}% }}` : '{{width:100% }}', 'around');
|
|
||||||
} else {
|
|
||||||
this.codeMirror.replaceSelection(`{{width:10% }}`, 'around');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
removeSpace : function() {
|
|
||||||
const selection = this.codeMirror.getSelection();
|
|
||||||
const t = selection.slice(0, 8) === '{{width:' && selection.slice(0 -4) === '% }}';
|
|
||||||
if(t){
|
|
||||||
const percent = parseInt(selection.slice(8, -4)) - 10;
|
|
||||||
this.codeMirror.replaceSelection(percent > 10 ? `{{width:${percent}% }}` : '', 'around');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
newColumn : function() {
|
|
||||||
this.codeMirror.replaceSelection('\n\\column\n\n', 'end');
|
|
||||||
},
|
|
||||||
|
|
||||||
newPage : function() {
|
|
||||||
this.codeMirror.replaceSelection('\n\\page\n\n', 'end');
|
|
||||||
},
|
|
||||||
|
|
||||||
injectText : function(injectText, overwrite=true) {
|
|
||||||
const cm = this.codeMirror;
|
|
||||||
if(!overwrite) {
|
|
||||||
cm.setCursor(cm.getCursor('from'));
|
|
||||||
}
|
|
||||||
cm.replaceSelection(injectText, 'end');
|
|
||||||
cm.focus();
|
|
||||||
},
|
|
||||||
|
|
||||||
makeUnderline : function() {
|
|
||||||
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 3) === '<u>' && selection.slice(-4) === '</u>';
|
|
||||||
this.codeMirror.replaceSelection(t ? selection.slice(3, -4) : `<u>${selection}</u>`, 'around');
|
|
||||||
if(selection.length === 0){
|
|
||||||
const cursor = this.codeMirror.getCursor();
|
|
||||||
this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - 4 });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
makeSpan : function() {
|
|
||||||
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 2) === '{{' && selection.slice(-2) === '}}';
|
|
||||||
this.codeMirror.replaceSelection(t ? selection.slice(2, -2) : `{{ ${selection}}}`, 'around');
|
|
||||||
if(selection.length === 0){
|
|
||||||
const cursor = this.codeMirror.getCursor();
|
|
||||||
this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - 2 });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
makeDiv : function() {
|
|
||||||
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 2) === '{{' && selection.slice(-2) === '}}';
|
|
||||||
this.codeMirror.replaceSelection(t ? selection.slice(2, -2) : `{{\n${selection}\n}}`, 'around');
|
|
||||||
if(selection.length === 0){
|
|
||||||
const cursor = this.codeMirror.getCursor();
|
|
||||||
this.codeMirror.setCursor({ line: cursor.line - 1, ch: cursor.ch }); // set to -2? if wanting to enter classes etc. if so, get rid of first \n when replacing selection
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
makeComment : function() {
|
|
||||||
let regex;
|
|
||||||
let cursorPos;
|
|
||||||
let newComment;
|
|
||||||
const selection = this.codeMirror.getSelection();
|
|
||||||
if(this.props.language === 'gfm'){
|
|
||||||
regex = /^\s*(<!--\s?)(.*?)(\s?-->)\s*$/gs;
|
|
||||||
cursorPos = 4;
|
|
||||||
newComment = `<!-- ${selection} -->`;
|
|
||||||
} else {
|
|
||||||
regex = /^\s*(\/\*\s?)(.*?)(\s?\*\/)\s*$/gs;
|
|
||||||
cursorPos = 3;
|
|
||||||
newComment = `/* ${selection} */`;
|
|
||||||
}
|
|
||||||
this.codeMirror.replaceSelection(regex.test(selection) == true ? selection.replace(regex, '$2') : newComment, 'around');
|
|
||||||
if(selection.length === 0){
|
|
||||||
const cursor = this.codeMirror.getCursor();
|
|
||||||
this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - cursorPos });
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
makeLink : function() {
|
|
||||||
const isLink = /^\[(.*)\]\((.*)\)$/;
|
|
||||||
const selection = this.codeMirror.getSelection().trim();
|
|
||||||
let match;
|
|
||||||
if(match = isLink.exec(selection)){
|
|
||||||
const altText = match[1];
|
|
||||||
const url = match[2];
|
|
||||||
this.codeMirror.replaceSelection(`${altText} ${url}`);
|
|
||||||
const cursor = this.codeMirror.getCursor();
|
|
||||||
this.codeMirror.setSelection({ line: cursor.line, ch: cursor.ch - url.length }, { line: cursor.line, ch: cursor.ch });
|
|
||||||
} else {
|
|
||||||
this.codeMirror.replaceSelection(`[${selection || 'alt text'}](url)`);
|
|
||||||
const cursor = this.codeMirror.getCursor();
|
|
||||||
this.codeMirror.setSelection({ line: cursor.line, ch: cursor.ch - 4 }, { line: cursor.line, ch: cursor.ch - 1 });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
makeList : function(listType) {
|
|
||||||
const selectionStart = this.codeMirror.getCursor('from'), selectionEnd = this.codeMirror.getCursor('to');
|
|
||||||
this.codeMirror.setSelection(
|
|
||||||
{ line: selectionStart.line, ch: 0 },
|
|
||||||
{ line: selectionEnd.line, ch: this.codeMirror.getLine(selectionEnd.line).length }
|
|
||||||
);
|
|
||||||
const newSelection = this.codeMirror.getSelection();
|
|
||||||
|
|
||||||
const regex = /^\d+\.\s|^-\s/gm;
|
|
||||||
if(newSelection.match(regex) != null){ // if selection IS A LIST
|
|
||||||
this.codeMirror.replaceSelection(newSelection.replace(regex, ''), 'around');
|
|
||||||
} else { // if selection IS NOT A LIST
|
|
||||||
listType == 'UL' ? this.codeMirror.replaceSelection(newSelection.replace(/^/gm, `- `), 'around') :
|
|
||||||
this.codeMirror.replaceSelection(newSelection.replace(/^/gm, (()=>{
|
|
||||||
let n = 1;
|
|
||||||
return ()=>{
|
|
||||||
return `${n++}. `;
|
|
||||||
};
|
|
||||||
})()), 'around');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
foldAllCode : function() {
|
|
||||||
this.codeMirror.execCommand('foldAll');
|
|
||||||
},
|
|
||||||
|
|
||||||
unfoldAllCode : function() {
|
|
||||||
this.codeMirror.execCommand('unfoldAll');
|
|
||||||
},
|
|
||||||
|
|
||||||
//=-- Externally used -==//
|
|
||||||
setCursorPosition : function(line, char){
|
|
||||||
setTimeout(()=>{
|
|
||||||
this.codeMirror.focus();
|
|
||||||
this.codeMirror.doc.setCursor(line, char);
|
|
||||||
}, 10);
|
|
||||||
},
|
|
||||||
getCursorPosition : function(){
|
|
||||||
return this.codeMirror.getCursor();
|
|
||||||
},
|
|
||||||
getTopVisibleLine : function(){
|
|
||||||
const rect = this.codeMirror.getWrapperElement().getBoundingClientRect();
|
|
||||||
const topVisibleLine = this.codeMirror.lineAtHeight(rect.top, 'window');
|
|
||||||
return topVisibleLine;
|
|
||||||
},
|
|
||||||
updateSize : function(){
|
|
||||||
this.codeMirror.refresh();
|
|
||||||
},
|
|
||||||
redo : function(){
|
|
||||||
return this.codeMirror.redo();
|
|
||||||
},
|
|
||||||
undo : function(){
|
|
||||||
return this.codeMirror.undo();
|
|
||||||
},
|
|
||||||
historySize : function(){
|
|
||||||
return this.codeMirror.doc.historySize();
|
|
||||||
},
|
|
||||||
|
|
||||||
foldOptions : function(cm){
|
|
||||||
return {
|
|
||||||
scanUp : true,
|
|
||||||
rangeFinder : this.props.language === 'css' ? CodeMirror.fold.homebrewerycss : CodeMirror.fold.homebrewery,
|
|
||||||
widget : (from, to)=>{
|
|
||||||
let text = '';
|
|
||||||
let currentLine = from.line;
|
|
||||||
let maxLength = 50;
|
|
||||||
|
|
||||||
let foldPreviewText = '';
|
|
||||||
while (currentLine <= to.line && text.length <= maxLength) {
|
|
||||||
const currentText = this.codeMirror.getLine(currentLine);
|
|
||||||
currentLine++;
|
|
||||||
if(currentText[0] == '#'){
|
|
||||||
foldPreviewText = currentText;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(!foldPreviewText && currentText != '\n') {
|
|
||||||
foldPreviewText = currentText;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
text = foldPreviewText || `Lines ${from.line+1}-${to.line+1}`;
|
|
||||||
text = text.replace('{', '').trim();
|
|
||||||
|
|
||||||
// Truncate data URLs at `data:`
|
|
||||||
const startOfData = text.indexOf('data:');
|
|
||||||
if(startOfData > 0)
|
|
||||||
maxLength = Math.min(startOfData + 5, maxLength);
|
|
||||||
|
|
||||||
if(text.length > maxLength)
|
|
||||||
text = `${text.slice(0, maxLength)}...`;
|
|
||||||
|
|
||||||
return `\u21A4 ${text} \u21A6`;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
},
|
|
||||||
//----------------------//
|
|
||||||
|
|
||||||
render : function(){
|
|
||||||
return <>
|
|
||||||
<link href={`../homebrew/cm-themes/${this.props.editorTheme}.css`} type='text/css' rel='stylesheet' />
|
|
||||||
<div className='codeEditor' ref={this.editor} style={this.props.style}/>
|
|
||||||
</>;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = CodeEditor;
|
const createSettingsExtensions = (settings)=>[
|
||||||
|
...(settings.autoCloseBrackets ? [autoCloseBrackets] : []),
|
||||||
|
...(settings.lineNumbers ? [lineNumbers()] : []),
|
||||||
|
...(settings.activeLineShading ? [highlightActiveLine(),
|
||||||
|
highlightActiveLineGutter()] : []),
|
||||||
|
...(settings.fontSize
|
||||||
|
? [EditorView.theme({
|
||||||
|
'&, .cm-content' : {
|
||||||
|
fontSize : `${settings.fontSize || 1}em`,
|
||||||
|
},
|
||||||
|
})]
|
||||||
|
: []),
|
||||||
|
];
|
||||||
|
|
||||||
|
const CodeEditor = forwardRef(
|
||||||
|
(
|
||||||
|
{
|
||||||
|
language = '',
|
||||||
|
tab = 'brewText',
|
||||||
|
view,
|
||||||
|
value = '',
|
||||||
|
onChange = ()=>{},
|
||||||
|
onCursorChange = ()=>{},
|
||||||
|
onViewChange = ()=>{},
|
||||||
|
onThemeChange = ()=>{},
|
||||||
|
editorTheme = 'default',
|
||||||
|
style,
|
||||||
|
renderer,
|
||||||
|
settings = {},
|
||||||
|
...props
|
||||||
|
},
|
||||||
|
ref,
|
||||||
|
)=>{
|
||||||
|
const editorRef = useRef(null);
|
||||||
|
const viewRef = useRef(null);
|
||||||
|
const docsRef = useRef({});
|
||||||
|
const tabRef = useRef(tab);
|
||||||
|
const prevTabRef = useRef(tab);
|
||||||
|
const scrollRef = useRef({});
|
||||||
|
const foldsRef = useRef({});
|
||||||
|
const pageMap = useRef([]);
|
||||||
|
|
||||||
|
const recomputePages = (doc)=>{
|
||||||
|
if(tab !== 'brewText') return;
|
||||||
|
const pages = [0];
|
||||||
|
const text = doc.toString();
|
||||||
|
let offset = 0;
|
||||||
|
|
||||||
|
for (const line of text.split('\n')) {
|
||||||
|
if(PAGEBREAK_REGEX_V3.test(line)) {
|
||||||
|
pages.push(offset);
|
||||||
|
}
|
||||||
|
offset += line.length + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pageMap.current = pages;
|
||||||
|
};
|
||||||
|
|
||||||
|
const findPageFromPos = (pos)=>{
|
||||||
|
const pages = pageMap.current;
|
||||||
|
let page = 1;
|
||||||
|
|
||||||
|
for (let i = 1; i < pages.length; i++) {
|
||||||
|
if(pos >= pages[i]) page = i + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return page;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getFoldRanges = (state)=>{
|
||||||
|
const folds = [];
|
||||||
|
state.field(foldState, false)?.between(0, state.doc.length, (from, to)=>{
|
||||||
|
folds.push({ from, to });
|
||||||
|
});
|
||||||
|
return folds;
|
||||||
|
};
|
||||||
|
|
||||||
|
const foldAll = (view = viewRef.current)=>{
|
||||||
|
if(!view) return false;
|
||||||
|
|
||||||
|
const doc = view.state.doc;
|
||||||
|
const pages = pageMap.current;
|
||||||
|
|
||||||
|
const effects = pages.map((start, i)=>{
|
||||||
|
const next = pages[i + 1] || doc.length;
|
||||||
|
const from = i ? doc.line(doc.lineAt(start).number + 1).from : 0;
|
||||||
|
const to = doc.line(doc.lineAt(next).number).from - 1;
|
||||||
|
|
||||||
|
return to > from ? foldEffect.of({ from, to }) : null;
|
||||||
|
}).filter(Boolean);
|
||||||
|
|
||||||
|
view.dispatch({ effects });
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const unfoldAll = (view = viewRef.current)=>{
|
||||||
|
if(!view) return false;
|
||||||
|
|
||||||
|
view.dispatch(unfoldAllCmd(view));
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const createExtensions = ({ onChange, language, editorTheme })=>{
|
||||||
|
const setEventListeners = EditorView.updateListener.of((update)=>{
|
||||||
|
if(update.docChanged) {
|
||||||
|
recomputePages(update.state.doc);
|
||||||
|
onChange(update.state.doc.toString());
|
||||||
|
}
|
||||||
|
if(update.selectionSet) {
|
||||||
|
const pos = update.state.selection.main.head;
|
||||||
|
const page = findPageFromPos(pos);
|
||||||
|
onCursorChange(page);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const highlightExtension = renderer === 'V3'
|
||||||
|
? syntaxHighlighting(customHighlightStyle)
|
||||||
|
: syntaxHighlighting(legacyCustomHighlightStyle);
|
||||||
|
|
||||||
|
const languageExtension = language === 'css' ? css() : [markdown({ base: markdownLanguage, codeLanguages: languages }), html({ autoCloseTags: true })];
|
||||||
|
const themeExtension = Array.isArray(themes[editorTheme]) ? themes[editorTheme] : themes[editorTheme] || themes['default'];
|
||||||
|
|
||||||
|
return [
|
||||||
|
EditorView.lineWrapping,
|
||||||
|
setEventListeners,
|
||||||
|
languageExtension,
|
||||||
|
settingsCompartment.of(createSettingsExtensions(settings)),
|
||||||
|
scrollPastEnd(),
|
||||||
|
search(),
|
||||||
|
history(), //allows for undo and redo
|
||||||
|
...(tab !== 'brewStyles' ? [autocompleteEmoji] : []),
|
||||||
|
|
||||||
|
//folding
|
||||||
|
foldOnPages,
|
||||||
|
foldGutter({
|
||||||
|
openText : '▾',
|
||||||
|
closedText : '▸'
|
||||||
|
}),
|
||||||
|
|
||||||
|
//highlights
|
||||||
|
highlightCompartment.of([customHighlightPlugin(renderer, tab, settings), highlightExtension]),
|
||||||
|
themeCompartment.of(themeExtension),
|
||||||
|
|
||||||
|
//keyboard shortcut
|
||||||
|
keymap.of([...defaultKeymap, foldKeymap, ...searchKeymap]),
|
||||||
|
generalKeymap(foldAll, unfoldAll),
|
||||||
|
...(tab === 'brewStyles' ? [cssKeymap] : [markdownKeymap]),
|
||||||
|
|
||||||
|
//multiple cursors and selections
|
||||||
|
drawSelection(),
|
||||||
|
rectangularSelection(),
|
||||||
|
crosshairCursor(),
|
||||||
|
EditorState.allowMultipleSelections.of(true),
|
||||||
|
dropCursor(),
|
||||||
|
programmaticCursorLineField,
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
if(!editorRef.current) return;
|
||||||
|
|
||||||
|
const state = EditorState.create({
|
||||||
|
doc : value,
|
||||||
|
extensions : createExtensions({ onChange, language, editorTheme }),
|
||||||
|
});
|
||||||
|
|
||||||
|
recomputePages(state.doc);
|
||||||
|
|
||||||
|
viewRef.current = new EditorView({
|
||||||
|
state,
|
||||||
|
parent : editorRef.current,
|
||||||
|
});
|
||||||
|
|
||||||
|
const view = viewRef.current;
|
||||||
|
|
||||||
|
let ticking = false;
|
||||||
|
|
||||||
|
const handleScroll = ()=>{
|
||||||
|
if(ticking) return;
|
||||||
|
|
||||||
|
ticking = true;
|
||||||
|
requestAnimationFrame(()=>{
|
||||||
|
const top = view.scrollDOM.scrollTop;
|
||||||
|
scrollRef.current[tabRef.current] = top;
|
||||||
|
const block = view.lineBlockAtHeight(top);
|
||||||
|
const page = findPageFromPos(block.from);
|
||||||
|
onViewChange(page);
|
||||||
|
ticking = false;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
view.scrollDOM.addEventListener('scroll', handleScroll);
|
||||||
|
|
||||||
|
docsRef.current[tab] = state;
|
||||||
|
|
||||||
|
return ()=>{
|
||||||
|
view.scrollDOM.removeEventListener('scroll', handleScroll);
|
||||||
|
viewRef.current?.destroy();
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const restoreFolds = (view, folds)=>{
|
||||||
|
if(!folds?.length) return;
|
||||||
|
|
||||||
|
view.dispatch({
|
||||||
|
effects : folds.map((f)=>foldEffect.of(f))
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
const view = viewRef.current;
|
||||||
|
if(!view) return;
|
||||||
|
|
||||||
|
tabRef.current = tab;
|
||||||
|
const prevTab = prevTabRef.current;
|
||||||
|
|
||||||
|
foldsRef.current[prevTab] = getFoldRanges(view.state);
|
||||||
|
|
||||||
|
if(prevTab !== tab) {
|
||||||
|
docsRef.current[prevTab] = view.state;
|
||||||
|
|
||||||
|
let nextState = docsRef.current[tab];
|
||||||
|
|
||||||
|
if(!nextState) {
|
||||||
|
nextState = EditorState.create({
|
||||||
|
doc : value,
|
||||||
|
extensions : createExtensions({ onChange, language, editorTheme }),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
view.setState(nextState);
|
||||||
|
view.dispatch({
|
||||||
|
effects : settingsCompartment.reconfigure(
|
||||||
|
createSettingsExtensions(settings)
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
restoreFolds(view, foldsRef.current[tab]);
|
||||||
|
|
||||||
|
const savedScroll = scrollRef.current[tab];
|
||||||
|
|
||||||
|
if(savedScroll != null) {
|
||||||
|
requestAnimationFrame(()=>{
|
||||||
|
view.scrollDOM.scrollTop = savedScroll;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
prevTabRef.current = tab;
|
||||||
|
}
|
||||||
|
view.focus();
|
||||||
|
}, [tab]);
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
const view = viewRef.current;
|
||||||
|
if(!view) return;
|
||||||
|
|
||||||
|
const current = view.state.doc.toString();
|
||||||
|
if(value !== current) {
|
||||||
|
view.dispatch({
|
||||||
|
changes : { from: 0, to: current.length, insert: value },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [value]);
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
//rebuild theme extension on theme change
|
||||||
|
const view = viewRef.current;
|
||||||
|
if(!view) return;
|
||||||
|
|
||||||
|
const themeExtension = Array.isArray(themes[editorTheme])? themes[editorTheme]: themes[editorTheme] || themes['default'];
|
||||||
|
|
||||||
|
view.dispatch({
|
||||||
|
effects : themeCompartment.reconfigure(themeExtension),
|
||||||
|
});
|
||||||
|
|
||||||
|
const isDark = view.state.facet(EditorView.darkTheme);
|
||||||
|
onThemeChange(isDark);
|
||||||
|
}, [editorTheme, tab]);
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
//rebuild syntax highlight when changing tab or renderer
|
||||||
|
const view = viewRef.current;
|
||||||
|
if(!view) return;
|
||||||
|
|
||||||
|
const highlightExtension =renderer === 'V3'
|
||||||
|
? syntaxHighlighting(customHighlightStyle)
|
||||||
|
: syntaxHighlighting(legacyCustomHighlightStyle);
|
||||||
|
|
||||||
|
view.dispatch({
|
||||||
|
effects : highlightCompartment.reconfigure([customHighlightPlugin(renderer, tab, settings), highlightExtension])
|
||||||
|
});
|
||||||
|
}, [renderer, tab]);
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
const view = viewRef.current;
|
||||||
|
if(!view) return;
|
||||||
|
|
||||||
|
view.dispatch({
|
||||||
|
effects : settingsCompartment.reconfigure(
|
||||||
|
createSettingsExtensions(settings)
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}, [settings]);
|
||||||
|
|
||||||
|
useImperativeHandle(ref, ()=>({
|
||||||
|
|
||||||
|
injectText : (text)=>{
|
||||||
|
const view = viewRef.current;
|
||||||
|
|
||||||
|
view.dispatch(
|
||||||
|
view.state.replaceSelection(text)
|
||||||
|
);
|
||||||
|
view.focus();
|
||||||
|
},
|
||||||
|
getCursorPosition : ()=>viewRef.current.state.selection.main.head,
|
||||||
|
|
||||||
|
scrollToPage : (pageNumber, smooth = true)=>{
|
||||||
|
const view = viewRef.current;
|
||||||
|
if(!view) return;
|
||||||
|
|
||||||
|
const pos = pageMap.current[pageNumber - 1] ?? 0;
|
||||||
|
|
||||||
|
view.dispatch({
|
||||||
|
selection : { anchor: pos },
|
||||||
|
effects : [setProgrammaticCursorLine.of(pos), EditorView.scrollIntoView(pos, { y: 'start' })],
|
||||||
|
});
|
||||||
|
|
||||||
|
view.focus();
|
||||||
|
|
||||||
|
setTimeout(()=>{
|
||||||
|
view.dispatch({
|
||||||
|
effects : setProgrammaticCursorLine.of(null)
|
||||||
|
});
|
||||||
|
}, 400);
|
||||||
|
},
|
||||||
|
|
||||||
|
formatCode : ()=>formatCSS(viewRef.current),
|
||||||
|
|
||||||
|
undo : ()=>undo(viewRef.current),
|
||||||
|
redo : ()=>redo(viewRef.current),
|
||||||
|
|
||||||
|
historySize : ()=>{
|
||||||
|
const view = viewRef.current;
|
||||||
|
if(!view) return { done: 0, undone: 0 };
|
||||||
|
|
||||||
|
return {
|
||||||
|
done : undoDepth(view.state),
|
||||||
|
undone : redoDepth(view.state),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
foldAll : ()=>foldAll(),
|
||||||
|
unfoldAll : ()=>unfoldAll(),
|
||||||
|
|
||||||
|
focus : ()=>viewRef.current.focus(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
return <div className={`codeEditor ${tab}`} ref={editorRef} style={style} />;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export default CodeEditor;
|
||||||
@@ -1,60 +1,235 @@
|
|||||||
@import (less) 'codemirror/lib/codemirror.css';
|
// Icon fonts for emoji/autocomplete
|
||||||
@import (less) 'codemirror/addon/fold/foldgutter.css';
|
@import (less) '@themes/fonts/iconFonts/diceFont.less';
|
||||||
@import (less) 'codemirror/addon/search/matchesonscrollbar.css';
|
@import (less) '@themes/fonts/iconFonts/elderberryInn.less';
|
||||||
@import (less) 'codemirror/addon/dialog/dialog.css';
|
@import (less) '@themes/fonts/iconFonts/gameIcons.less';
|
||||||
@import (less) 'codemirror/addon/hint/show-hint.css';
|
@import (less) '@themes/fonts/iconFonts/fontAwesome.less';
|
||||||
|
|
||||||
//Icon fonts included so they can appear in emoji autosuggest dropdown
|
|
||||||
@import (less) './themes/fonts/iconFonts/diceFont.less';
|
|
||||||
@import (less) './themes/fonts/iconFonts/elderberryInn.less';
|
|
||||||
@import (less) './themes/fonts/iconFonts/gameIcons.less';
|
|
||||||
@import (less) './themes/fonts/iconFonts/fontAwesome.less';
|
|
||||||
|
|
||||||
@keyframes sourceMoveAnimation {
|
@keyframes sourceMoveAnimation {
|
||||||
50% { color : white;background-color : red;}
|
50% {
|
||||||
100% { color : unset;background-color : unset;}
|
color : white;
|
||||||
|
background-color : red;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
color : unset;
|
||||||
|
background-color : unset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.codeEditor {
|
@keyframes slideacross {
|
||||||
|
0% {
|
||||||
|
bottom : -200px;
|
||||||
|
left : -200px;
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
bottom : 100%;
|
||||||
|
left : 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:where(.codeEditor) {
|
||||||
|
width : 100%;
|
||||||
|
height : calc(100% - 25px);
|
||||||
|
font-family : monospace;
|
||||||
|
|
||||||
|
.cm-editor {
|
||||||
|
height : 100%;
|
||||||
|
outline : none !important;
|
||||||
|
|
||||||
|
&.cm-flash {
|
||||||
|
position : relative;
|
||||||
|
&::after {
|
||||||
|
position : absolute;
|
||||||
|
bottom : -200px;
|
||||||
|
left : -200px;
|
||||||
|
display : block;
|
||||||
|
width : 200%;
|
||||||
|
height : 100px;
|
||||||
|
content : '';
|
||||||
|
background : linear-gradient(0deg, #89EAFC00 0px, #89EBFC8E 50px, #89EAFC00 100px, transparent);
|
||||||
|
|
||||||
|
rotate : 30deg;
|
||||||
|
translate : -50%;
|
||||||
|
|
||||||
|
@media screen and (prefers-reduced-motion : no-preference) {
|
||||||
|
animation : 0.5s linear 1 slideacross;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.brewSnippets .cm-snippetLine,
|
||||||
|
:where(&.brewText) .cm-pageLine {
|
||||||
|
background : #33333328;
|
||||||
|
border-top : #333399 solid 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.brewSnippets {
|
||||||
|
.cm-pageLine {
|
||||||
|
color : #777777;
|
||||||
|
background : #3E4E3E1B;
|
||||||
|
border-top : #3399423B solid 1px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&:where(.brewText), &.brewSnippets {
|
||||||
|
|
||||||
|
|
||||||
|
.cm-pageLine[data-page-number]::after {
|
||||||
|
float : right;
|
||||||
|
color : grey;
|
||||||
|
content : attr(data-page-number);
|
||||||
|
}
|
||||||
|
.cm-columnSplit {
|
||||||
|
font-style : italic;
|
||||||
|
color : grey;
|
||||||
|
background-color : fade(#229999, 15%);
|
||||||
|
border-bottom : #229999 solid 1px;
|
||||||
|
}
|
||||||
|
.cm-define {
|
||||||
|
&:not(.term):not(.definition) {
|
||||||
|
font-weight : bold;
|
||||||
|
color : #949494;
|
||||||
|
background : #E5E5E5;
|
||||||
|
border-radius : 3px;
|
||||||
|
}
|
||||||
|
&.term { color : rgb(96, 117, 143); }
|
||||||
|
&.definition { color : rgb(97, 57, 178); }
|
||||||
|
}
|
||||||
|
.cm-block:not(.cm-comment),
|
||||||
|
.cm-block:not(.cm-comment) * {
|
||||||
|
font-weight : bold;
|
||||||
|
color : purple;
|
||||||
|
}
|
||||||
|
.cm-inline-block,
|
||||||
|
.cm-define .cm-inline-block {
|
||||||
|
font-weight : bold;
|
||||||
|
color : red;
|
||||||
|
span:not(.cm-comment) { color : inherit; }
|
||||||
|
}
|
||||||
|
.cm-injection:not(.cm-comment) {
|
||||||
|
font-weight : bold;
|
||||||
|
color : green;
|
||||||
|
span { color : inherit; }
|
||||||
|
}
|
||||||
|
.cm-emoji:not(.cm-comment) {
|
||||||
|
padding-bottom : 1px;
|
||||||
|
margin-left : 2px;
|
||||||
|
font-weight : bold;
|
||||||
|
color : #360034;
|
||||||
|
outline : solid 2px #FF96FC;
|
||||||
|
outline-offset : -2px;
|
||||||
|
background : #FFC8FF;
|
||||||
|
border-radius : 6px;
|
||||||
|
}
|
||||||
|
.cm-superscript:not(.cm-comment) {
|
||||||
|
font-size : 0.9em;
|
||||||
|
font-weight : bold;
|
||||||
|
vertical-align : super;
|
||||||
|
color : goldenrod;
|
||||||
|
}
|
||||||
|
.cm-subscript:not(.cm-comment) {
|
||||||
|
font-size : 0.9em;
|
||||||
|
font-weight : bold;
|
||||||
|
vertical-align : sub;
|
||||||
|
color : rgb(123, 123, 15);
|
||||||
|
}
|
||||||
|
.cm-strikethrough { text-decoration : line-through; }
|
||||||
|
|
||||||
|
.cm-definitionList {
|
||||||
|
.cm-definitionTerm { color : rgb(96, 117, 143); }
|
||||||
|
.cm-definitionColon:not(:has(.cm-comment)) {
|
||||||
|
font-weight : bold;
|
||||||
|
color : #949494;
|
||||||
|
background : #E5E5E5;
|
||||||
|
border-radius : 3px;
|
||||||
|
}
|
||||||
|
.cm-definitionDesc { color : rgb(97, 57, 178); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.cm-tooltip-autocomplete {
|
||||||
|
|
||||||
|
li {
|
||||||
|
display : flex;
|
||||||
|
gap : 10px;
|
||||||
|
align-items : center;
|
||||||
|
justify-content : flex-start;
|
||||||
|
|
||||||
|
.cm-completionIcon { display : none; }
|
||||||
|
.cm-tooltip-autocomplete .cm-completionLabel { translate : 0 -2px; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.cm-content { tab-size : 2 !important; }
|
||||||
|
|
||||||
@media screen and (pointer : coarse) {
|
@media screen and (pointer : coarse) {
|
||||||
font-size : 16px;
|
font-size : 16px;
|
||||||
}
|
}
|
||||||
.CodeMirror-foldmarker {
|
|
||||||
|
.cm-gutterElement span {
|
||||||
font-family : inherit;
|
font-family : inherit;
|
||||||
font-weight : 600;
|
font-weight : 600;
|
||||||
color : grey;
|
color : grey;
|
||||||
text-shadow : none;
|
text-shadow : none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.CodeMirror-foldgutter {
|
.cm-foldGutter {
|
||||||
cursor : pointer;
|
cursor : pointer;
|
||||||
border-left : 1px solid #EEEEEE;
|
border-left : 1px solid #EEEEEE;
|
||||||
transition : background 0.1s;
|
transition : background 0.1s;
|
||||||
&:hover { background : #DDDDDD; }
|
&:hover { background : #DDDDDD; }
|
||||||
}
|
}
|
||||||
|
|
||||||
.sourceMoveFlash .CodeMirror-line {
|
/* Flash animation for source moves */
|
||||||
|
.cm-line.sourceMoveFlash {
|
||||||
animation-name : sourceMoveAnimation;
|
animation-name : sourceMoveAnimation;
|
||||||
animation-duration : 0.4s;
|
animation-duration : 0.4s;
|
||||||
}
|
}
|
||||||
|
|
||||||
.CodeMirror-search-field {
|
/* Search input */
|
||||||
width:25em !important;
|
.cm-searchField {
|
||||||
outline:1px inset #00000055 !important;
|
width : 25em !important;
|
||||||
|
outline : 1px inset #00000055 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.cm-image {
|
||||||
|
position : relative;
|
||||||
|
|
||||||
|
.cm-preview {
|
||||||
|
position : absolute;
|
||||||
|
bottom : 0;
|
||||||
|
left : 0;
|
||||||
|
z-index : 1000;
|
||||||
|
width : 200px;
|
||||||
|
height : 200px;
|
||||||
|
padding : 5px;
|
||||||
|
pointer-events : none;
|
||||||
|
object-fit : contain;
|
||||||
|
background-color : #FFFFFF;
|
||||||
|
border : 3px solid grey;
|
||||||
|
border-radius : 10px;
|
||||||
|
opacity : 0;
|
||||||
|
translate : 0 100%;
|
||||||
|
transition : 0.2s opacity 0.5s;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover .cm-preview { opacity : 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Tab character visualization (optional) */
|
||||||
//.cm-tab {
|
//.cm-tab {
|
||||||
// background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAMCAQAAACOs/baAAAARUlEQVR4nGJgIAG8JkXxUAcCtDWemcGR1lY4MvgzCEKY7jSBjgxBDAG09UEQzAe0AMwMHrSOAwEGRtpaMIwAAAAA//8DAG4ID9EKs6YqAAAAAElFTkSuQmCC) no-repeat right;
|
// background: url(...) no-repeat right;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//.cm-trailingspace {
|
/* Trailing space visualization (optional) */
|
||||||
// .cm-space {
|
//.cm-trailingSpace .cm-space {
|
||||||
// background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAQAgMAAABW5NbuAAAACVBMVEVHcEwAAAAAAAAWawmTAAAAA3RSTlMAPBJ6PMxpAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAFUlEQVQI12NgwACcCQysASAEZGAAACMuAX06aCQUAAAAAElFTkSuQmCC) no-repeat right;
|
// background: url(...) no-repeat right;
|
||||||
// }
|
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Emoji preview styling */
|
||||||
.emojiPreview {
|
.emojiPreview {
|
||||||
font-size : 1.5em;
|
font-size : 1.5em;
|
||||||
line-height : 1.2em;
|
line-height : 1.2em;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
import { autocompletion } from '@codemirror/autocomplete';
|
||||||
|
|
||||||
|
import diceFont from '@themes/fonts/iconFonts/diceFont.js';
|
||||||
|
import elderberryInn from '@themes/fonts/iconFonts/elderberryInn.js';
|
||||||
|
import fontAwesome from '@themes/fonts/iconFonts/fontAwesome.js';
|
||||||
|
import gameIcons from '@themes/fonts/iconFonts/gameIcons.js';
|
||||||
|
|
||||||
|
const emojis = {
|
||||||
|
...diceFont,
|
||||||
|
...elderberryInn,
|
||||||
|
...fontAwesome,
|
||||||
|
...gameIcons
|
||||||
|
};
|
||||||
|
|
||||||
|
const emojiCompletionList = (context)=>{
|
||||||
|
const word = context.matchBefore(/:[^\s:]+/);
|
||||||
|
if(!word) return null;
|
||||||
|
|
||||||
|
const line = context.state.doc.lineAt(context.pos);
|
||||||
|
const textToCursor = line.text.slice(0, context.pos - line.from);
|
||||||
|
|
||||||
|
if(textToCursor.includes('{')) {
|
||||||
|
const curlyToCursor = textToCursor.slice(textToCursor.indexOf('{'));
|
||||||
|
const curlySpanRegex = /{(?=((?:[:=](?:"[\w,\-()#%. ]*"|[\w\-()#%.]*)|[^"':={}\s]*)*))\1$/g;
|
||||||
|
if(curlySpanRegex.test(curlyToCursor)) return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentWord = word.text.slice(1); // remove ':'
|
||||||
|
|
||||||
|
const options = Object.keys(emojis)
|
||||||
|
.filter((e)=>e.toLowerCase().includes(currentWord.toLowerCase()))
|
||||||
|
.sort((a, b)=>{
|
||||||
|
const normalize = (str)=>str.replace(/\d+/g, (m)=>m.padStart(4, '0')).toLowerCase();
|
||||||
|
return normalize(a) < normalize(b) ? -1 : 1;
|
||||||
|
})
|
||||||
|
.map((e)=>({
|
||||||
|
label : e,
|
||||||
|
apply : `${e}:`,
|
||||||
|
type : 'text',
|
||||||
|
info : ()=>{
|
||||||
|
const div = document.createElement('div');
|
||||||
|
div.innerHTML = `<i class="emojiPreview ${emojis[e]}"></i> ${e}`;
|
||||||
|
return div;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
//Label is the text in the list, comes with an icon that just
|
||||||
|
//renders example text "abc", hid that with css because i didn't see other choice
|
||||||
|
//Apply is the text that is set when the choice is selected
|
||||||
|
//Info is the tooltip
|
||||||
|
|
||||||
|
return {
|
||||||
|
from : word.from + 1,
|
||||||
|
options,
|
||||||
|
filter : false,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const autocompleteEmoji = autocompletion({
|
||||||
|
override : [emojiCompletionList],
|
||||||
|
activateOnTyping : true,
|
||||||
|
addToOptions : [
|
||||||
|
{
|
||||||
|
render(completion) {
|
||||||
|
const e = completion.label;
|
||||||
|
|
||||||
|
const icon = document.createElement('i');
|
||||||
|
icon.className = `emojiPreview ${emojis[e]}`;
|
||||||
|
|
||||||
|
const fragment = document.createDocumentFragment();
|
||||||
|
fragment.appendChild(icon);
|
||||||
|
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import { foldService, codeFolding } from '@codemirror/language';
|
||||||
|
|
||||||
|
const foldOnPages = [
|
||||||
|
foldService.of((state, lineStart)=>{ //tells where to fold
|
||||||
|
const doc = state.doc;
|
||||||
|
const matcher = /^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m;
|
||||||
|
|
||||||
|
const startLine = doc.lineAt(lineStart);
|
||||||
|
const prevLineText = startLine.number > 1 ? doc.line(startLine.number - 1).text : '';
|
||||||
|
|
||||||
|
if(!matcher.test(prevLineText)) return null;
|
||||||
|
|
||||||
|
let endLine = startLine.number;
|
||||||
|
while (endLine < doc.lines && !matcher.test(doc.line(endLine + 1).text)) {
|
||||||
|
endLine++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(endLine === startLine.number) return null;
|
||||||
|
|
||||||
|
return { from: startLine.from, to: doc.line(endLine).to };
|
||||||
|
}),
|
||||||
|
codeFolding({
|
||||||
|
preparePlaceholder : (state, range)=>{
|
||||||
|
const doc = state.doc;
|
||||||
|
const start = doc.lineAt(range.from).number;
|
||||||
|
const end = doc.lineAt(range.to).number;
|
||||||
|
|
||||||
|
if(doc.line(start).text.trim()) return ` ↤ Lines ${start}-${end} ↦`;
|
||||||
|
|
||||||
|
const preview = Array.from({ length: end - start }, (_, i)=>doc.line(start + 1 + i).text.trim()
|
||||||
|
).find(Boolean) || `Lines ${start}-${end}`;
|
||||||
|
|
||||||
|
return ` ↤ ${preview.replace('{', '').slice(0, 50).trim()}${preview.length > 50 ? '...' : ''} ↦`;
|
||||||
|
},
|
||||||
|
placeholderDOM(view, onclick, prepared) {
|
||||||
|
const span = document.createElement('span');
|
||||||
|
span.className = 'cm-fold-placeholder';
|
||||||
|
span.textContent = prepared;
|
||||||
|
span.onclick = onclick;
|
||||||
|
span.style.color = '#989898';
|
||||||
|
return span;
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
|
||||||
|
export default foldOnPages;
|
||||||
@@ -0,0 +1,468 @@
|
|||||||
|
/* eslint max-lines: ["error", { "max": 500 }] */
|
||||||
|
import { HighlightStyle } from '@codemirror/language';
|
||||||
|
import { tags } from '@lezer/highlight';
|
||||||
|
import { legacyTokenizeCustomMarkdown } from './legacyCustomHighlight';
|
||||||
|
import {
|
||||||
|
Decoration,
|
||||||
|
ViewPlugin,
|
||||||
|
} from '@codemirror/view';
|
||||||
|
import {
|
||||||
|
syntaxTree,
|
||||||
|
ensureSyntaxTree
|
||||||
|
} from '@codemirror/language';
|
||||||
|
|
||||||
|
// Making the tokens
|
||||||
|
const customTags = {
|
||||||
|
pageLine : 'pageLine', // .cm-pageLine
|
||||||
|
snippetLine : 'snippetLine', // .cm-snippetLine
|
||||||
|
columnSplit : 'columnSplit', // .cm-columnSplit
|
||||||
|
block : 'block', // .cm-block
|
||||||
|
inlineBlock : 'inline-block', // .cm-inline-block
|
||||||
|
injection : 'injection', // .cm-injection
|
||||||
|
emoji : 'emoji', // .cm-emoji
|
||||||
|
superscript : 'superscript', // .cm-superscript
|
||||||
|
subscript : 'subscript', // .cm-subscript
|
||||||
|
definitionList : 'definitionList', // .cm-definitionList
|
||||||
|
definitionTerm : 'definitionTerm', // .cm-definitionTerm
|
||||||
|
definitionDesc : 'definitionDesc', // .cm-definitionDesc
|
||||||
|
definitionColon : 'definitionColon', // .cm-definitionColon
|
||||||
|
strikethrough : 'strikethrough', // .cm-strikethrough
|
||||||
|
|
||||||
|
//CSS
|
||||||
|
|
||||||
|
variable : 'variable',
|
||||||
|
};
|
||||||
|
|
||||||
|
function tokenizeCustomMarkdown(text) {
|
||||||
|
const tokens = [];
|
||||||
|
const lines = text.split('\n');
|
||||||
|
|
||||||
|
//tokens without a `from` or `to` are interpreted by the custom plugin as line tokens
|
||||||
|
|
||||||
|
lines.forEach((lineText, lineNumber)=>{
|
||||||
|
// --- Page / snippet lines ---
|
||||||
|
if(/^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m.test(lineText)) tokens.push({ line: lineNumber, type: customTags.pageLine });
|
||||||
|
if(/^\\snippet\ .*$/.test(lineText)) tokens.push({ line: lineNumber, type: customTags.snippetLine });
|
||||||
|
if(/^\\column(?:break)?$/.test(lineText)) tokens.push({ line: lineNumber, type: customTags.columnSplit });
|
||||||
|
|
||||||
|
// --- Emoji ---
|
||||||
|
if(/:.\w+?:/.test(lineText)) {
|
||||||
|
const emojiRegex = /(:\w+?:)/g;
|
||||||
|
let match;
|
||||||
|
while ((match = emojiRegex.exec(lineText)) !== null) {
|
||||||
|
tokens.push({
|
||||||
|
line : lineNumber,
|
||||||
|
type : customTags.emoji,
|
||||||
|
from : match.index,
|
||||||
|
to : match.index + match[0].length,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Superscript / Subscript ---
|
||||||
|
if(/\^/.test(lineText)) {
|
||||||
|
let startIndex = lineText.indexOf('^');
|
||||||
|
const superRegex = /\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^/gy;
|
||||||
|
const subRegex = /\^\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^\^/gy;
|
||||||
|
|
||||||
|
while (startIndex >= 0) {
|
||||||
|
superRegex.lastIndex = subRegex.lastIndex = startIndex;
|
||||||
|
|
||||||
|
let match = subRegex.exec(lineText);
|
||||||
|
let type = customTags.subscript;
|
||||||
|
|
||||||
|
if(!match) {
|
||||||
|
match = superRegex.exec(lineText);
|
||||||
|
type = customTags.superscript;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(match) {
|
||||||
|
tokens.push({
|
||||||
|
line : lineNumber,
|
||||||
|
type,
|
||||||
|
from : match.index,
|
||||||
|
to : match.index + match[0].length,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
startIndex = lineText.indexOf(
|
||||||
|
'^',
|
||||||
|
Math.max(startIndex + 1, superRegex.lastIndex || 0, subRegex.lastIndex || 0),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Strikethrough ---
|
||||||
|
if(/\~/.test(lineText)) {
|
||||||
|
const strikethroughRegex = /~(?!\s)(.+?)(?<!\s)~/g;
|
||||||
|
|
||||||
|
const match = strikethroughRegex.exec(lineText);
|
||||||
|
const type = customTags.strikethrough;
|
||||||
|
|
||||||
|
if(match) {
|
||||||
|
tokens.push({
|
||||||
|
line : lineNumber,
|
||||||
|
type,
|
||||||
|
from : match.index,
|
||||||
|
to : match.index + match[0].length,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- single line def list ---
|
||||||
|
const singleLineRegex = /^(?=.*[^:])(.+?)(\s*)(::)([^\n]*)$/dmy;
|
||||||
|
const match = singleLineRegex.exec(lineText);
|
||||||
|
|
||||||
|
if(match) {
|
||||||
|
const [full, term, spaces, colons, desc] = match;
|
||||||
|
|
||||||
|
let offset = 0;
|
||||||
|
|
||||||
|
tokens.push({
|
||||||
|
line : lineNumber,
|
||||||
|
type : customTags.definitionList,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Term
|
||||||
|
tokens.push({
|
||||||
|
line : lineNumber,
|
||||||
|
type : customTags.definitionTerm,
|
||||||
|
from : offset,
|
||||||
|
to : offset + term.length,
|
||||||
|
});
|
||||||
|
offset += term.length;
|
||||||
|
|
||||||
|
// Spaces before ::
|
||||||
|
if(spaces) {
|
||||||
|
offset += spaces.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
// :: colons
|
||||||
|
tokens.push({
|
||||||
|
line : lineNumber,
|
||||||
|
type : customTags.definitionColon,
|
||||||
|
from : offset,
|
||||||
|
to : offset + colons.length,
|
||||||
|
});
|
||||||
|
offset += colons.length;
|
||||||
|
|
||||||
|
// Definition
|
||||||
|
tokens.push({
|
||||||
|
line : lineNumber,
|
||||||
|
type : customTags.definitionDesc,
|
||||||
|
from : offset,
|
||||||
|
to : offset + desc.length,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- multiline def list ---
|
||||||
|
if(!/^::/.test(lines[lineNumber]) && lineNumber + 1 < lines.length && /^::/.test(lines[lineNumber + 1])) {
|
||||||
|
const startLine = lineNumber;
|
||||||
|
const defs = [];
|
||||||
|
|
||||||
|
// collect all following :: definitions
|
||||||
|
for (let i = lineNumber + 1; i < lines.length; i++) {
|
||||||
|
const nextLine = lines[i];
|
||||||
|
const onlyColonsMatch = /^:*$/.test(nextLine);
|
||||||
|
const defMatch = /^(::)(.+)$/.exec(nextLine);
|
||||||
|
if(!onlyColonsMatch && defMatch) {
|
||||||
|
defs.push({ colons: defMatch[1], desc: defMatch[2], line: i });
|
||||||
|
} else break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(defs.length > 0 && lineText.trim().length > 0) {
|
||||||
|
tokens.push({
|
||||||
|
line : startLine,
|
||||||
|
type : customTags.definitionList,
|
||||||
|
});
|
||||||
|
|
||||||
|
// term
|
||||||
|
tokens.push({
|
||||||
|
line : startLine,
|
||||||
|
type : customTags.definitionTerm,
|
||||||
|
from : 0,
|
||||||
|
to : lineText.length,
|
||||||
|
});
|
||||||
|
|
||||||
|
// definitions
|
||||||
|
defs.forEach((d)=>{
|
||||||
|
tokens.push({
|
||||||
|
line : d.line,
|
||||||
|
type : customTags.definitionList,
|
||||||
|
});
|
||||||
|
|
||||||
|
tokens.push({
|
||||||
|
line : d.line,
|
||||||
|
type : customTags.definitionColon,
|
||||||
|
from : 0,
|
||||||
|
to : d.colons.length,
|
||||||
|
});
|
||||||
|
tokens.push({
|
||||||
|
line : d.line,
|
||||||
|
type : customTags.definitionDesc,
|
||||||
|
from : d.colons.length,
|
||||||
|
to : d.colons.length + d.desc?.length,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(lineText.includes('{') && lineText.includes('}')) {
|
||||||
|
const injectionRegex = /(?:^|[^{\n])({(?=((?:[:=](?:"[\w,\-()#%. ]*"|[\w\-()#%.]*)|[^"':={}\s]*)*))\2})/gmd;
|
||||||
|
let match;
|
||||||
|
|
||||||
|
while ((match = injectionRegex.exec(lineText)) !== null) {
|
||||||
|
tokens.push({
|
||||||
|
line : lineNumber,
|
||||||
|
from : match.indices[1][0],
|
||||||
|
to : match.indices[1][1],
|
||||||
|
type : customTags.injection,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(lineText.includes('{{') && lineText.includes('}}')) {
|
||||||
|
// Inline blocks: single-line {{…}}
|
||||||
|
const spanRegex = /{{(?=((?:[:=](?:"[\w,\-()#%. ]*"|[\w\-()#%.]*)|[^"':={}\s]*)*))\1 *|}}/g;
|
||||||
|
let match;
|
||||||
|
let blockCount = 0;
|
||||||
|
while ((match = spanRegex.exec(lineText)) !== null) {
|
||||||
|
if(match[0].startsWith('{{')) {
|
||||||
|
blockCount += 1;
|
||||||
|
} else {
|
||||||
|
blockCount -= 1;
|
||||||
|
}
|
||||||
|
if(blockCount < 0) {
|
||||||
|
blockCount = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
tokens.push({
|
||||||
|
line : lineNumber,
|
||||||
|
from : match.index,
|
||||||
|
to : match.index + match[0].length,
|
||||||
|
type : customTags.inlineBlock,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if(lineText.trimLeft().startsWith('{{') || lineText.trimLeft().startsWith('}}')) {
|
||||||
|
// Highlight block divs {{\n Content \n}}
|
||||||
|
let endCh = lineText.length + 1;
|
||||||
|
|
||||||
|
const match = lineText.match(
|
||||||
|
/^ *{{(?=((?:[:=](?:"[\w,\-()#%. ]*"|[\w\-()#%.]*)|[^"':={}\s]*)*))\1 *$|^ *}}$/,
|
||||||
|
);
|
||||||
|
if(match) endCh = match.index + match[0].length;
|
||||||
|
const closingMatch = lineText.match(/ *(}})/d);
|
||||||
|
|
||||||
|
if(closingMatch) {
|
||||||
|
tokens.push({ line: lineNumber, from: closingMatch.indices[1][0], to: closingMatch.indices[1][1], type: customTags.block });
|
||||||
|
} else {
|
||||||
|
tokens.push({ line: lineNumber, type: customTags.block });
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
function tokenizeCustomCSS(text) {
|
||||||
|
const tokens = [];
|
||||||
|
const lines = text.split('\n');
|
||||||
|
|
||||||
|
lines.forEach((lineText, lineNumber)=>{
|
||||||
|
|
||||||
|
if(/--[a-zA-Z0-9-_]+/gm.test(lineText)) {
|
||||||
|
const varRegex =/--[a-zA-Z0-9-_]+/gm;
|
||||||
|
let match;
|
||||||
|
while ((match = varRegex.exec(lineText)) !== null) {
|
||||||
|
tokens.push({
|
||||||
|
line : lineNumber,
|
||||||
|
from : match.index +1,
|
||||||
|
to : match.index + match.length[1] +1,
|
||||||
|
type : customTags.varProperty,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
//assign classes to tags provided by lezer, not unlike the function above
|
||||||
|
export const customHighlightStyle = HighlightStyle.define([
|
||||||
|
{ tag: tags.heading, class: 'cm-header' },
|
||||||
|
{ tag: tags.heading1, class: 'cm-header cm-header-1' },
|
||||||
|
{ tag: tags.heading2, class: 'cm-header cm-header-2' },
|
||||||
|
{ tag: tags.heading3, class: 'cm-header cm-header-3' },
|
||||||
|
{ tag: tags.heading4, class: 'cm-header cm-header-4' },
|
||||||
|
{ tag: tags.heading5, class: 'cm-header cm-header-5' },
|
||||||
|
{ tag: tags.heading6, class: 'cm-header cm-header-6' },
|
||||||
|
{ tag: tags.link, class: 'cm-link' },
|
||||||
|
{ tag: tags.string, class: 'cm-string' },
|
||||||
|
{ tag: tags.url, class: 'cm-string cm-url' },
|
||||||
|
{ tag: tags.list, class: 'cm-list' },
|
||||||
|
{ tag: tags.strong, class: 'cm-strong' },
|
||||||
|
{ tag: tags.emphasis, class: 'cm-em' },
|
||||||
|
{ tag: tags.quote, class: 'cm-quote' },
|
||||||
|
{ tag: tags.comment, class: 'cm-comment' },
|
||||||
|
{ tag: tags.monospace, class: 'cm-comment' },
|
||||||
|
|
||||||
|
//css tags
|
||||||
|
|
||||||
|
{ tag: tags.tagName, class: 'cm-tag' },
|
||||||
|
{ tag: tags.className, class: 'cm-class' },
|
||||||
|
{ tag: tags.propertyName, class: 'cm-property' },
|
||||||
|
{ tag: tags.attributeValue, class: 'cm-value' },
|
||||||
|
{ tag: tags.keyword, class: 'cm-keyword' },
|
||||||
|
{ tag: tags.atom, class: 'cm-atom' },
|
||||||
|
{ tag: tags.integer, class: 'cm-integer' },
|
||||||
|
{ tag: tags.unit, class: 'cm-unit' },
|
||||||
|
{ tag: tags.color, class: 'cm-color' },
|
||||||
|
{ tag: tags.paren, class: 'cm-paren' },
|
||||||
|
{ tag: tags.variableName, class: 'cm-variable' },
|
||||||
|
{ tag: tags.invalid, class: 'cm-error' },
|
||||||
|
|
||||||
|
]);
|
||||||
|
|
||||||
|
function getUrl(node, doc) {
|
||||||
|
let url = null;
|
||||||
|
|
||||||
|
const cursor = node.node.cursor();
|
||||||
|
|
||||||
|
if(cursor.firstChild()) {
|
||||||
|
do {
|
||||||
|
if(cursor.name === 'URL') {
|
||||||
|
url = doc.sliceString(cursor.from, cursor.to);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (cursor.nextSibling());
|
||||||
|
}
|
||||||
|
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
import { WidgetType } from '@codemirror/view';
|
||||||
|
|
||||||
|
class ImageWidget extends WidgetType {
|
||||||
|
constructor(url) {
|
||||||
|
super();
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
toDOM() {
|
||||||
|
const img = document.createElement('img');
|
||||||
|
img.loading = 'lazy';
|
||||||
|
img.className = 'cm-preview';
|
||||||
|
img.src = this.url;
|
||||||
|
|
||||||
|
if (img.onerror) return document.createElement('span');
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
|
||||||
|
eq(other) {
|
||||||
|
return other.url === this.url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function customHighlightPlugin(renderer, tab, settings) {
|
||||||
|
//this function takes the custom tokens created in the tokenize function in customhighlight files
|
||||||
|
//takes the tokens defined by that function and assigns classes to them
|
||||||
|
//it also creates page number and snippet number widgets
|
||||||
|
|
||||||
|
let tokenize;
|
||||||
|
|
||||||
|
if(tab === 'brewStyles') {
|
||||||
|
tokenize = tokenizeCustomCSS;
|
||||||
|
} else {
|
||||||
|
tokenize = renderer === 'V3' ? tokenizeCustomMarkdown : legacyTokenizeCustomMarkdown;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ViewPlugin.fromClass(
|
||||||
|
class {
|
||||||
|
constructor(view) {
|
||||||
|
this.decorations = this.buildDecorations(view);
|
||||||
|
}
|
||||||
|
update(update) {
|
||||||
|
if(update.docChanged) {
|
||||||
|
this.decorations = this.buildDecorations(update.view);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buildDecorations(view) {
|
||||||
|
const decos = [];
|
||||||
|
const tokens = tokenize(view.state.doc.toString());
|
||||||
|
let pageCount = 1;
|
||||||
|
let snippetCount = 0;
|
||||||
|
|
||||||
|
const tree = ensureSyntaxTree(view.state, view.state.doc.length, 50) || syntaxTree(view.state);
|
||||||
|
tree.iterate({
|
||||||
|
enter : (node)=>{
|
||||||
|
if(node.name === 'Image' && settings.showImagePreviews) {
|
||||||
|
const url = getUrl(node, view.state.doc);
|
||||||
|
|
||||||
|
const widgetPosition = node.node.lastChild.from;
|
||||||
|
//this is not exactly standard, but should hold,
|
||||||
|
//and is the shortest way i could find of positioning
|
||||||
|
//the image inside the cm-image node
|
||||||
|
|
||||||
|
if(!url) return;
|
||||||
|
|
||||||
|
decos.push(
|
||||||
|
Decoration.mark({
|
||||||
|
class : 'cm-image'
|
||||||
|
}).range(node.from, node.to)
|
||||||
|
);
|
||||||
|
decos.push(
|
||||||
|
Decoration.widget({
|
||||||
|
widget : new ImageWidget(url),
|
||||||
|
side : 1
|
||||||
|
}).range(widgetPosition)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tokens.forEach((token)=>{
|
||||||
|
const line = view.state.doc.line(token.line + 1);
|
||||||
|
|
||||||
|
if(token.from != null && token.to != null && token.from < token.to) {
|
||||||
|
const from = line.from + token.from;
|
||||||
|
const to = line.from + token.to;
|
||||||
|
|
||||||
|
const attrs = {};
|
||||||
|
if(token.type === 'Image' && token.url && settings.showImagePreviews) {
|
||||||
|
|
||||||
|
attrs['data-url'] = token.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
decos.push(
|
||||||
|
Decoration.mark({
|
||||||
|
class : `cm-${token.type}`,
|
||||||
|
...(Object.keys(attrs).length
|
||||||
|
? { attributes: attrs }
|
||||||
|
: {})
|
||||||
|
}).range(from, to)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
decos.push(
|
||||||
|
Decoration.line({
|
||||||
|
class : `cm-${token.type}`
|
||||||
|
}).range(line.from)
|
||||||
|
);
|
||||||
|
if(token.type === 'pageLine' && tab === 'brewText') {
|
||||||
|
pageCount++;
|
||||||
|
if(line.from === 0) pageCount--;
|
||||||
|
decos.push(Decoration.line({ attributes: { 'data-page-number': pageCount } }).range(line.from));
|
||||||
|
}
|
||||||
|
if(token.type === 'snippetLine' && tab === 'brewSnippets') {
|
||||||
|
snippetCount++;
|
||||||
|
decos.push(Decoration.line({ attributes: { 'data-page-number': snippetCount } }).range(line.from));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
decos.sort((a, b)=>a.from - b.from || a.to - b.to);
|
||||||
|
return Decoration.set(decos);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ decorations: (v)=>v.decorations }
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,257 @@
|
|||||||
|
/* eslint max-lines: ["error", { "max": 300 }] */
|
||||||
|
import { keymap } from '@codemirror/view';
|
||||||
|
import { undo, redo, indentMore, indentLess, deleteLine } from '@codemirror/commands';
|
||||||
|
import { EditorSelection, ChangeSet } from '@codemirror/state';
|
||||||
|
import { Prec } from '@codemirror/state';
|
||||||
|
import * as prettier from 'prettier/standalone';
|
||||||
|
import * as postcssPlugin from 'prettier/plugins/postcss';
|
||||||
|
|
||||||
|
export async function formatCSS(view) {
|
||||||
|
try {
|
||||||
|
const { from, to, empty } = view.state.selection.main;
|
||||||
|
const fullDoc = view.state.doc.toString();
|
||||||
|
const selection = view.state.doc.sliceString(from, to);
|
||||||
|
const code = empty ? fullDoc : selection;
|
||||||
|
|
||||||
|
let formatted = await prettier.format(code, {
|
||||||
|
parser : 'css',
|
||||||
|
plugins : [postcssPlugin],
|
||||||
|
|
||||||
|
// formatting options
|
||||||
|
tabWidth : 2,
|
||||||
|
useTabs : false,
|
||||||
|
printWidth : 100,
|
||||||
|
singleQuote : false,
|
||||||
|
trailingComma : 'all',
|
||||||
|
bracketSpacing : true,
|
||||||
|
endOfLine : 'lf'
|
||||||
|
});
|
||||||
|
|
||||||
|
//format manually single declaration rules to span one line.
|
||||||
|
//Prettier can't do it by default, this is crude but it works
|
||||||
|
formatted = formatted.replace(
|
||||||
|
/([^{]+)\{\s*\n\s*([^;\n]+:[^;\n]+;)\s*\n\s*\}(\s*)/g,
|
||||||
|
(_, selector, decl, whitespace)=>`${selector} { ${decl.trim()} }${whitespace}`
|
||||||
|
);
|
||||||
|
if(formatted === code) return true;
|
||||||
|
|
||||||
|
view.dom.classList.add('cm-flash');
|
||||||
|
setTimeout(()=>{
|
||||||
|
view.dom.classList.remove('cm-flash');
|
||||||
|
|
||||||
|
view.dispatch({
|
||||||
|
changes : {
|
||||||
|
from : empty ? 0 : from,
|
||||||
|
to : empty ? view.state.doc.length : to,
|
||||||
|
insert : formatted
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}, 500);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error formatting css: ', err);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const forEachSelection = (view, fn)=>{
|
||||||
|
view.dispatch(view.state.changeByRange((range)=>fn(view.state, range.from, range.to, view.state.doc.sliceString(range.from, range.to))));
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const insertTab = (view)=>{
|
||||||
|
// If any selection spans multiple lines, delegates to CodeMirror's indentMore
|
||||||
|
// Otherwise inserts two spaces at each cursor/selection
|
||||||
|
const shouldIndent = view.state.selection.ranges.some((range)=>view.state.doc.lineAt(range.from).number !==
|
||||||
|
view.state.doc.lineAt(range.to).number
|
||||||
|
);
|
||||||
|
if(shouldIndent) return indentMore(view);
|
||||||
|
|
||||||
|
return forEachSelection(view, (state, from, to, selected)=>{
|
||||||
|
return {
|
||||||
|
changes : { from, to, insert: ' ' }, // Insert two spaces, not a tab char!
|
||||||
|
range : EditorSelection.cursor(from + 2)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const wrapSelection = (prefix, suffix)=>(view)=>forEachSelection(view, (state, from, to, selected)=>{
|
||||||
|
const noSelection = from === to;
|
||||||
|
if(noSelection) {
|
||||||
|
const insert = prefix + suffix;
|
||||||
|
|
||||||
|
return {
|
||||||
|
changes : { from, to, insert },
|
||||||
|
range : EditorSelection.cursor(from + prefix.length)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasWrapper = selected.startsWith(prefix) && selected.endsWith(suffix);
|
||||||
|
if(hasWrapper) {
|
||||||
|
return {
|
||||||
|
changes : [
|
||||||
|
{ from: to - suffix.length, to, insert: '' },
|
||||||
|
{ from, to: from + prefix.length, insert: '' }
|
||||||
|
],
|
||||||
|
range : EditorSelection.range(from, to - prefix.length - suffix.length)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
changes : { from, to, insert: prefix + selected + suffix },
|
||||||
|
range : EditorSelection.range(from, to + prefix.length + suffix.length)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const makeNbsp = (view)=>forEachSelection(view, (state, from, to, selected)=>{
|
||||||
|
const prev2 = from >= 2 ? state.doc.sliceString(from - 2, from) : '';
|
||||||
|
const insert = (prev2 === ':>' || prev2 === '>>') ? '>' : ':>';
|
||||||
|
|
||||||
|
return {
|
||||||
|
changes : { from, to, insert },
|
||||||
|
range : EditorSelection.cursor(from + insert.length)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const makeSpace = (view)=>forEachSelection(view, (state, from, to, selected)=>{
|
||||||
|
let insert = '{{width:10% }}';
|
||||||
|
const match = selected.match(/^{{width:(\d+)% }}$/);
|
||||||
|
if(match) {
|
||||||
|
const percent = Math.min(parseInt(match[1], 10) + 10, 100);
|
||||||
|
insert = `{{width:${percent}% }}`;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
changes : { from, to, insert },
|
||||||
|
range : EditorSelection.range(from, from + insert.length)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const removeSpace = (view)=>forEachSelection(view, (state, from, to, selected)=>{
|
||||||
|
const match = selected.match(/^{{width:(\d+)% }}$/);
|
||||||
|
if(match) {
|
||||||
|
const percent = parseInt(match[1], 10) - 10;
|
||||||
|
const insert = percent > 0 ? `{{width:${percent}% }}` : '';
|
||||||
|
return { changes: { from, to, insert: insert }, range: EditorSelection.range(from, from + insert.length) };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const makeLink = (view)=>forEachSelection(view, (state, from, to, selected)=>{
|
||||||
|
// If the selection is already a Markdown link, unwrap it
|
||||||
|
const existingLink = /^\[(.*)\]\((.*)\)$/.exec(selected);
|
||||||
|
if(existingLink) {
|
||||||
|
const [, text, url] = existingLink;
|
||||||
|
const insert = `${text} ${url}`;
|
||||||
|
return {
|
||||||
|
changes : { from, to, insert },
|
||||||
|
range : EditorSelection.range(
|
||||||
|
from,
|
||||||
|
from + insert.length
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the selection is a URL, use its domain as the link text.
|
||||||
|
const isUrl =
|
||||||
|
/^(https?:\/\/|www\.)\S+$/i.test(selected) ||
|
||||||
|
/^[a-z0-9-]+(\.[a-z0-9-]+)+([/?#]\S*)?$/i.test(selected);
|
||||||
|
if(isUrl) {
|
||||||
|
const domain = selected
|
||||||
|
.replace(/^https?:\/\//i, '')
|
||||||
|
.replace(/^www\./i, '')
|
||||||
|
.split(/[/?#]/)[0];
|
||||||
|
|
||||||
|
const name = domain.split('.')[0];
|
||||||
|
const insert = `[${name}](${selected})`;
|
||||||
|
return {
|
||||||
|
changes : { from, to, insert },
|
||||||
|
range : EditorSelection.range(from, from + insert.length),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the selection is just text, use it as alt text and set url as placeholder
|
||||||
|
const insert = `[${selected || 'alt text'}](url)`;
|
||||||
|
return {
|
||||||
|
changes : { from, to, insert },
|
||||||
|
range : EditorSelection.range(from, from + insert.length),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const addPrefixAtLineStart = (prefix)=>(view)=>forEachSelection(view, (state, from, to, selected)=>{
|
||||||
|
const startLine = state.doc.lineAt(from);
|
||||||
|
const endLine = state.doc.lineAt(to);
|
||||||
|
const selectedLines = [];
|
||||||
|
|
||||||
|
for (let lineNumber = startLine.number; lineNumber <= endLine.number; lineNumber++) { selectedLines.push(state.doc.line(lineNumber)); }
|
||||||
|
|
||||||
|
const allLinesHavePrefix = selectedLines.every((line)=>line.text.startsWith(prefix));
|
||||||
|
|
||||||
|
const changes = selectedLines.map((line)=>{
|
||||||
|
const shouldRemovePrefix = allLinesHavePrefix && line.text.startsWith(prefix);
|
||||||
|
|
||||||
|
return {
|
||||||
|
from : line.from,
|
||||||
|
to : shouldRemovePrefix
|
||||||
|
? line.from + prefix.length
|
||||||
|
: line.from,
|
||||||
|
insert : shouldRemovePrefix ? '' : prefix,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
const changeSet = ChangeSet.of(changes, state.doc.length);
|
||||||
|
|
||||||
|
return {
|
||||||
|
changes,
|
||||||
|
range : EditorSelection.range(
|
||||||
|
changeSet.mapPos(from, -1),
|
||||||
|
changeSet.mapPos(to, 1)
|
||||||
|
),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const newBreak = (type)=>(view)=>forEachSelection(view, (state, from, to, selected)=>{
|
||||||
|
const insert = `\n\\${type}\n\n`;
|
||||||
|
return {
|
||||||
|
changes : { from, to, insert },
|
||||||
|
range : EditorSelection.cursor(from + insert.length)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
export const generalKeymap = (foldAll, unfoldAll) => Prec.high(keymap.of([
|
||||||
|
{ key: 'Tab', run: insertTab },
|
||||||
|
{ key: 'Shift-Tab', run: indentLess },
|
||||||
|
{ key: 'Mod-z', run: undo }, //it may be unnecessary
|
||||||
|
{ key: 'Mod-Shift-z', run: redo },
|
||||||
|
{ key: 'Mod-y', run: redo }, //user asked, so double keybind
|
||||||
|
{ key: 'Mod-d', run: deleteLine }, //annoyingly overrides "selectNextOccurrence" because users asked
|
||||||
|
{ key: 'Mod-Shift-[', run: foldAll },
|
||||||
|
{ key: 'Mod-Shift-]', run: unfoldAll },
|
||||||
|
]));
|
||||||
|
|
||||||
|
export const cssKeymap = Prec.highest(keymap.of([
|
||||||
|
{ key: 'Mod-Shift-f', run: formatCSS },
|
||||||
|
{ key: 'Alt-Shift-f', run: formatCSS },
|
||||||
|
]));
|
||||||
|
|
||||||
|
export const markdownKeymap = Prec.highest(keymap.of([
|
||||||
|
{ key: 'Mod-b', run: wrapSelection('**', '**') }, // makeBold
|
||||||
|
{ key: 'Mod-i', run: wrapSelection('*', '*') }, // makeItalic
|
||||||
|
{ key: 'Mod-u', run: wrapSelection('<u>', '</u>') }, // makeUnderline
|
||||||
|
{ key: 'Shift-Mod-=', run: wrapSelection('^', '^') }, // makeSuper
|
||||||
|
{ key: 'Mod-=', run: wrapSelection('^^', '^^') }, // makeSub
|
||||||
|
{ key: 'Mod-.', run: makeNbsp },
|
||||||
|
{ key: 'Shift-Mod-.', run: makeSpace },
|
||||||
|
{ key: 'Shift-Mod-,', run: removeSpace },
|
||||||
|
{ key: 'Mod-m', run: wrapSelection('{{', '}}') },
|
||||||
|
{ key: 'Shift-Mod-m', run: wrapSelection('{{\n', '\n}}') },
|
||||||
|
{ key: 'Mod-/', run: wrapSelection('<!-- ', ' -->') },
|
||||||
|
{ key: 'Mod-Shift-k', run: makeLink },
|
||||||
|
{ key: 'Mod-Shift-u', run: addPrefixAtLineStart('- ') },
|
||||||
|
{ key: 'Mod-Shift-o', run: addPrefixAtLineStart('1. ') },
|
||||||
|
{ key: 'Shift-Mod-1', run: addPrefixAtLineStart('# ') },
|
||||||
|
{ key: 'Shift-Mod-2', run: addPrefixAtLineStart('## ') },
|
||||||
|
{ key: 'Shift-Mod-3', run: addPrefixAtLineStart('### ') },
|
||||||
|
{ key: 'Shift-Mod-4', run: addPrefixAtLineStart('#### ') },
|
||||||
|
{ key: 'Shift-Mod-5', run: addPrefixAtLineStart('##### ') },
|
||||||
|
{ key: 'Shift-Mod-6', run: addPrefixAtLineStart('###### ') },
|
||||||
|
{ key: 'Mod-Enter', run: newBreak('page') },
|
||||||
|
{ key: 'Shift-Mod-Enter', run: newBreak('column') },
|
||||||
|
]));
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import { HighlightStyle } from '@codemirror/language';
|
||||||
|
import { tags } from '@lezer/highlight';
|
||||||
|
|
||||||
|
const customTags = {
|
||||||
|
pageLine : 'pageLine', // .cm-pageLine
|
||||||
|
snippetLine : 'snippetLine', // .cm-snippetLine
|
||||||
|
};
|
||||||
|
|
||||||
|
export function legacyTokenizeCustomMarkdown(text) {
|
||||||
|
const tokens = [];
|
||||||
|
const lines = text.split('\n');
|
||||||
|
|
||||||
|
lines.forEach((lineText, lineNumber)=>{
|
||||||
|
// --- Page / snippet lines ---
|
||||||
|
if(/^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m.test(lineText)) tokens.push({ line: lineNumber, type: customTags.pageLine });
|
||||||
|
if(/^\\snippet\ .*$/.test(lineText)) tokens.push({ line: lineNumber, type: customTags.snippetLine });
|
||||||
|
});
|
||||||
|
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const legacyCustomHighlightStyle = HighlightStyle.define([
|
||||||
|
{ tag: tags.heading, class: 'cm-header' },
|
||||||
|
{ tag: tags.heading1, class: 'cm-header cm-header-1' },
|
||||||
|
{ tag: tags.heading2, class: 'cm-header cm-header-2' },
|
||||||
|
{ tag: tags.heading3, class: 'cm-header cm-header-3' },
|
||||||
|
{ tag: tags.heading4, class: 'cm-header cm-header-4' },
|
||||||
|
{ tag: tags.heading5, class: 'cm-header cm-header-5' },
|
||||||
|
{ tag: tags.heading6, class: 'cm-header cm-header-6' },
|
||||||
|
{ tag: tags.link, class: 'cm-link' },
|
||||||
|
{ tag: tags.string, class: 'cm-string' },
|
||||||
|
{ tag: tags.url, class: 'cm-string cm-url' },
|
||||||
|
{ tag: tags.list, class: 'cm-list' },
|
||||||
|
{ tag: tags.strong, class: 'cm-strong' },
|
||||||
|
{ tag: tags.emphasis, class: 'cm-em' },
|
||||||
|
{ tag: tags.quote, class: 'cm-quote' },
|
||||||
|
|
||||||
|
//css tags
|
||||||
|
|
||||||
|
{ tag: tags.tagName, class: 'cm-tag' },
|
||||||
|
{ tag: tags.className, class: 'cm-class' },
|
||||||
|
{ tag: tags.propertyName, class: 'cm-property' },
|
||||||
|
{ tag: tags.attributeValue, class: 'cm-value' },
|
||||||
|
{ tag: tags.keyword, class: 'cm-keyword' },
|
||||||
|
{ tag: tags.atom, class: 'cm-atom' },
|
||||||
|
{ tag: tags.integer, class: 'cm-integer' },
|
||||||
|
{ tag: tags.unit, class: 'cm-unit' },
|
||||||
|
{ tag: tags.color, class: 'cm-color' },
|
||||||
|
{ tag: tags.paren, class: 'cm-paren' },
|
||||||
|
{ tag: tags.variableName, class: 'cm-variable' },
|
||||||
|
{ tag: tags.invalid, class: 'cm-error' },
|
||||||
|
{ tag: tags.comment, class: 'cm-comment' },
|
||||||
|
]);
|
||||||
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
registerHomebreweryHelper : function(CodeMirror) {
|
|
||||||
CodeMirror.registerHelper('fold', 'homebrewerycss', function(cm, start) {
|
|
||||||
|
|
||||||
// BRACE FOLDING
|
|
||||||
const startMatcher = /\{[ \t]*$/;
|
|
||||||
const endMatcher = /\}[ \t]*$/;
|
|
||||||
const activeLine = cm.getLine(start.line);
|
|
||||||
|
|
||||||
|
|
||||||
if(activeLine.match(startMatcher)) {
|
|
||||||
const lastLineNo = cm.lastLine();
|
|
||||||
let end = start.line + 1;
|
|
||||||
let braceCount = 1;
|
|
||||||
|
|
||||||
while (end < lastLineNo) {
|
|
||||||
const curLine = cm.getLine(end);
|
|
||||||
if(curLine.match(startMatcher)) braceCount++;
|
|
||||||
if(curLine.match(endMatcher)) braceCount--;
|
|
||||||
if(braceCount == 0) break;
|
|
||||||
++end;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
from : CodeMirror.Pos(start.line, 0),
|
|
||||||
to : CodeMirror.Pos(end, cm.getLine(end).length)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// @import and data-url folding
|
|
||||||
const importMatcher = /^@import.*?;/;
|
|
||||||
const dataURLMatcher = /url\(.*?data\:.*\)/;
|
|
||||||
|
|
||||||
if(activeLine.match(importMatcher) || activeLine.match(dataURLMatcher)) {
|
|
||||||
return {
|
|
||||||
from : CodeMirror.Pos(start.line, 0),
|
|
||||||
to : CodeMirror.Pos(start.line, activeLine.length)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
registerHomebreweryHelper : function(CodeMirror) {
|
|
||||||
CodeMirror.registerHelper('fold', 'homebrewery', function(cm, start) {
|
|
||||||
const matcher = /^\\page.*/;
|
|
||||||
const prevLine = cm.getLine(start.line - 1);
|
|
||||||
|
|
||||||
if(start.line === cm.firstLine() || prevLine.match(matcher)) {
|
|
||||||
const lastLineNo = cm.lastLine();
|
|
||||||
let end = start.line;
|
|
||||||
|
|
||||||
while (end < lastLineNo) {
|
|
||||||
if(cm.getLine(end + 1).match(matcher))
|
|
||||||
break;
|
|
||||||
++end;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
from : CodeMirror.Pos(start.line, 0),
|
|
||||||
to : CodeMirror.Pos(end, cm.getLine(end).length)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
+103
-99
@@ -1,129 +1,133 @@
|
|||||||
const React = require('react');
|
import React, { useState, useEffect, useRef, useCallback } from 'react';
|
||||||
const createClass = require('create-react-class');
|
import _ from 'lodash';
|
||||||
const _ = require('lodash');
|
import './combobox.less';
|
||||||
require('./combobox.less');
|
|
||||||
|
|
||||||
const Combobox = createClass({
|
const Combobox = ({
|
||||||
displayName : 'Combobox',
|
id = '',
|
||||||
getDefaultProps : function() {
|
className = '',
|
||||||
return {
|
trigger = 'hover',
|
||||||
className : '',
|
defaultValue = '',
|
||||||
trigger : 'hover',
|
placeholder = '',
|
||||||
default : '',
|
tooltip = '',
|
||||||
placeholder : '',
|
autoSuggest = {
|
||||||
autoSuggest : {
|
clearAutoSuggestOnClick : true,
|
||||||
clearAutoSuggestOnClick : true,
|
suggestMethod : 'includes',
|
||||||
suggestMethod : 'includes',
|
filterOn : [] // should allow as array to filter on multiple attributes, or even custom filter
|
||||||
filterOn : [] // should allow as array to filter on multiple attributes, or even custom filter
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
getInitialState : function() {
|
valuePatterns = '.+',
|
||||||
return {
|
options = [],
|
||||||
showDropdown : false,
|
keepValueOnClose = false,
|
||||||
value : '',
|
...props
|
||||||
options : [...this.props.options],
|
})=>{
|
||||||
inputFocused : false
|
const dropdownRef = useRef(null);
|
||||||
};
|
const [showDropdown, setShowDropdown] = useState(false);
|
||||||
},
|
const [inputFocused, setInputFocused] = useState(false);
|
||||||
componentDidMount : function() {
|
const [value, setValue] = useState(defaultValue);
|
||||||
if(this.props.trigger == 'click')
|
|
||||||
document.addEventListener('click', this.handleClickOutside);
|
useEffect(()=>{
|
||||||
this.setState({
|
if(trigger === 'click') {
|
||||||
value : this.props.default
|
document.addEventListener('click', handleClickOutside);
|
||||||
});
|
return ()=>document.removeEventListener('click', handleClickOutside);
|
||||||
},
|
|
||||||
componentWillUnmount : function() {
|
|
||||||
if(this.props.trigger == 'click')
|
|
||||||
document.removeEventListener('click', this.handleClickOutside);
|
|
||||||
},
|
|
||||||
handleClickOutside : function(e){
|
|
||||||
// Close dropdown when clicked outside
|
|
||||||
if(this.refs.dropdown && !this.refs.dropdown.contains(e.target)) {
|
|
||||||
this.handleDropdown(false);
|
|
||||||
}
|
}
|
||||||
},
|
}, []);
|
||||||
handleDropdown : function(show){
|
|
||||||
this.setState({
|
const handleClickOutside = useCallback((e)=>{
|
||||||
value : show ? '' : this.props.default,
|
// Close dropdown when clicked outside
|
||||||
showDropdown : show,
|
if(!dropdownRef.current?.contains(e.target)) {
|
||||||
inputFocused : this.props.autoSuggest.clearAutoSuggestOnClick ? show : false
|
handleDropdown(false);
|
||||||
});
|
}
|
||||||
},
|
}, []);
|
||||||
handleInput : function(e){
|
|
||||||
e.persist();
|
const handleDropdown = (show)=>{
|
||||||
this.setState({
|
if(show) {
|
||||||
value : e.target.value,
|
if(autoSuggest.clearAutoSuggestOnClick) {
|
||||||
inputFocused : false
|
setValue('');
|
||||||
}, ()=>{
|
}
|
||||||
this.props.onEntry(e);
|
} else if(!keepValueOnClose) {
|
||||||
});
|
setValue(defaultValue);
|
||||||
},
|
}
|
||||||
handleSelect : function(value, data=value){
|
setShowDropdown(show);
|
||||||
this.setState({
|
setInputFocused(autoSuggest.clearAutoSuggestOnClick && show);
|
||||||
value : value
|
};
|
||||||
}, ()=>{this.props.onSelect(data);});
|
|
||||||
;
|
const handleInput = (e)=>{
|
||||||
},
|
setValue(e.target.value);
|
||||||
renderTextInput : function(){
|
setInputFocused(false);
|
||||||
|
props.onEntry(e);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSelect = (value, data=value)=>{
|
||||||
|
setValue(value);
|
||||||
|
props.onSelect(data);
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderTextInput = ()=>{
|
||||||
return (
|
return (
|
||||||
<div className='dropdown-input item'
|
<div className='dropdown-input item'
|
||||||
onMouseEnter={this.props.trigger == 'hover' ? ()=>{this.handleDropdown(true);} : undefined}
|
onMouseEnter={trigger == 'hover' ? ()=>{handleDropdown(true);} : undefined}
|
||||||
onClick= {this.props.trigger == 'click' ? ()=>{this.handleDropdown(true);} : undefined}>
|
onClick= {trigger == 'click' ? ()=>{handleDropdown(true);} : undefined}
|
||||||
|
{...(tooltip ? { 'data-tooltip-right': tooltip } : {})}>
|
||||||
<input
|
<input
|
||||||
|
id={id}
|
||||||
type='text'
|
type='text'
|
||||||
onChange={(e)=>this.handleInput(e)}
|
onChange={(e)=>handleInput(e)}
|
||||||
value={this.state.value || ''}
|
value={value || ''}
|
||||||
placeholder={this.props.placeholder}
|
title=''
|
||||||
|
pattern={valuePatterns}
|
||||||
|
placeholder={placeholder}
|
||||||
onBlur={(e)=>{
|
onBlur={(e)=>{
|
||||||
if(!e.target.checkValidity()){
|
if(!e.target.checkValidity()){
|
||||||
this.setState({
|
setValue(defaultValue);
|
||||||
value : this.props.default
|
}
|
||||||
});
|
}}
|
||||||
|
onKeyDown={(e)=>{
|
||||||
|
if(e.key === 'Enter') {
|
||||||
|
e.preventDefault();
|
||||||
|
props.onEntry(e);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<i className='fas fa-caret-down'/>
|
<i className='fas fa-caret-down'/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
};
|
||||||
renderDropdown : function(dropdownChildren){
|
|
||||||
if(!this.state.showDropdown) return null;
|
const renderDropdown = ()=>{
|
||||||
if(this.props.autoSuggest && !this.state.inputFocused){
|
if(!showDropdown) return null;
|
||||||
const suggestMethod = this.props.autoSuggest.suggestMethod;
|
let dropdownChildren = options.map((child, i)=>{
|
||||||
const filterOn = _.isString(this.props.autoSuggest.filterOn) ? [this.props.autoSuggest.filterOn] : this.props.autoSuggest.filterOn;
|
const clone = React.cloneElement(child, { onClick: ()=>handleSelect(child.props.value, child.props.data) });
|
||||||
|
return clone;
|
||||||
|
});
|
||||||
|
if(autoSuggest && !inputFocused){
|
||||||
|
const suggestMethod = autoSuggest.suggestMethod;
|
||||||
|
const filterOn = _.isString(autoSuggest.filterOn) ? [autoSuggest.filterOn] : autoSuggest.filterOn;
|
||||||
const filteredArrays = filterOn.map((attr)=>{
|
const filteredArrays = filterOn.map((attr)=>{
|
||||||
const children = dropdownChildren.filter((item)=>{
|
const children = dropdownChildren.filter((item)=>{
|
||||||
if(suggestMethod === 'includes')
|
if(suggestMethod === 'includes')
|
||||||
return item.props[attr]?.toLowerCase().includes(this.state.value.toLowerCase());
|
return item.props[attr]?.toLowerCase().includes(value.toLowerCase());
|
||||||
if(suggestMethod === 'startsWith')
|
if(suggestMethod === 'startsWith')
|
||||||
return item.props[attr]?.toLowerCase().startsWith(this.state.value.toLowerCase());
|
return item.props[attr]?.toLowerCase().startsWith(value.toLowerCase());
|
||||||
});
|
});
|
||||||
return children;
|
return children;
|
||||||
});
|
});
|
||||||
dropdownChildren = _.uniq(filteredArrays.flat(1));
|
dropdownChildren = _.uniq(filteredArrays.flat(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='dropdown-options'>
|
<div className='dropdown-options'>
|
||||||
{dropdownChildren}
|
{dropdownChildren}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
};
|
||||||
render : function () {
|
|
||||||
const dropdownChildren = this.state.options.map((child, i)=>{
|
|
||||||
const clone = React.cloneElement(child, { onClick: ()=>this.handleSelect(child.props.value, child.props.data) });
|
|
||||||
return clone;
|
|
||||||
});
|
|
||||||
return (
|
|
||||||
<div className={`dropdown-container ${this.props.className}`}
|
|
||||||
ref='dropdown'
|
|
||||||
onMouseLeave={this.props.trigger == 'hover' ? ()=>{this.handleDropdown(false);} : undefined}>
|
|
||||||
{this.renderTextInput()}
|
|
||||||
{this.renderDropdown(dropdownChildren)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = Combobox;
|
return (
|
||||||
|
<div className={`dropdown-container ${className}`}
|
||||||
|
ref={dropdownRef}
|
||||||
|
onMouseLeave={trigger == 'hover' ? ()=>{handleDropdown(false);} : undefined}>
|
||||||
|
{renderTextInput()}
|
||||||
|
{renderDropdown()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Combobox;
|
||||||
@@ -4,12 +4,13 @@
|
|||||||
.item i {
|
.item i {
|
||||||
position : absolute;
|
position : absolute;
|
||||||
right : 10px;
|
right : 10px;
|
||||||
color : black;
|
color : inherit;
|
||||||
}
|
}
|
||||||
.dropdown-options {
|
.dropdown-options {
|
||||||
position : absolute;
|
position : absolute;
|
||||||
z-index : 100;
|
z-index : 100;
|
||||||
width : 100%;
|
width : 100%;
|
||||||
|
height : max-content;
|
||||||
max-height : 200px;
|
max-height : 200px;
|
||||||
overflow-y : auto;
|
overflow-y : auto;
|
||||||
background-color : white;
|
background-color : white;
|
||||||
@@ -30,15 +31,12 @@
|
|||||||
font-family : 'Open Sans';
|
font-family : 'Open Sans';
|
||||||
font-size : 11px;
|
font-size : 11px;
|
||||||
cursor : default;
|
cursor : default;
|
||||||
&:hover {
|
&:hover { background-color : #DDDDDD; }
|
||||||
background-color : rgb(163, 163, 163);
|
|
||||||
filter : brightness(120%);
|
|
||||||
}
|
|
||||||
.detail {
|
.detail {
|
||||||
width : 100%;
|
width : 100%;
|
||||||
font-size : 9px;
|
font-size : 9px;
|
||||||
font-style : italic;
|
font-style : italic;
|
||||||
color : rgb(124, 124, 124);
|
color : #7C7C7C;
|
||||||
text-align : left;
|
text-align : left;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,140 @@
|
|||||||
|
/**
|
||||||
|
* A dropdown menu component that uses the Anchor Positioning API to position the elements. It supports nested submenus as well.
|
||||||
|
* Anchor Positioning is now supported in all major browsers. A polyfill is conditionally loaded for older browsers.
|
||||||
|
*
|
||||||
|
* As-is, the menus will always open down aligned on left to trigger, submenus open to the right initially.
|
||||||
|
* If no space, menus will still open down, but aligned to the right of the trigger. Submenus will flip to the other side of the top menu.
|
||||||
|
* This could be customized either in more specific CSS, or as a `direction` prop on the component (in future iterations).
|
||||||
|
*
|
||||||
|
* @param {string} props.groupName - Name of the menu. Appears as the trigger text.
|
||||||
|
* @param {string} [props.icon] - Icon to display in the trigger.
|
||||||
|
* @param {string} [props.color] - Color class to add to the trigger.
|
||||||
|
* @param {string} [props.className] - Additional classes for the menu wrapper.
|
||||||
|
* @param {React.ReactNode} [props.customTrigger] - Custom element to use as a trigger.
|
||||||
|
* @param {React.ReactNode} [props.children] - Child elements to render in the menu.
|
||||||
|
* @returns {React.JSX.Element}
|
||||||
|
*/
|
||||||
|
|
||||||
|
import './dropdown.less';
|
||||||
|
import React, { useEffect, useId, useRef } from 'react';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
// use react context to keep track of the menu depth (menus in menus)
|
||||||
|
const MenuDepthContext = React.createContext(0);
|
||||||
|
|
||||||
|
const Dropdown = ({ groupName, className = null, icon, children, color = null, customTrigger, disabled = false, ...props })=>{
|
||||||
|
const reactId = useId();
|
||||||
|
const safeId = reactId.replace(/[^a-zA-Z0-9_-]/g, '');
|
||||||
|
const menuId = `${_.kebabCase(groupName)}-${safeId}-menu`;
|
||||||
|
const anchorName = `--${menuId}`;
|
||||||
|
const depth = React.useContext(MenuDepthContext);
|
||||||
|
|
||||||
|
// A menu is a submenu if depth > 0
|
||||||
|
const isSubMenu = depth > 0;
|
||||||
|
|
||||||
|
const triggerRef = useRef(null);
|
||||||
|
const menuRef = useRef(null);
|
||||||
|
|
||||||
|
// use setAttribute instead of the React style prop because React strips unknown CSS
|
||||||
|
// properties (like anchor-name) from inline styles in browsers that don't support them.
|
||||||
|
// setAttribute writes raw CSS text that the anchor positioning polyfill can read
|
||||||
|
useEffect(()=>{
|
||||||
|
triggerRef.current?.setAttribute('style', `anchor-name: ${anchorName}`);
|
||||||
|
menuRef.current?.setAttribute('style', `position-anchor: ${anchorName}`);
|
||||||
|
}, [anchorName, disabled]);
|
||||||
|
|
||||||
|
// hide popover with click inside iframe (not supported by light dismiss)
|
||||||
|
useEffect(()=>{
|
||||||
|
const menuElement = document.getElementById(menuId);
|
||||||
|
if(!menuElement) return;
|
||||||
|
|
||||||
|
const handleClick = ()=>{
|
||||||
|
if(menuElement.matches(':popover-open')) {
|
||||||
|
menuElement.hidePopover();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Listen for clicks from both the main document and the iframe
|
||||||
|
document.addEventListener('iframe-click', handleClick);
|
||||||
|
return ()=>{
|
||||||
|
document.removeEventListener('iframe-click', handleClick);
|
||||||
|
};
|
||||||
|
}, [menuId]);
|
||||||
|
|
||||||
|
// the trigger is the piece placed inside the opening button of the menu.
|
||||||
|
// This method allows for creating a generic span with the group name,
|
||||||
|
// or using a bespoke element (like a graphic) passed in from props to be used as the trigger
|
||||||
|
const trigger = (groupName = 'menu', icon = '')=>{
|
||||||
|
if(!customTrigger){
|
||||||
|
return <>
|
||||||
|
<i className={icon}></i><span className='menu-name'>{groupName}</span><i className={`caret fas fa-caret-${isSubMenu ? 'right' : 'down'}`}></i>
|
||||||
|
</>;
|
||||||
|
} else {
|
||||||
|
return customTrigger;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// handle clicks on menu items. By default, actions do dismiss.
|
||||||
|
const handleMenuActionClick = (event)=>{
|
||||||
|
const menuElement = menuRef.current;
|
||||||
|
if(!menuElement) return;
|
||||||
|
|
||||||
|
const menuAction = event.target.closest('button, a, [role="menuitem"]');
|
||||||
|
if(!menuAction || !menuElement.contains(menuAction)) return;
|
||||||
|
|
||||||
|
// don't dismiss if the target triggers a submenu
|
||||||
|
if(menuAction.hasAttribute('popovertarget')) return;
|
||||||
|
|
||||||
|
// don't dismiss if the target has `no-dismiss` attribute
|
||||||
|
const noDismissValue = menuAction.getAttribute('no-dismiss')?.toLowerCase();
|
||||||
|
if(noDismissValue === '' || noDismissValue === 'true') return;
|
||||||
|
|
||||||
|
document.querySelectorAll('.menu-list:popover-open').forEach((openMenu)=>openMenu.hidePopover());
|
||||||
|
};
|
||||||
|
|
||||||
|
if(disabled){
|
||||||
|
return (
|
||||||
|
<li className={['menu-wrapper', className].filter(Boolean).join(' ')} role='none'>
|
||||||
|
<button
|
||||||
|
className={['menu-item', color].filter(Boolean).join(' ')}
|
||||||
|
aria-label={groupName}
|
||||||
|
role='menuitem'
|
||||||
|
disabled
|
||||||
|
>
|
||||||
|
{trigger(groupName, icon)}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<li className={['menu-wrapper', className].filter(Boolean).join(' ')} role='none'>
|
||||||
|
<button
|
||||||
|
id={`${menuId}-trigger`}
|
||||||
|
className={['menu-item', color].join(' ')}
|
||||||
|
popoverTarget={menuId}
|
||||||
|
aria-haspopup='menu'
|
||||||
|
aria-label={groupName}
|
||||||
|
role='menuitem'
|
||||||
|
disabled={!React.Children.count(children)}
|
||||||
|
ref={triggerRef}
|
||||||
|
>
|
||||||
|
{trigger(groupName, icon)}
|
||||||
|
</button>
|
||||||
|
<MenuDepthContext.Provider value={depth + 1}>
|
||||||
|
<ul
|
||||||
|
ref={menuRef}
|
||||||
|
id={menuId}
|
||||||
|
className='menu-list'
|
||||||
|
popover='auto'
|
||||||
|
role='menu'
|
||||||
|
aria-label={`${groupName} Submenu`}
|
||||||
|
onClick={handleMenuActionClick}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</ul>
|
||||||
|
</MenuDepthContext.Provider>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { Dropdown };
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
@property --menuColor {
|
||||||
|
syntax : '<color>';
|
||||||
|
inherits : true;
|
||||||
|
initial-value : #DDDDDD;
|
||||||
|
}
|
||||||
|
|
||||||
|
@property --activeTriggerColor {
|
||||||
|
syntax : '<color>';
|
||||||
|
inherits : true;
|
||||||
|
initial-value : #999999;
|
||||||
|
}
|
||||||
|
|
||||||
|
:root { --activeTriggerColor : var(--activeTriggerColor); }
|
||||||
|
.menu-wrapper {
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
.menu-list {
|
||||||
|
position : fixed;
|
||||||
|
top : anchor(bottom);
|
||||||
|
left : anchor(left);
|
||||||
|
position-try : flip-inline flip-block;
|
||||||
|
contain : content;
|
||||||
|
color : inherit; // [popover] gets a `canvastext` color value from useragent.
|
||||||
|
background : var(--menuColor);
|
||||||
|
li > .menu-list {
|
||||||
|
top : anchor(top);
|
||||||
|
left : anchor(right);
|
||||||
|
margin : 0 0px;
|
||||||
|
position-try : flip-inline;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.menu-wrapper:has(:popover-open) > button { // if menu is open...
|
||||||
|
background-color : var(--activeTriggerColor, hsl(from var(--menuColor) h s calc(l * 0.85))); // tint menu triggers based on menu color
|
||||||
|
}
|
||||||
|
|
||||||
|
.darkMode .menu-wrapper:has(:popover-open) > button { // if menu is open...
|
||||||
|
--activeTriggerColor : #444444; // tint menu triggers based on menu color
|
||||||
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
require('./renderWarnings.less');
|
import './renderWarnings.less';
|
||||||
const React = require('react');
|
import React from 'react';
|
||||||
const createClass = require('create-react-class');
|
import createReactClass from 'create-react-class';
|
||||||
const _ = require('lodash');
|
import _ from 'lodash';
|
||||||
|
|
||||||
import Dialog from '../dialog.jsx';
|
import Dialog from '../dialog.jsx';
|
||||||
|
|
||||||
const RenderWarnings = createClass({
|
const RenderWarnings = createReactClass({
|
||||||
displayName : 'RenderWarnings',
|
displayName : 'RenderWarnings',
|
||||||
getInitialState : function() {
|
getInitialState : function() {
|
||||||
return {
|
return {
|
||||||
@@ -57,4 +57,4 @@ const RenderWarnings = createClass({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = RenderWarnings;
|
export default RenderWarnings;
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@import '@sharedStyles/colors.less';
|
||||||
|
|
||||||
.renderWarnings {
|
.renderWarnings {
|
||||||
position : relative;
|
position : relative;
|
||||||
float : right;
|
float : right;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
require('./splitPane.less');
|
import './splitPane.less';
|
||||||
const React = require('react');
|
import React, { useEffect, useState } from 'react';
|
||||||
const { useState, useEffect } = React;
|
|
||||||
|
|
||||||
const PANE_WIDTH_KEY = 'HB_editor_splitWidth';
|
const PANE_WIDTH_KEY = 'HB_editor_splitWidth';
|
||||||
const LIVE_SCROLL_KEY = 'HB_editor_liveScroll';
|
const LIVE_SCROLL_KEY = 'HB_editor_liveScroll';
|
||||||
@@ -19,8 +18,7 @@ const SplitPane = (props)=>{
|
|||||||
const [liveScroll, setLiveScroll] = useState(false);
|
const [liveScroll, setLiveScroll] = useState(false);
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
const savedPos = window.localStorage.getItem(PANE_WIDTH_KEY);
|
handleResize();
|
||||||
setDividerPos(savedPos ? limitPosition(savedPos, 0.1 * (window.innerWidth - 13), 0.9 * (window.innerWidth - 13)) : window.innerWidth / 2);
|
|
||||||
setLiveScroll(window.localStorage.getItem(LIVE_SCROLL_KEY) === 'true');
|
setLiveScroll(window.localStorage.getItem(LIVE_SCROLL_KEY) === 'true');
|
||||||
|
|
||||||
window.addEventListener('resize', handleResize);
|
window.addEventListener('resize', handleResize);
|
||||||
@@ -30,7 +28,10 @@ const SplitPane = (props)=>{
|
|||||||
const limitPosition = (x, min = 1, max = window.innerWidth - 13)=>Math.round(Math.min(max, Math.max(min, x)));
|
const limitPosition = (x, min = 1, max = window.innerWidth - 13)=>Math.round(Math.min(max, Math.max(min, x)));
|
||||||
|
|
||||||
//when resizing, the divider should grow smaller if less space is given, then grow back if the space is restored, to the original position
|
//when resizing, the divider should grow smaller if less space is given, then grow back if the space is restored, to the original position
|
||||||
const handleResize = ()=>setDividerPos(limitPosition(window.localStorage.getItem(PANE_WIDTH_KEY), 0.1 * (window.innerWidth - 13), 0.9 * (window.innerWidth - 13)));
|
const handleResize = ()=>{
|
||||||
|
const savedPos = window.localStorage.getItem(PANE_WIDTH_KEY);
|
||||||
|
setDividerPos(savedPos ? limitPosition(savedPos, 0.1 * (window.innerWidth - 13), 0.9 * (window.innerWidth - 13)) : window.innerWidth / 2);
|
||||||
|
};
|
||||||
|
|
||||||
const handleUp =(e)=>{
|
const handleUp =(e)=>{
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -57,20 +58,32 @@ const SplitPane = (props)=>{
|
|||||||
setLiveScroll(!liveScroll);
|
setLiveScroll(!liveScroll);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const DividerButton = ({ className, children, ...props })=>{
|
||||||
|
return <div
|
||||||
|
className={className}
|
||||||
|
onPointerDown={(e)=>{e.stopPropagation();}}
|
||||||
|
{...props} >
|
||||||
|
|
||||||
|
{children}
|
||||||
|
|
||||||
|
</div>;
|
||||||
|
};
|
||||||
|
|
||||||
const renderMoveArrows = (showMoveArrows &&
|
const renderMoveArrows = (showMoveArrows &&
|
||||||
<>
|
<>
|
||||||
<div className='arrow left'
|
<DividerButton className='arrow left'
|
||||||
onClick={()=>setMoveSource(!moveSource)} >
|
onClick={()=>setMoveSource(!moveSource)} >
|
||||||
<i className='fas fa-arrow-left' />
|
<i className='fas fa-arrow-left' />
|
||||||
</div>
|
</DividerButton>
|
||||||
<div className='arrow right'
|
<DividerButton
|
||||||
|
className='arrow right'
|
||||||
onClick={()=>setMoveBrew(!moveBrew)} >
|
onClick={()=>setMoveBrew(!moveBrew)} >
|
||||||
<i className='fas fa-arrow-right' />
|
<i className='fas fa-arrow-right' />
|
||||||
</div>
|
</DividerButton>
|
||||||
<div id='scrollToggleDiv' className={liveScroll ? 'arrow lock' : 'arrow unlock'}
|
<DividerButton id='scrollToggleDiv' className={liveScroll ? 'arrow lock' : 'arrow unlock'}
|
||||||
onClick={liveScrollToggle} >
|
onClick={liveScrollToggle} >
|
||||||
<i id='scrollToggle' className={liveScroll ? 'fas fa-lock' : 'fas fa-unlock'} />
|
<i id='scrollToggle' className={liveScroll ? 'fas fa-lock' : 'fas fa-unlock'} />
|
||||||
</div>
|
</DividerButton>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -108,4 +121,4 @@ const Pane = ({ width, children, isDragging, moveBrew, moveSource, liveScroll, s
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = SplitPane;
|
export default SplitPane;
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
@import '@sharedStyles/core.less';
|
||||||
|
|
||||||
.splitPane {
|
.splitPane {
|
||||||
position : relative;
|
position : relative;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
const React = require('react');
|
import React from 'react';
|
||||||
const createClass = require('create-react-class');
|
|
||||||
|
|
||||||
module.exports = function(props){
|
export default function(props){
|
||||||
return <svg version='1.1' x='0px' y='0px' viewBox='0 0 90 112.5' enableBackground='new 0 0 90 90' >
|
return <svg version='1.1' x='0px' y='0px' viewBox='0 0 90 112.5' enableBackground='new 0 0 90 90' >
|
||||||
<path d='M25.363,25.54c0,1.906,8.793,3.454,19.636,3.454c10.848,0,19.638-1.547,19.638-3.454c0-1.12-3.056-2.117-7.774-2.75 c-1.418,1.891-3.659,3.133-6.208,3.133c-2.85,0-5.315-1.547-6.67-3.833C33.617,22.185,25.363,23.692,25.363,25.54z'/><path d='M84.075,54.142c0-8.68-2.868-17.005-8.144-23.829c1.106-1.399,1.41-2.771,1.41-3.854c0-6.574-10.245-9.358-19.264-10.533 c0.209,0.706,0.359,1.439,0.359,2.215c0,0.09-0.022,0.17-0.028,0.26l0,0c-0.028,0.853-0.195,1.667-0.479,2.429 c9.106,1.282,14.508,3.754,14.508,5.63c0,2.644-10.688,6.486-27.439,6.486c-16.748,0-27.438-3.842-27.438-6.486 c0-2.542,9.904-6.183,25.559-6.459c-0.098-0.396-0.159-0.807-0.2-1.223c0.006,0,0.013,0,0.017,0 c-0.017-0.213-0.063-0.417-0.063-0.636c0-1.084,0.226-2.119,0.628-3.058c-6.788,0.129-30.846,1.299-30.846,11.376 c0,1.083,0.305,2.455,1.411,3.854c-5.276,6.823-8.145,15.149-8.145,23.829c0,11.548,5.187,20.107,14.693,25.115 c-0.902,3.146-1.391,7.056,1.111,8.181c2.626,1.178,5.364-2.139,7.111-5.005c4.73,1.261,10.13,1.923,16.161,1.923 c6.034,0,11.428-0.661,16.158-1.922c1.75,2.865,4.493,6.18,7.112,5.004c2.504-1.123,2.014-5.035,1.113-8.179 C78.889,74.249,84.075,65.689,84.075,54.142z M70.39,31.392c5.43,6.046,8.78,14,8.78,22.75c0,20.919-18.582,25.309-34.171,25.309 c-15.587,0-34.17-4.39-34.17-25.309c0-8.75,3.35-16.7,8.781-22.753c5.561,2.643,15.502,4.009,25.389,4.009 C54.886,35.397,64.829,34.031,70.39,31.392z'/><path d='M50.654,23.374c2.892,0,5.234-2.341,5.234-5.233c0-2.887-2.343-5.23-5.234-5.23c-2.887,0-5.231,2.343-5.231,5.23 C45.423,21.032,47.768,23.374,50.654,23.374z'/>
|
<path d='M25.363,25.54c0,1.906,8.793,3.454,19.636,3.454c10.848,0,19.638-1.547,19.638-3.454c0-1.12-3.056-2.117-7.774-2.75 c-1.418,1.891-3.659,3.133-6.208,3.133c-2.85,0-5.315-1.547-6.67-3.833C33.617,22.185,25.363,23.692,25.363,25.54z'/><path d='M84.075,54.142c0-8.68-2.868-17.005-8.144-23.829c1.106-1.399,1.41-2.771,1.41-3.854c0-6.574-10.245-9.358-19.264-10.533 c0.209,0.706,0.359,1.439,0.359,2.215c0,0.09-0.022,0.17-0.028,0.26l0,0c-0.028,0.853-0.195,1.667-0.479,2.429 c9.106,1.282,14.508,3.754,14.508,5.63c0,2.644-10.688,6.486-27.439,6.486c-16.748,0-27.438-3.842-27.438-6.486 c0-2.542,9.904-6.183,25.559-6.459c-0.098-0.396-0.159-0.807-0.2-1.223c0.006,0,0.013,0,0.017,0 c-0.017-0.213-0.063-0.417-0.063-0.636c0-1.084,0.226-2.119,0.628-3.058c-6.788,0.129-30.846,1.299-30.846,11.376 c0,1.083,0.305,2.455,1.411,3.854c-5.276,6.823-8.145,15.149-8.145,23.829c0,11.548,5.187,20.107,14.693,25.115 c-0.902,3.146-1.391,7.056,1.111,8.181c2.626,1.178,5.364-2.139,7.111-5.005c4.73,1.261,10.13,1.923,16.161,1.923 c6.034,0,11.428-0.661,16.158-1.922c1.75,2.865,4.493,6.18,7.112,5.004c2.504-1.123,2.014-5.035,1.113-8.179 C78.889,74.249,84.075,65.689,84.075,54.142z M70.39,31.392c5.43,6.046,8.78,14,8.78,22.75c0,20.919-18.582,25.309-34.171,25.309 c-15.587,0-34.17-4.39-34.17-25.309c0-8.75,3.35-16.7,8.781-22.753c5.561,2.643,15.502,4.009,25.389,4.009 C54.886,35.397,64.829,34.031,70.39,31.392z'/><path d='M50.654,23.374c2.892,0,5.234-2.341,5.234-5.233c0-2.887-2.343-5.23-5.234-5.23c-2.887,0-5.231,2.343-5.231,5.23 C45.423,21.032,47.768,23.374,50.654,23.374z'/>
|
||||||
<circle cx='62.905' cy='10.089' r='3.595'/>
|
<circle cx='62.905' cy='10.089' r='3.595'/>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
const React = require('react');
|
import React from 'react';
|
||||||
const createClass = require('create-react-class');
|
|
||||||
|
|
||||||
module.exports = function(props){
|
export default function(props){
|
||||||
return <svg version='1.1' x='0px' y='0px' viewBox='0 0 100 100' enableBackground='new 0 0 100 100'><path d='M80.644,87.982l16.592-41.483c0.054-0.128,0.088-0.26,0.108-0.394c0.006-0.039,0.007-0.077,0.011-0.116 c0.007-0.087,0.008-0.174,0.002-0.26c-0.003-0.046-0.007-0.091-0.014-0.137c-0.014-0.089-0.036-0.176-0.063-0.262 c-0.012-0.034-0.019-0.069-0.031-0.103c-0.047-0.118-0.106-0.229-0.178-0.335c-0.004-0.006-0.006-0.012-0.01-0.018L67.999,3.358 c-0.01-0.013-0.003-0.026-0.013-0.04L68,3.315V4c0,0-0.033,0-0.037,0c-0.403-1-1.094-1.124-1.752-0.976 c0,0.004-0.004-0.012-0.007-0.012C66.201,3.016,66.194,3,66.194,3H66.19h-0.003h-0.003h-0.004h-0.003c0,0-0.004,0-0.007,0 s-0.003-0.151-0.007-0.151L20.495,15.227c-0.025,0.007-0.046-0.019-0.071-0.011c-0.087,0.028-0.172,0.041-0.253,0.083 c-0.054,0.027-0.102,0.053-0.152,0.085c-0.051,0.033-0.101,0.061-0.147,0.099c-0.044,0.036-0.084,0.073-0.124,0.113 c-0.048,0.048-0.093,0.098-0.136,0.152c-0.03,0.039-0.059,0.076-0.085,0.117c-0.046,0.07-0.084,0.145-0.12,0.223 c-0.011,0.023-0.027,0.042-0.036,0.066L2.911,57.664C2.891,57.715,3,57.768,3,57.82v0.002c0,0.186,0,0.375,0,0.562 c0,0.004,0,0.004,0,0.008c0,0,0,0,0,0.002c0,0,0,0,0,0.004v0.004v0.002c0,0.074-0.002,0.15,0.012,0.223 C3.015,58.631,3,58.631,3,58.633c0,0.004,0,0.004,0,0.008c0,0,0,0,0,0.002c0,0,0,0,0,0.004v0.004c0,0,0,0,0,0.002v0.004 c0,0.191-0.046,0.377,0.06,0.545c0-0.002-0.03,0.004-0.03,0.004c0,0.004-0.03,0.004-0.03,0.004c0,0.002,0,0.002,0,0.002 l-0.045,0.004c0.03,0.047,0.036,0.09,0.068,0.133l29.049,37.359c0.002,0.004,0,0.006,0.002,0.01c0.002,0.002,0,0.004,0.002,0.008 c0.006,0.008,0.014,0.014,0.021,0.021c0.024,0.029,0.052,0.051,0.078,0.078c0.027,0.029,0.053,0.057,0.082,0.082 c0.03,0.027,0.055,0.062,0.086,0.088c0.026,0.02,0.057,0.033,0.084,0.053c0.04,0.027,0.081,0.053,0.123,0.076 c0.005,0.004,0.01,0.008,0.016,0.01c0.087,0.051,0.176,0.09,0.269,0.123c0.042,0.014,0.082,0.031,0.125,0.043 c0.021,0.006,0.041,0.018,0.062,0.021c0.123,0.027,0.249,0.043,0.375,0.043c0.099,0,0.202-0.012,0.304-0.027l45.669-8.303 c0.057-0.01,0.108-0.021,0.163-0.037C79.547,88.992,79.562,89,79.575,89c0.004,0,0.004,0,0.004,0c0.021,0,0.039-0.027,0.06-0.035 c0.041-0.014,0.08-0.034,0.12-0.052c0.021-0.01,0.044-0.019,0.064-0.03c0.017-0.01,0.026-0.015,0.033-0.017 c0.014-0.008,0.023-0.021,0.037-0.028c0.14-0.078,0.269-0.174,0.38-0.285c0.014-0.016,0.024-0.034,0.038-0.048 c0.109-0.119,0.201-0.252,0.271-0.398c0.006-0.01,0.016-0.018,0.021-0.029c0.004-0.008,0.008-0.017,0.011-0.026 c0.002-0.004,0.003-0.006,0.005-0.01C80.627,88.021,80.635,88.002,80.644,87.982z M77.611,84.461L48.805,66.453l32.407-25.202 L77.611,84.461z M46.817,63.709L35.863,23.542l43.818,14.608L46.817,63.709z M84.668,40.542l8.926,5.952l-11.902,29.75 L84.668,40.542z M89.128,39.446L84.53,36.38l-6.129-12.257L89.128,39.446z M79.876,34.645L37.807,20.622L65.854,6.599L79.876,34.645 z M33.268,19.107l-6.485-2.162l23.781-6.487L33.268,19.107z M21.92,18.895l8.67,2.891L10.357,47.798L21.92,18.895z M32.652,24.649 l10.845,39.757L7.351,57.178L32.652,24.649z M43.472,67.857L32.969,92.363L8.462,60.855L43.472,67.857z M46.631,69.09l27.826,17.393 l-38.263,6.959L46.631,69.09z'></path></svg>;
|
return <svg version='1.1' x='0px' y='0px' viewBox='0 0 100 100' enableBackground='new 0 0 100 100'><path d='M80.644,87.982l16.592-41.483c0.054-0.128,0.088-0.26,0.108-0.394c0.006-0.039,0.007-0.077,0.011-0.116 c0.007-0.087,0.008-0.174,0.002-0.26c-0.003-0.046-0.007-0.091-0.014-0.137c-0.014-0.089-0.036-0.176-0.063-0.262 c-0.012-0.034-0.019-0.069-0.031-0.103c-0.047-0.118-0.106-0.229-0.178-0.335c-0.004-0.006-0.006-0.012-0.01-0.018L67.999,3.358 c-0.01-0.013-0.003-0.026-0.013-0.04L68,3.315V4c0,0-0.033,0-0.037,0c-0.403-1-1.094-1.124-1.752-0.976 c0,0.004-0.004-0.012-0.007-0.012C66.201,3.016,66.194,3,66.194,3H66.19h-0.003h-0.003h-0.004h-0.003c0,0-0.004,0-0.007,0 s-0.003-0.151-0.007-0.151L20.495,15.227c-0.025,0.007-0.046-0.019-0.071-0.011c-0.087,0.028-0.172,0.041-0.253,0.083 c-0.054,0.027-0.102,0.053-0.152,0.085c-0.051,0.033-0.101,0.061-0.147,0.099c-0.044,0.036-0.084,0.073-0.124,0.113 c-0.048,0.048-0.093,0.098-0.136,0.152c-0.03,0.039-0.059,0.076-0.085,0.117c-0.046,0.07-0.084,0.145-0.12,0.223 c-0.011,0.023-0.027,0.042-0.036,0.066L2.911,57.664C2.891,57.715,3,57.768,3,57.82v0.002c0,0.186,0,0.375,0,0.562 c0,0.004,0,0.004,0,0.008c0,0,0,0,0,0.002c0,0,0,0,0,0.004v0.004v0.002c0,0.074-0.002,0.15,0.012,0.223 C3.015,58.631,3,58.631,3,58.633c0,0.004,0,0.004,0,0.008c0,0,0,0,0,0.002c0,0,0,0,0,0.004v0.004c0,0,0,0,0,0.002v0.004 c0,0.191-0.046,0.377,0.06,0.545c0-0.002-0.03,0.004-0.03,0.004c0,0.004-0.03,0.004-0.03,0.004c0,0.002,0,0.002,0,0.002 l-0.045,0.004c0.03,0.047,0.036,0.09,0.068,0.133l29.049,37.359c0.002,0.004,0,0.006,0.002,0.01c0.002,0.002,0,0.004,0.002,0.008 c0.006,0.008,0.014,0.014,0.021,0.021c0.024,0.029,0.052,0.051,0.078,0.078c0.027,0.029,0.053,0.057,0.082,0.082 c0.03,0.027,0.055,0.062,0.086,0.088c0.026,0.02,0.057,0.033,0.084,0.053c0.04,0.027,0.081,0.053,0.123,0.076 c0.005,0.004,0.01,0.008,0.016,0.01c0.087,0.051,0.176,0.09,0.269,0.123c0.042,0.014,0.082,0.031,0.125,0.043 c0.021,0.006,0.041,0.018,0.062,0.021c0.123,0.027,0.249,0.043,0.375,0.043c0.099,0,0.202-0.012,0.304-0.027l45.669-8.303 c0.057-0.01,0.108-0.021,0.163-0.037C79.547,88.992,79.562,89,79.575,89c0.004,0,0.004,0,0.004,0c0.021,0,0.039-0.027,0.06-0.035 c0.041-0.014,0.08-0.034,0.12-0.052c0.021-0.01,0.044-0.019,0.064-0.03c0.017-0.01,0.026-0.015,0.033-0.017 c0.014-0.008,0.023-0.021,0.037-0.028c0.14-0.078,0.269-0.174,0.38-0.285c0.014-0.016,0.024-0.034,0.038-0.048 c0.109-0.119,0.201-0.252,0.271-0.398c0.006-0.01,0.016-0.018,0.021-0.029c0.004-0.008,0.008-0.017,0.011-0.026 c0.002-0.004,0.003-0.006,0.005-0.01C80.627,88.021,80.635,88.002,80.644,87.982z M77.611,84.461L48.805,66.453l32.407-25.202 L77.611,84.461z M46.817,63.709L35.863,23.542l43.818,14.608L46.817,63.709z M84.668,40.542l8.926,5.952l-11.902,29.75 L84.668,40.542z M89.128,39.446L84.53,36.38l-6.129-12.257L89.128,39.446z M79.876,34.645L37.807,20.622L65.854,6.599L79.876,34.645 z M33.268,19.107l-6.485-2.162l23.781-6.487L33.268,19.107z M21.92,18.895l8.67,2.891L10.357,47.798L21.92,18.895z M32.652,24.649 l10.845,39.757L7.351,57.178L32.652,24.649z M43.472,67.857L32.969,92.363L8.462,60.855L43.472,67.857z M46.631,69.09l27.826,17.393 l-38.263,6.959L46.631,69.09z'></path></svg>;
|
||||||
};
|
};
|
||||||
@@ -1,36 +1,38 @@
|
|||||||
/*eslint max-lines: ["warn", {"max": 300, "skipBlankLines": true, "skipComments": true}]*/
|
/*eslint max-lines: ["warn", {"max": 300, "skipBlankLines": true, "skipComments": true}]*/
|
||||||
require('./brewRenderer.less');
|
import brewRendererStylesUrl from './brewRenderer.less?url';
|
||||||
const React = require('react');
|
import headerNavStylesUrl from './headerNav/headerNav.less?url';
|
||||||
const { useState, useRef, useMemo, useEffect } = React;
|
import './brewRenderer.less';
|
||||||
const _ = require('lodash');
|
import React, { useState, useRef, useMemo, useEffect } from 'react';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
const MarkdownLegacy = require('markdownLegacy.js');
|
import MarkdownLegacy from '@shared/markdownLegacy.js';
|
||||||
import Markdown from 'markdown.js';
|
import { hbfm } from 'marked-hbfm';
|
||||||
const ErrorBar = require('./errorBar/errorBar.jsx');
|
import ErrorBar from './errorBar/errorBar.jsx';
|
||||||
const ToolBar = require('./toolBar/toolBar.jsx');
|
import ToolBar from './toolBar/toolBar.jsx';
|
||||||
|
|
||||||
//TODO: move to the brew renderer
|
//TODO: move to the brew renderer
|
||||||
const RenderWarnings = require('client/components/renderWarnings/renderWarnings.jsx');
|
import RenderWarnings from '@components/renderWarnings/renderWarnings.jsx';
|
||||||
const NotificationPopup = require('./notificationPopup/notificationPopup.jsx');
|
import NotificationPopup from './notificationPopup/notificationPopup.jsx';
|
||||||
const Frame = require('react-frame-component').default;
|
import Frame from 'react-frame-component';
|
||||||
const dedent = require('dedent-tabs').default;
|
import dedent from 'dedent';
|
||||||
const { printCurrentBrew } = require('../../../shared/helpers.js');
|
import { printCurrentBrew } from '@shared/helpers.js';
|
||||||
|
|
||||||
import HeaderNav from './headerNav/headerNav.jsx';
|
import HeaderNav from './headerNav/headerNav.jsx';
|
||||||
import { safeHTML } from './safeHTML.js';
|
import safeHTML from './safeHTML.js';
|
||||||
|
|
||||||
const PAGEBREAK_REGEX_V3 = /^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m;
|
const PAGEBREAK_REGEX_V3 = /^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m;
|
||||||
const PAGEBREAK_REGEX_LEGACY = /\\page(?:break)?/m;
|
const PAGEBREAK_REGEX_LEGACY = /\\page(?:break)?/m;
|
||||||
const COLUMNBREAK_REGEX_LEGACY = /\\column(:?break)?/m;
|
const COLUMNBREAK_REGEX_LEGACY = /\\column(:?break)?/m;
|
||||||
const PAGE_HEIGHT = 1056;
|
|
||||||
|
|
||||||
const TOOLBAR_STATE_KEY = 'HB_renderer_toolbarState';
|
const TOOLBAR_STATE_KEY = 'HB_renderer_toolbarState';
|
||||||
|
|
||||||
const INITIAL_CONTENT = dedent`
|
const INITIAL_CONTENT = dedent`
|
||||||
<!DOCTYPE html><html><head>
|
<!DOCTYPE html><html><head>
|
||||||
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700" rel="stylesheet" type="text/css" />
|
<title>Rendered Brew Content</title>
|
||||||
<link href='/homebrew/bundle.css' type="text/css" rel='stylesheet' />
|
<link href='/homebrew/bundle.css' type="text/css" rel='stylesheet' />
|
||||||
<base target=_blank>
|
<link href="${brewRendererStylesUrl}" rel="stylesheet" />
|
||||||
|
<link href="${headerNavStylesUrl}" rel="stylesheet" />
|
||||||
|
<base target="_top">
|
||||||
</head><body style='overflow: hidden'><div></div></body></html>`;
|
</head><body style='overflow: hidden'><div></div></body></html>`;
|
||||||
|
|
||||||
|
|
||||||
@@ -43,31 +45,25 @@ const BrewPage = (props)=>{
|
|||||||
};
|
};
|
||||||
const pageRef = useRef(null);
|
const pageRef = useRef(null);
|
||||||
const cleanText = safeHTML(props.contents);
|
const cleanText = safeHTML(props.contents);
|
||||||
|
const pageNum = props.index + 1;
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
if(!pageRef.current) return;
|
if(!pageRef.current) return;
|
||||||
|
|
||||||
// Observer for tracking pages within the `.pages` div
|
// Observer for tracking which pages are at least 30% visible in the iframe
|
||||||
const visibleObserver = new IntersectionObserver(
|
const visibleObserver = new IntersectionObserver(
|
||||||
(entries)=>{
|
(entries)=>entries.forEach((entry)=>{
|
||||||
entries.forEach((entry)=>{
|
props.onVisibilityChange(pageNum, entry.isIntersecting, false); // add/remove page from array of visible pages.
|
||||||
if(entry.isIntersecting)
|
}),
|
||||||
props.onVisibilityChange(props.index + 1, true, false); // add page to array of visible pages.
|
|
||||||
else
|
|
||||||
props.onVisibilityChange(props.index + 1, false, false);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
{ threshold: .3, rootMargin: '0px 0px 0px 0px' } // detect when >30% of page is within bounds.
|
{ threshold: .3, rootMargin: '0px 0px 0px 0px' } // detect when >30% of page is within bounds.
|
||||||
);
|
);
|
||||||
|
|
||||||
// Observer for tracking the page at the center of the iframe.
|
// Observer for tracking the page at the center of the iframe.
|
||||||
const centerObserver = new IntersectionObserver(
|
const centerObserver = new IntersectionObserver(
|
||||||
(entries)=>{
|
(entries)=>entries.forEach((entry)=>{
|
||||||
entries.forEach((entry)=>{
|
if(entry.isIntersecting)
|
||||||
if(entry.isIntersecting)
|
props.onVisibilityChange(pageNum, true, true); // Set this page as the center page
|
||||||
props.onVisibilityChange(props.index + 1, true, true); // Set this page as the center page
|
}),
|
||||||
});
|
|
||||||
},
|
|
||||||
{ threshold: 0, rootMargin: '-50% 0px -50% 0px' } // Detect when the page is at the center
|
{ threshold: 0, rootMargin: '-50% 0px -50% 0px' } // Detect when the page is at the center
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -88,6 +84,7 @@ const BrewPage = (props)=>{
|
|||||||
|
|
||||||
//v=====--------------------< Brew Renderer Component >-------------------=====v//
|
//v=====--------------------< Brew Renderer Component >-------------------=====v//
|
||||||
let renderedPages = [];
|
let renderedPages = [];
|
||||||
|
const pageTemplates = [];
|
||||||
let rawPages = [];
|
let rawPages = [];
|
||||||
|
|
||||||
const BrewRenderer = (props)=>{
|
const BrewRenderer = (props)=>{
|
||||||
@@ -95,22 +92,23 @@ const BrewRenderer = (props)=>{
|
|||||||
text : '',
|
text : '',
|
||||||
style : '',
|
style : '',
|
||||||
renderer : 'legacy',
|
renderer : 'legacy',
|
||||||
theme : '5ePHB',
|
|
||||||
lang : '',
|
lang : '',
|
||||||
errors : [],
|
errors : [],
|
||||||
currentEditorCursorPageNum : 1,
|
currentEditorCursorPageNum : 1,
|
||||||
currentEditorViewPageNum : 1,
|
|
||||||
currentBrewRendererPageNum : 1,
|
|
||||||
themeBundle : {},
|
themeBundle : {},
|
||||||
onPageChange : ()=>{},
|
onPageChange : ()=>{},
|
||||||
...props
|
...props
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const pagesRef = useRef(null);
|
||||||
|
|
||||||
|
const [visiblePages, setVisiblePages] = useState([]);
|
||||||
|
const [centerPage, setCenterPage] = useState(1);
|
||||||
|
const [headerState, setHeaderState] = useState(false);
|
||||||
|
|
||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
isMounted : false,
|
isMounted : false,
|
||||||
visibility : 'hidden',
|
visibility : 'hidden'
|
||||||
visiblePages : [],
|
|
||||||
centerPage : 1
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const [displayOptions, setDisplayOptions] = useState({
|
const [displayOptions, setDisplayOptions] = useState({
|
||||||
@@ -128,11 +126,6 @@ const BrewRenderer = (props)=>{
|
|||||||
toolbarState && setDisplayOptions(toolbarState);
|
toolbarState && setDisplayOptions(toolbarState);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const [headerState, setHeaderState] = useState(false);
|
|
||||||
|
|
||||||
const mainRef = useRef(null);
|
|
||||||
const pagesRef = useRef(null);
|
|
||||||
|
|
||||||
if(props.renderer == 'legacy') {
|
if(props.renderer == 'legacy') {
|
||||||
rawPages = props.text.split(PAGEBREAK_REGEX_LEGACY);
|
rawPages = props.text.split(PAGEBREAK_REGEX_LEGACY);
|
||||||
} else {
|
} else {
|
||||||
@@ -140,20 +133,16 @@ const BrewRenderer = (props)=>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handlePageVisibilityChange = (pageNum, isVisible, isCenter)=>{
|
const handlePageVisibilityChange = (pageNum, isVisible, isCenter)=>{
|
||||||
setState((prevState)=>{
|
setVisiblePages((prev)=>{
|
||||||
const updatedVisiblePages = new Set(prevState.visiblePages);
|
const updatedVisiblePages = new Set(prev);
|
||||||
if(!isCenter)
|
isVisible ? updatedVisiblePages.add(pageNum) : updatedVisiblePages.delete(pageNum);
|
||||||
isVisible ? updatedVisiblePages.add(pageNum) : updatedVisiblePages.delete(pageNum);
|
return [...updatedVisiblePages].sort((a, b)=>a - b);
|
||||||
|
|
||||||
return {
|
|
||||||
...prevState,
|
|
||||||
visiblePages : [...updatedVisiblePages].sort((a, b)=>a - b),
|
|
||||||
centerPage : isCenter ? pageNum : prevState.centerPage
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if(isCenter)
|
if(isCenter) {
|
||||||
|
setCenterPage(pageNum);
|
||||||
props.onPageChange(pageNum);
|
props.onPageChange(pageNum);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const isInView = (index)=>{
|
const isInView = (index)=>{
|
||||||
@@ -163,17 +152,15 @@ const BrewRenderer = (props)=>{
|
|||||||
if(index == props.currentEditorCursorPageNum - 1) //Already rendered before this step
|
if(index == props.currentEditorCursorPageNum - 1) //Already rendered before this step
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(Math.abs(index - props.currentBrewRendererPageNum - 1) <= 3)
|
if(Math.abs(index - centerPage - 1) <= 3)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderDummyPage = (index)=>{
|
const renderDummyPage = (index)=><div className='phb page' id={`p${index + 1}`} key={index}>
|
||||||
return <div className='phb page' id={`p${index + 1}`} key={index}>
|
<i className='fas fa-spinner fa-spin' />
|
||||||
<i className='fas fa-spinner fa-spin' />
|
</div>;
|
||||||
</div>;
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderStyle = ()=>{
|
const renderStyle = ()=>{
|
||||||
const themeStyles = props.themeBundle?.joinedStyles ?? '<style>@import url("/themes/V3/Blank/style.css");</style>';
|
const themeStyles = props.themeBundle?.joinedStyles ?? '<style>@import url("/themes/V3/Blank/style.css");</style>';
|
||||||
@@ -197,13 +184,27 @@ const BrewRenderer = (props)=>{
|
|||||||
return <BrewPage className='page phb' index={index} key={index} contents={html} style={styles} onVisibilityChange={handlePageVisibilityChange} />;
|
return <BrewPage className='page phb' index={index} key={index} contents={html} style={styles} onVisibilityChange={handlePageVisibilityChange} />;
|
||||||
} else {
|
} else {
|
||||||
if(pageText.startsWith('\\page')) {
|
if(pageText.startsWith('\\page')) {
|
||||||
const firstLineTokens = Markdown.marked.lexer(pageText.split('\n', 1)[0])[0].tokens;
|
const firstLineTokens = hbfm.marked.lexer(pageText.split('\n', 1)[0])[0].tokens;
|
||||||
const injectedTags = firstLineTokens?.find((obj)=>obj.injectedTags !== undefined)?.injectedTags;
|
const injectedTags = firstLineTokens?.find((obj)=>obj.injectedTags !== undefined)?.injectedTags;
|
||||||
if(injectedTags) {
|
if(injectedTags) {
|
||||||
styles = { ...styles, ...injectedTags.styles };
|
styles = { ...styles, ...injectedTags.styles };
|
||||||
styles = _.mapKeys(styles, (v, k)=>k.startsWith('--') ? k : _.camelCase(k)); // Convert CSS to camelCase for React
|
styles = _.mapKeys(styles, (v, k)=>k.startsWith('--') ? k : _.camelCase(k)); // Convert CSS to camelCase for React
|
||||||
classes = [classes, injectedTags.classes].join(' ').trim();
|
classes = [classes, injectedTags.classes].join(' ').trim();
|
||||||
attributes = injectedTags.attributes;
|
attributes = injectedTags.attributes;
|
||||||
|
if(global.enablev4) {
|
||||||
|
if(attributes && Object.hasOwn(attributes, 'hbtemplate')) {
|
||||||
|
pageTemplates[index] = attributes['hbtemplate'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(global.enablev4) {
|
||||||
|
// If we don't have a template for this page, look backwards until one is found or the first page.
|
||||||
|
if(!pageTemplates[index]) {
|
||||||
|
for (let i=index;i>=0; i--) {
|
||||||
|
// If one is found, add the template attribute
|
||||||
|
if(pageTemplates[i]) attributes['hbtemplate'] = pageTemplates[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pageText = pageText.includes('\n') ? pageText.substring(pageText.indexOf('\n') + 1) : ''; // Remove the \page line
|
pageText = pageText.includes('\n') ? pageText.substring(pageText.indexOf('\n') + 1) : ''; // Remove the \page line
|
||||||
}
|
}
|
||||||
@@ -211,18 +212,20 @@ const BrewRenderer = (props)=>{
|
|||||||
// DO NOT REMOVE!!! REQUIRED FOR BACKWARDS COMPATIBILITY WITH NON-UPGRADABLE VERSIONS OF CHROME.
|
// DO NOT REMOVE!!! REQUIRED FOR BACKWARDS COMPATIBILITY WITH NON-UPGRADABLE VERSIONS OF CHROME.
|
||||||
pageText += `\n\n \n\\column\n `; //Artificial column break at page end to emulate column-fill:auto (until `wide` is used, when column-fill:balance will reappear)
|
pageText += `\n\n \n\\column\n `; //Artificial column break at page end to emulate column-fill:auto (until `wide` is used, when column-fill:balance will reappear)
|
||||||
|
|
||||||
const html = Markdown.render(pageText, index);
|
const html = hbfm.render(pageText, index);
|
||||||
|
|
||||||
return <BrewPage className={classes} index={index} key={index} contents={html} style={styles} attributes={attributes} onVisibilityChange={handlePageVisibilityChange} />;
|
return <BrewPage className={classes} index={index} key={index} contents={html} style={styles} attributes={attributes} onVisibilityChange={handlePageVisibilityChange} />;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderPages = ()=>{
|
const renderPages = ()=>{
|
||||||
if(props.errors && props.errors.length)
|
if(props.errors?.length)
|
||||||
return renderedPages;
|
return renderedPages;
|
||||||
|
|
||||||
if(rawPages.length != renderedPages.length) // Re-render all pages when page count changes
|
if(rawPages.length != renderedPages.length) { // Re-render all pages when page count changes
|
||||||
renderedPages.length = 0;
|
renderedPages.length = 0;
|
||||||
|
pageTemplates.length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Render currently-edited page first so cross-page effects (variables, links) can propagate out first
|
// Render currently-edited page first so cross-page effects (variables, links) can propagate out first
|
||||||
if(rawPages.length > props.currentEditorCursorPageNum -1)
|
if(rawPages.length > props.currentEditorCursorPageNum -1)
|
||||||
@@ -269,7 +272,9 @@ const BrewRenderer = (props)=>{
|
|||||||
const frameDidMount = ()=>{ //This triggers when iFrame finishes internal "componentDidMount"
|
const frameDidMount = ()=>{ //This triggers when iFrame finishes internal "componentDidMount"
|
||||||
scrollToHash(window.location.hash);
|
scrollToHash(window.location.hash);
|
||||||
|
|
||||||
setTimeout(()=>{ //We still see a flicker where the style isn't applied yet, so wait 100ms before showing iFrame
|
window.addEventListener('hashchange', ()=>scrollToHash(window.location.hash));
|
||||||
|
|
||||||
|
setTimeout(()=>{ //We still see a flicker where the style isn't applied yet, so wait 100ms before showing iFrame
|
||||||
renderPages(); //Make sure page is renderable before showing
|
renderPages(); //Make sure page is renderable before showing
|
||||||
setState((prevState)=>({
|
setState((prevState)=>({
|
||||||
...prevState,
|
...prevState,
|
||||||
@@ -296,7 +301,7 @@ const BrewRenderer = (props)=>{
|
|||||||
};
|
};
|
||||||
|
|
||||||
const renderedStyle = useMemo(()=>renderStyle(), [props.style, props.themeBundle]);
|
const renderedStyle = useMemo(()=>renderStyle(), [props.style, props.themeBundle]);
|
||||||
renderedPages = useMemo(()=>renderPages(), [props.text, displayOptions]);
|
renderedPages = useMemo(()=>renderPages(), [props.text, centerPage, displayOptions]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -310,18 +315,19 @@ const BrewRenderer = (props)=>{
|
|||||||
: null}
|
: null}
|
||||||
|
|
||||||
<ErrorBar errors={props.errors} />
|
<ErrorBar errors={props.errors} />
|
||||||
<div className='popups' ref={mainRef}>
|
<div className='popups'>
|
||||||
<RenderWarnings />
|
<RenderWarnings />
|
||||||
<NotificationPopup />
|
<NotificationPopup />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ToolBar displayOptions={displayOptions} onDisplayOptionsChange={handleDisplayOptionsChange} visiblePages={state.visiblePages.length > 0 ? state.visiblePages : [state.centerPage]} totalPages={rawPages.length} headerState={headerState} setHeaderState={setHeaderState}/>
|
<ToolBar displayOptions={displayOptions} onDisplayOptionsChange={handleDisplayOptionsChange} visiblePages={visiblePages.length > 0 ? visiblePages : [centerPage]} totalPages={rawPages.length} headerState={headerState} setHeaderState={setHeaderState}/>
|
||||||
|
|
||||||
{/*render in iFrame so broken code doesn't crash the site.*/}
|
{/*render in iFrame so broken code doesn't crash the site.*/}
|
||||||
<Frame id='BrewRenderer' initialContent={INITIAL_CONTENT}
|
<Frame id='BrewRenderer' title='Rendered Brew Content' initialContent={INITIAL_CONTENT}
|
||||||
style={{ width: '100%', height: '100%', visibility: state.visibility }}
|
style={{ width: '100%', height: '100%', visibility: state.visibility }}
|
||||||
contentDidMount={frameDidMount}
|
contentDidMount={frameDidMount}
|
||||||
onClick={()=>{emitClick();}}
|
onClick={emitClick}
|
||||||
|
sandbox='allow-same-origin allow-modals allow-top-navigation'
|
||||||
>
|
>
|
||||||
<div className='brewRenderer'
|
<div className='brewRenderer'
|
||||||
onKeyDown={handleControlKeys}
|
onKeyDown={handleControlKeys}
|
||||||
@@ -345,4 +351,4 @@ const BrewRenderer = (props)=>{
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = BrewRenderer;
|
export default BrewRenderer;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
@import (multiple, less) 'shared/naturalcrit/styles/reset.less';
|
@import '@sharedStyles/core.less';
|
||||||
|
|
||||||
.brewRenderer {
|
.brewRenderer {
|
||||||
height : 100vh;
|
height : 100vh;
|
||||||
@@ -59,6 +59,10 @@
|
|||||||
}
|
}
|
||||||
&-corner { visibility : hidden; }
|
&-corner { visibility : hidden; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@supports (break-after:always) {
|
||||||
|
.columnSplit { margin-bottom : 100vh; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.pane { position : relative; }
|
.pane { position : relative; }
|
||||||
@@ -70,15 +74,14 @@
|
|||||||
height : 100%;
|
height : 100%;
|
||||||
padding : unset;
|
padding : unset;
|
||||||
overflow-y : unset;
|
overflow-y : unset;
|
||||||
&:has(.facing, .flow) {
|
&:has(.facing, .flow) { padding : unset; }
|
||||||
padding : unset;
|
|
||||||
}
|
|
||||||
.pages {
|
.pages {
|
||||||
|
display : block;
|
||||||
margin : 0px;
|
margin : 0px;
|
||||||
zoom : 100% !important;
|
zoom : 100% !important;
|
||||||
display : block;
|
|
||||||
& > .page { box-shadow : unset; }
|
& > .page { box-shadow : unset; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.headerNav { visibility : hidden; }
|
.headerNav { visibility : hidden; }
|
||||||
}
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
require('./errorBar.less');
|
import './errorBar.less';
|
||||||
const React = require('react');
|
import React from 'react';
|
||||||
|
|
||||||
import Dialog from '../../../components/dialog.jsx';
|
import Dialog from '@components/dialog.jsx';
|
||||||
|
|
||||||
const DISMISS_BUTTON = <i className='fas fa-times dismiss' />;
|
const DISMISS_BUTTON = <i className='fas fa-times dismiss' />;
|
||||||
|
|
||||||
@@ -50,4 +50,4 @@ const ErrorBar = (props)=>{
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = ErrorBar;
|
export default ErrorBar;
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
@import '@sharedStyles/colors.less';
|
||||||
|
|
||||||
.errorBar {
|
.errorBar {
|
||||||
position : absolute;
|
position : absolute;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
require('./headerNav.less');
|
import './headerNav.less';
|
||||||
|
|
||||||
import * as React from 'react';
|
import React from 'react';
|
||||||
import * as _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
const MAX_TEXT_LENGTH = 40;
|
const MAX_TEXT_LENGTH = 40;
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ const HeaderNavItem = ({ link, text, depth, className })=>{
|
|||||||
if(!link || !text) return;
|
if(!link || !text) return;
|
||||||
|
|
||||||
return <li>
|
return <li>
|
||||||
<a href={`#${link}`} target='_self' className={`depth-${depth} ${className ?? ''}`}>
|
<a href={`#${link}`} className={`depth-${depth} ${className ?? ''}`}>
|
||||||
{trimString(text, depth)}
|
{trimString(text, depth)}
|
||||||
</a>
|
</a>
|
||||||
</li>;
|
</li>;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
require('./notificationPopup.less');
|
import './notificationPopup.less';
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import request from '../../utils/request-middleware.js';
|
import request from '../../utils/request-middleware.js';
|
||||||
import Markdown from 'markdown.js';
|
import { hbfm } from 'marked-hbfm';
|
||||||
|
|
||||||
import Dialog from '../../../components/dialog.jsx';
|
import Dialog from '@components/dialog.jsx';
|
||||||
|
|
||||||
const DISMISS_BUTTON = <i className='fas fa-times dismiss' />;
|
const DISMISS_BUTTON = <i className='fas fa-times dismiss' />;
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ const NotificationPopup = ()=>{
|
|||||||
return notifications.map((notification)=>(
|
return notifications.map((notification)=>(
|
||||||
<li key={notification.dismissKey} >
|
<li key={notification.dismissKey} >
|
||||||
<em>{notification.title}</em><br />
|
<em>{notification.title}</em><br />
|
||||||
<p dangerouslySetInnerHTML={{ __html: Markdown.render(notification.text) }}></p>
|
<p dangerouslySetInnerHTML={{ __html: hbfm.render(notification.text) }}></p>
|
||||||
</li>
|
</li>
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
@@ -62,4 +62,4 @@ const NotificationPopup = ()=>{
|
|||||||
</Dialog>;
|
</Dialog>;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = NotificationPopup;
|
export default NotificationPopup;
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@import './client/homebrew/navbar/navbar.less';
|
||||||
|
|
||||||
.popups {
|
.popups {
|
||||||
position : fixed;
|
position : fixed;
|
||||||
top : calc(@navbarHeight + @viewerToolsHeight);
|
top : calc(@navbarHeight + @viewerToolsHeight);
|
||||||
|
|||||||
@@ -32,15 +32,15 @@ function safeHTML(htmlString) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check remaining elements for blacklisted attributes
|
// Check remaining elements for blacklisted attributes
|
||||||
for (const attribute of element.attributes){
|
[...element.attributes].forEach((attribute)=>{
|
||||||
if(blacklistAttrs.some((test)=>{return test(attribute);})) {
|
if(blacklistAttrs.some((test)=>{return test(attribute);})) {
|
||||||
element.removeAttribute(attribute.localName);
|
element.removeAttribute(attribute.name);
|
||||||
break;
|
return;
|
||||||
};
|
};
|
||||||
};
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return div.innerHTML;
|
return div.innerHTML;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.safeHTML = safeHTML;
|
export default safeHTML;
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
/* eslint-disable max-lines */
|
/* eslint-disable max-lines */
|
||||||
require('./toolBar.less');
|
import './toolBar.less';
|
||||||
const React = require('react');
|
import React, { useState, useEffect } from 'react';
|
||||||
const { useState, useEffect } = React;
|
import _ from 'lodash';
|
||||||
const _ = require('lodash');
|
|
||||||
|
|
||||||
import { Anchored, AnchoredBox, AnchoredTrigger } from '../../../components/Anchored.jsx';
|
import { Anchored, AnchoredBox, AnchoredTrigger } from '@components/Anchored.jsx';
|
||||||
|
|
||||||
const MAX_ZOOM = 300;
|
const MAX_ZOOM = 300;
|
||||||
const MIN_ZOOM = 10;
|
const MIN_ZOOM = 10;
|
||||||
@@ -100,46 +99,54 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
|||||||
return (
|
return (
|
||||||
<div id='preview-toolbar' className={`toolBar ${toolsVisible ? 'visible' : 'hidden'}`} role='toolbar'>
|
<div id='preview-toolbar' className={`toolBar ${toolsVisible ? 'visible' : 'hidden'}`} role='toolbar'>
|
||||||
<div className='toggleButton'>
|
<div className='toggleButton'>
|
||||||
<button title={`${toolsVisible ? 'Hide' : 'Show'} Preview Toolbar`} onClick={()=>{
|
<button data-tooltip-right={`${toolsVisible ? 'Hide' : 'Show'} Preview Toolbar`}
|
||||||
setToolsVisible(!toolsVisible);
|
aria-label={`${toolsVisible ? 'Hide' : 'Show'} Preview Toolbar`}
|
||||||
localStorage.setItem(TOOLBAR_VISIBILITY, !toolsVisible);
|
onClick={()=>{ setToolsVisible(!toolsVisible); localStorage.setItem(TOOLBAR_VISIBILITY, !toolsVisible); }}>
|
||||||
}}><i className='fas fa-glasses' /></button>
|
<i aria-hidden='true' className='fas fa-glasses' />
|
||||||
<button title={`${headerState ? 'Hide' : 'Show'} Header Navigation`} onClick={()=>{setHeaderState(!headerState);}}><i className='fas fa-rectangle-list' /></button>
|
</button>
|
||||||
|
<button data-tooltip-right={`${headerState ? 'Hide' : 'Show'} Header Navigation`}
|
||||||
|
aria-label={`${headerState ? 'Hide' : 'Show'} Header Navigation`}
|
||||||
|
onClick={()=>{setHeaderState(!headerState);}}>
|
||||||
|
<i aria-hidden='true' className='fas fa-rectangle-list' />
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{/*v=====----------------------< Zoom Controls >---------------------=====v*/}
|
{/*v=====----------------------< Zoom Controls >---------------------=====v*/}
|
||||||
<div className='group' role='group' aria-label='Zoom' aria-hidden={!toolsVisible}>
|
<div className='group' role='group' aria-label='Zoom' aria-hidden={!toolsVisible}>
|
||||||
<button
|
<button
|
||||||
id='fill-width'
|
id='fill-width'
|
||||||
className='tool'
|
className='tool'
|
||||||
title='Set zoom to fill preview with one page'
|
data-tooltip-bottom='Set zoom to fill preview with one page'
|
||||||
|
aria-label='Set zoom to fill preview with one page'
|
||||||
onClick={()=>handleZoomButton(displayOptions.zoomLevel + calculateChange('fill'))}
|
onClick={()=>handleZoomButton(displayOptions.zoomLevel + calculateChange('fill'))}
|
||||||
>
|
>
|
||||||
<i className='fac fit-width' />
|
<i aria-hidden='true' className='fac fit-width' />
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
id='zoom-to-fit'
|
id='zoom-to-fit'
|
||||||
className='tool'
|
className='tool'
|
||||||
title='Set zoom to fit entire page in preview'
|
data-tooltip-bottom='Set zoom to fit entire page in preview'
|
||||||
|
aria-label='Set zoom to fit entire page in preview'
|
||||||
onClick={()=>handleZoomButton(displayOptions.zoomLevel + calculateChange('fit'))}
|
onClick={()=>handleZoomButton(displayOptions.zoomLevel + calculateChange('fit'))}
|
||||||
>
|
>
|
||||||
<i className='fac zoom-to-fit' />
|
<i aria-hidden='true' className='fac zoom-to-fit' />
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
id='zoom-out'
|
id='zoom-out'
|
||||||
className='tool'
|
className='tool'
|
||||||
onClick={()=>handleZoomButton(displayOptions.zoomLevel - 20)}
|
onClick={()=>handleZoomButton(displayOptions.zoomLevel - 20)}
|
||||||
disabled={displayOptions.zoomLevel <= MIN_ZOOM}
|
disabled={displayOptions.zoomLevel <= MIN_ZOOM}
|
||||||
title='Zoom Out'
|
data-tooltip-bottom='Zoom Out'
|
||||||
|
aria-label='Zoom Out'
|
||||||
>
|
>
|
||||||
<i className='fas fa-magnifying-glass-minus' />
|
<i aria-hidden='true' className='fas fa-magnifying-glass-minus' />
|
||||||
</button>
|
</button>
|
||||||
<input
|
<input
|
||||||
id='zoom-slider'
|
id='zoom-slider'
|
||||||
className='range-input tool hover-tooltip'
|
className='range-input tool hover-tooltip'
|
||||||
type='range'
|
type='range'
|
||||||
name='zoom'
|
name='zoom'
|
||||||
title='Set Zoom'
|
|
||||||
list='zoomLevels'
|
list='zoomLevels'
|
||||||
|
aria-label='Zoom Amount'
|
||||||
min={MIN_ZOOM}
|
min={MIN_ZOOM}
|
||||||
max={MAX_ZOOM}
|
max={MAX_ZOOM}
|
||||||
step='1'
|
step='1'
|
||||||
@@ -155,9 +162,10 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
|||||||
className='tool'
|
className='tool'
|
||||||
onClick={()=>handleZoomButton(displayOptions.zoomLevel + 20)}
|
onClick={()=>handleZoomButton(displayOptions.zoomLevel + 20)}
|
||||||
disabled={displayOptions.zoomLevel >= MAX_ZOOM}
|
disabled={displayOptions.zoomLevel >= MAX_ZOOM}
|
||||||
title='Zoom In'
|
data-tooltip-bottom='Zoom In'
|
||||||
|
aria-label='Zoom In'
|
||||||
>
|
>
|
||||||
<i className='fas fa-magnifying-glass-plus' />
|
<i aria-hidden='true' className='fas fa-magnifying-glass-plus' />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -167,44 +175,49 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
|||||||
<button role='radio'
|
<button role='radio'
|
||||||
id='single-spread'
|
id='single-spread'
|
||||||
className='tool'
|
className='tool'
|
||||||
title='Single Page'
|
data-tooltip-bottom='Single Page'
|
||||||
|
aria-label='Single Page Spread'
|
||||||
onClick={()=>{handleOptionChange('spread', 'single');}}
|
onClick={()=>{handleOptionChange('spread', 'single');}}
|
||||||
aria-checked={displayOptions.spread === 'single'}
|
aria-checked={displayOptions.spread === 'single'}
|
||||||
><i className='fac single-spread' /></button>
|
><i aria-hidden='true' className='fac single-spread' /></button>
|
||||||
<button role='radio'
|
<button role='radio'
|
||||||
id='facing-spread'
|
id='facing-spread'
|
||||||
className='tool'
|
className='tool'
|
||||||
title='Facing Pages'
|
data-tooltip-bottom='Facing Pages'
|
||||||
|
aria-label='Facing Pages Spread'
|
||||||
onClick={()=>{handleOptionChange('spread', 'facing');}}
|
onClick={()=>{handleOptionChange('spread', 'facing');}}
|
||||||
aria-checked={displayOptions.spread === 'facing'}
|
aria-checked={displayOptions.spread === 'facing'}
|
||||||
><i className='fac facing-spread' /></button>
|
><i aria-hidden='true' className='fac facing-spread' /></button>
|
||||||
<button role='radio'
|
<button role='radio'
|
||||||
id='flow-spread'
|
id='flow-spread'
|
||||||
className='tool'
|
className='tool'
|
||||||
title='Flow Pages'
|
data-tooltip-bottom='Flow Pages'
|
||||||
|
aria-label='Flow Pages Spread'
|
||||||
onClick={()=>{handleOptionChange('spread', 'flow');}}
|
onClick={()=>{handleOptionChange('spread', 'flow');}}
|
||||||
aria-checked={displayOptions.spread === 'flow'}
|
aria-checked={displayOptions.spread === 'flow'}
|
||||||
><i className='fac flow-spread' /></button>
|
><i aria-hidden='true' className='fac flow-spread' /></button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<Anchored>
|
<Anchored>
|
||||||
<AnchoredTrigger id='spread-settings' className='tool' title='Spread options'><i className='fas fa-gear' /></AnchoredTrigger>
|
<AnchoredTrigger id='spread-settings' className='tool' aria-label='Spread options' data-tooltip-bottom='Spread options'>
|
||||||
<AnchoredBox title='Options'>
|
<i aria-hidden='true' className='fas fa-gear' />
|
||||||
|
</AnchoredTrigger>
|
||||||
|
<AnchoredBox>
|
||||||
<h1>Options</h1>
|
<h1>Options</h1>
|
||||||
<label title='Modify the horizontal space between pages.'>
|
<label data-tooltip-left='Modify the horizontal space between pages.'>
|
||||||
Column gap
|
Column gap
|
||||||
<input type='range' min={0} max={200} defaultValue={displayOptions.columnGap || 10} className='range-input' onChange={(evt)=>handleOptionChange('columnGap', evt.target.value)} />
|
<input type='range' min={0} max={200} defaultValue={displayOptions.columnGap || 10} className='range-input' onChange={(evt)=>handleOptionChange('columnGap', evt.target.value)} />
|
||||||
</label>
|
</label>
|
||||||
<label title='Modify the vertical space between rows of pages.'>
|
<label data-tooltip-left='Modify the vertical space between rows of pages.'>
|
||||||
Row gap
|
Row gap
|
||||||
<input type='range' min={0} max={200} defaultValue={displayOptions.rowGap || 10} className='range-input' onChange={(evt)=>handleOptionChange('rowGap', evt.target.value)} />
|
<input type='range' min={0} max={200} defaultValue={displayOptions.rowGap || 10} className='range-input' onChange={(evt)=>handleOptionChange('rowGap', evt.target.value)} />
|
||||||
</label>
|
</label>
|
||||||
<label title='Start 1st page on the right side, such as if you have cover page.'>
|
<label data-tooltip-left='Start 1st page on the right side, such as if you have cover page.'>
|
||||||
Start on right
|
Start on right
|
||||||
<input type='checkbox' checked={displayOptions.startOnRight} onChange={()=>{handleOptionChange('startOnRight', !displayOptions.startOnRight);}}
|
<input type='checkbox' checked={displayOptions.startOnRight} onChange={()=>{handleOptionChange('startOnRight', !displayOptions.startOnRight);}}
|
||||||
title={displayOptions.spread !== 'facing' ? 'Switch to Facing to enable toggle.' : null} />
|
data-tooltip-right={displayOptions.spread !== 'facing' ? 'Switch to Facing to enable toggle.' : null} />
|
||||||
</label>
|
</label>
|
||||||
<label title='Toggle the page shadow on every page.'>
|
<label data-tooltip-left='Toggle the page shadow on every page.'>
|
||||||
Page shadows
|
Page shadows
|
||||||
<input type='checkbox' checked={displayOptions.pageShadows} onChange={()=>{handleOptionChange('pageShadows', !displayOptions.pageShadows);}} />
|
<input type='checkbox' checked={displayOptions.pageShadows} onChange={()=>{handleOptionChange('pageShadows', !displayOptions.pageShadows);}} />
|
||||||
</label>
|
</label>
|
||||||
@@ -218,11 +231,12 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
|||||||
id='previous-page'
|
id='previous-page'
|
||||||
className='previousPage tool'
|
className='previousPage tool'
|
||||||
type='button'
|
type='button'
|
||||||
title='Previous Page(s)'
|
data-tooltip-bottom='Previous Page(s)'
|
||||||
|
aria-label='Previous Page'
|
||||||
onClick={()=>scrollToPage(_.min(visiblePages) - visiblePages.length)}
|
onClick={()=>scrollToPage(_.min(visiblePages) - visiblePages.length)}
|
||||||
disabled={visiblePages.includes(1)}
|
disabled={visiblePages.includes(1)}
|
||||||
>
|
>
|
||||||
<i className='fas fa-arrow-left'></i>
|
<i aria-hidden='true' className='fas fa-arrow-left'></i>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div className='tool'>
|
<div className='tool'>
|
||||||
@@ -231,7 +245,8 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
|||||||
className='text-input'
|
className='text-input'
|
||||||
type='text'
|
type='text'
|
||||||
name='page'
|
name='page'
|
||||||
title='Current page(s) in view'
|
data-tooltip-bottom='Current page(s) in view'
|
||||||
|
aria-label='Current page in view'
|
||||||
inputMode='numeric'
|
inputMode='numeric'
|
||||||
pattern='[0-9]'
|
pattern='[0-9]'
|
||||||
value={pageNum}
|
value={pageNum}
|
||||||
@@ -241,22 +256,23 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
|||||||
onKeyDown={(e)=>e.key == 'Enter' && scrollToPage(pageNum)}
|
onKeyDown={(e)=>e.key == 'Enter' && scrollToPage(pageNum)}
|
||||||
style={{ width: `${pageNum.length}ch` }}
|
style={{ width: `${pageNum.length}ch` }}
|
||||||
/>
|
/>
|
||||||
<span id='page-count' title='Total Page Count'>/ {totalPages}</span>
|
<span id='page-count' aria-label={`${totalPages} Total Pages`} data-tooltip-bottom='Total Page Count'><span aria-hidden='true'>/ {totalPages}</span></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
id='next-page'
|
id='next-page'
|
||||||
className='tool'
|
className='tool'
|
||||||
type='button'
|
type='button'
|
||||||
title='Next Page(s)'
|
data-tooltip-bottom='Next Page(s)'
|
||||||
|
aria-label='Next Page'
|
||||||
onClick={()=>scrollToPage(_.max(visiblePages) + 1)}
|
onClick={()=>scrollToPage(_.max(visiblePages) + 1)}
|
||||||
disabled={visiblePages.includes(totalPages)}
|
disabled={visiblePages.includes(totalPages)}
|
||||||
>
|
>
|
||||||
<i className='fas fa-arrow-right'></i>
|
<i aria-hidden='true' className='fas fa-arrow-right'></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = ToolBar;
|
export default ToolBar;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
@import (less) './client/icons/customIcons.less';
|
@import (less) '../../../icons/customIcons.less';
|
||||||
|
|
||||||
.toolBar {
|
.toolBar {
|
||||||
position : absolute;
|
position : absolute;
|
||||||
@@ -166,7 +166,7 @@
|
|||||||
|
|
||||||
&.hidden {
|
&.hidden {
|
||||||
flex-wrap : nowrap;
|
flex-wrap : nowrap;
|
||||||
width : 92px;
|
width : 50%;
|
||||||
overflow : hidden;
|
overflow : hidden;
|
||||||
background-color : unset;
|
background-color : unset;
|
||||||
opacity : 0.7;
|
opacity : 0.7;
|
||||||
@@ -176,9 +176,7 @@
|
|||||||
transition : all 0.2s ease;
|
transition : all 0.2s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.toggleButton button i {
|
.toggleButton button i { filter : drop-shadow(0 0 2px black) drop-shadow(0 0 1px black); }
|
||||||
filter: drop-shadow(0 0 2px black) drop-shadow(0 0 1px black);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+337
-482
@@ -1,19 +1,43 @@
|
|||||||
/*eslint max-lines: ["warn", {"max": 500, "skipBlankLines": true, "skipComments": true}]*/
|
/*eslint max-lines: ["warn", {"max": 500, "skipBlankLines": true, "skipComments": true}]*/
|
||||||
require('./editor.less');
|
import './editor.less';
|
||||||
const React = require('react');
|
import React, { useState, useRef, useEffect, forwardRef, useImperativeHandle } from 'react';
|
||||||
const createClass = require('create-react-class');
|
import dedent from 'dedent';
|
||||||
const _ = require('lodash');
|
import { EditorView } from '@codemirror/view';
|
||||||
const dedent = require('dedent-tabs').default;
|
|
||||||
import Markdown from '../../../shared/markdown.js';
|
|
||||||
|
|
||||||
const CodeEditor = require('client/components/codeEditor/codeEditor.jsx');
|
import CodeEditor from '@components/codeEditor/codeEditor.jsx';
|
||||||
const SnippetBar = require('./snippetbar/snippetbar.jsx');
|
import SnippetBar from './snippetbar/snippetbar.jsx';
|
||||||
const MetadataEditor = require('./metadataEditor/metadataEditor.jsx');
|
import MetadataEditor from './metadataEditor/metadataEditor.jsx';
|
||||||
|
import SettingsEditor from './settingsEditor/settingsEditor.jsx';
|
||||||
|
|
||||||
const EDITOR_THEME_KEY = 'HB_editor_theme';
|
const EDITOR_THEME_KEY = 'HB_editor_theme';
|
||||||
|
const EDITOR_SETTINGS_KEY = 'HB_edit_settings';
|
||||||
|
|
||||||
const PAGEBREAK_REGEX_V3 = /^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m;
|
import defaultCM5Theme from '@themes/codeMirror/default.js';
|
||||||
const SNIPPETBREAK_REGEX_V3 = /^\\snippet\ .*$/;
|
import darkbrewery from '@themes/codeMirror/darkbrewery.js';
|
||||||
|
import cm5Themes from 'codemirror-5-themes';
|
||||||
|
|
||||||
|
const themes = { default: defaultCM5Theme, ...cm5Themes, darkbrewery };
|
||||||
|
|
||||||
|
const EditorThemes = Object.entries(themes)
|
||||||
|
.filter(([name, value])=>Array.isArray(value) && !name.endsWith('Init') && !name.endsWith('Style'))
|
||||||
|
.map(([name])=>name);
|
||||||
|
|
||||||
|
const themeNames = Object.entries(themes)
|
||||||
|
.filter(([name, value])=>Array.isArray(value) &&
|
||||||
|
!name.endsWith('Init') &&
|
||||||
|
!name.endsWith('Style')
|
||||||
|
)
|
||||||
|
.map(([name])=>name);
|
||||||
|
|
||||||
|
const EditorThemeNameList = [
|
||||||
|
'default',
|
||||||
|
...themeNames
|
||||||
|
.filter((name)=>name !== 'default')
|
||||||
|
.sort((a, b)=>a.localeCompare(b))
|
||||||
|
];
|
||||||
|
|
||||||
|
//const PAGEBREAK_REGEX_V3 = /^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m;
|
||||||
|
//const SNIPPETBREAK_REGEX_V3 = /^\\snippet\ .*$/;
|
||||||
const DEFAULT_STYLE_TEXT = dedent`
|
const DEFAULT_STYLE_TEXT = dedent`
|
||||||
/*=======--- Example CSS styling ---=======*/
|
/*=======--- Example CSS styling ---=======*/
|
||||||
/* Any CSS here will apply to your document! */
|
/* Any CSS here will apply to your document! */
|
||||||
@@ -30,516 +54,347 @@ const DEFAULT_SNIPPET_TEXT = dedent`
|
|||||||
This snippet is accessible in the brew tab, and will be inherited if the brew is used as a theme.
|
This snippet is accessible in the brew tab, and will be inherited if the brew is used as a theme.
|
||||||
`;
|
`;
|
||||||
let isJumping = false;
|
let isJumping = false;
|
||||||
|
let jumpSource = null;
|
||||||
|
|
||||||
const Editor = createClass({
|
const Editor = forwardRef(
|
||||||
displayName : 'Editor',
|
(
|
||||||
getDefaultProps : function() {
|
{
|
||||||
return {
|
brew = {},
|
||||||
brew : {
|
|
||||||
text : '',
|
|
||||||
style : ''
|
|
||||||
},
|
|
||||||
|
|
||||||
onBrewChange : ()=>{},
|
onBrewChange = ()=>{},
|
||||||
reportError : ()=>{},
|
reportError = ()=>{},
|
||||||
|
|
||||||
onCursorPageChange : ()=>{},
|
onCursorPageChange = ()=>{},
|
||||||
onViewPageChange : ()=>{},
|
onViewPageChange = ()=>{},
|
||||||
|
|
||||||
editorTheme : 'default',
|
renderer = 'legacy',
|
||||||
renderer : 'legacy',
|
|
||||||
|
|
||||||
currentEditorCursorPageNum : 1,
|
moveBrew,
|
||||||
currentEditorViewPageNum : 1,
|
moveSource,
|
||||||
currentBrewRendererPageNum : 1,
|
liveScroll,
|
||||||
};
|
|
||||||
},
|
|
||||||
getInitialState : function() {
|
|
||||||
return {
|
|
||||||
editorTheme : this.props.editorTheme,
|
|
||||||
view : 'text', //'text', 'style', 'meta', 'snippet'
|
|
||||||
snippetBarHeight : 26,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
editor : React.createRef(null),
|
setMoveArrows,
|
||||||
codeEditor : React.createRef(null),
|
updateBrew,
|
||||||
|
showEditButtons,
|
||||||
|
themeBundle,
|
||||||
|
userThemes,
|
||||||
|
|
||||||
isText : function() {return this.state.view == 'text';},
|
currentEditorCursorPageNum = 1,
|
||||||
isStyle : function() {return this.state.view == 'style';},
|
currentEditorViewPageNum = 1,
|
||||||
isMeta : function() {return this.state.view == 'meta';},
|
currentBrewRendererPageNum = 1,
|
||||||
isSnip : function() {return this.state.view == 'snippet';},
|
},
|
||||||
|
ref,
|
||||||
componentDidMount : function() {
|
)=>{
|
||||||
|
const [view, setView] = useState('text'); // 'text', 'style', 'meta', 'snippet'
|
||||||
this.highlightCustomMarkdown();
|
const [snippetBarHeight, setSnippetBarHeight] = useState(26);
|
||||||
document.getElementById('BrewRenderer').addEventListener('keydown', this.handleControlKeys);
|
const [isDark, setIsDark] = useState(false);
|
||||||
document.addEventListener('keydown', this.handleControlKeys);
|
const [editorSettings, setEditorSettings] = useState({
|
||||||
|
autoCloseBrackets : true,
|
||||||
this.codeEditor.current.codeMirror.on('cursorActivity', (cm)=>{this.updateCurrentCursorPage(cm.getCursor());});
|
showImagePreviews : true,
|
||||||
this.codeEditor.current.codeMirror.on('scroll', _.throttle(()=>{this.updateCurrentViewPage(this.codeEditor.current.getTopVisibleLine());}, 200));
|
activeLineShading : true,
|
||||||
|
lineNumbers : true,
|
||||||
const editorTheme = window.localStorage.getItem(EDITOR_THEME_KEY);
|
fontSize : 1,
|
||||||
if(editorTheme) {
|
editorTheme : 'default',
|
||||||
this.setState({
|
|
||||||
editorTheme : editorTheme
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const snippetBar = document.querySelector('.editor > .snippetBar');
|
|
||||||
if (!snippetBar) return;
|
|
||||||
|
|
||||||
this.resizeObserver = new ResizeObserver(entries => {
|
|
||||||
const height = document.querySelector('.editor > .snippetBar').offsetHeight;
|
|
||||||
this.setState({ snippetBarHeight: height });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.resizeObserver.observe(snippetBar);
|
const editor = useRef(null);
|
||||||
},
|
const codeEditor = useRef(null);
|
||||||
|
const throttleBrewMove = useRef(null);
|
||||||
|
|
||||||
componentDidUpdate : function(prevProps, prevState, snapshot) {
|
const isText = ()=>isView('text');
|
||||||
|
const isStyle = ()=>isView('style');
|
||||||
|
const isMeta = ()=>isView('meta');
|
||||||
|
const isSnip = ()=>isView('snippet');
|
||||||
|
const isSettings = ()=>isView('settings');
|
||||||
|
|
||||||
this.highlightCustomMarkdown();
|
const isView = (name)=>view === name;
|
||||||
if(prevProps.moveBrew !== this.props.moveBrew)
|
|
||||||
this.brewJump();
|
|
||||||
|
|
||||||
if(prevProps.moveSource !== this.props.moveSource)
|
useEffect(()=>{
|
||||||
this.sourceJump();
|
const brewRenderer = document.getElementById('BrewRenderer');
|
||||||
|
brewRenderer.onload = ()=>brewRenderer.contentDocument?.addEventListener('keydown', handleControlKeys);
|
||||||
|
document.addEventListener('keydown', handleControlKeys);
|
||||||
|
|
||||||
if(this.props.liveScroll) {
|
const localEditorTheme = window.localStorage.getItem(EDITOR_THEME_KEY);
|
||||||
if(prevProps.currentBrewRendererPageNum !== this.props.currentBrewRendererPageNum) {
|
if(localEditorTheme && EditorThemes.includes(localEditorTheme)) {
|
||||||
this.sourceJump(this.props.currentBrewRendererPageNum, false);
|
setEditorSettings({ ...editorSettings, editorTheme: localEditorTheme });
|
||||||
} else if(prevProps.currentEditorViewPageNum !== this.props.currentEditorViewPageNum) {
|
} else setEditorSettings({ ...editorSettings, editorTheme: 'default' });
|
||||||
this.brewJump(this.props.currentEditorViewPageNum, false);
|
const localEditorSettings = window.localStorage.getItem(EDITOR_SETTINGS_KEY);
|
||||||
} else if(prevProps.currentEditorCursorPageNum !== this.props.currentEditorCursorPageNum) {
|
if(localEditorSettings) setEditorSettings(JSON.parse(localEditorSettings));
|
||||||
this.brewJump(this.props.currentEditorCursorPageNum, false);
|
const snippetBar = document.querySelector('.editor > .snippetBar');
|
||||||
}
|
if(!snippetBar) return;
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
componentWillUnmount() {
|
const resizeObserver = new ResizeObserver((entries)=>{
|
||||||
if (this.resizeObserver) this.resizeObserver.disconnect();
|
const height = document.querySelector('.editor > .snippetBar').offsetHeight;
|
||||||
},
|
setSnippetBarHeight(height);
|
||||||
|
|
||||||
handleControlKeys : function(e){
|
|
||||||
if(!(e.ctrlKey && e.metaKey && e.shiftKey)) return;
|
|
||||||
const LEFTARROW_KEY = 37;
|
|
||||||
const RIGHTARROW_KEY = 39;
|
|
||||||
if(e.keyCode == RIGHTARROW_KEY) this.brewJump();
|
|
||||||
if(e.keyCode == LEFTARROW_KEY) this.sourceJump();
|
|
||||||
if(e.keyCode == LEFTARROW_KEY || e.keyCode == RIGHTARROW_KEY) {
|
|
||||||
e.stopPropagation();
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
updateCurrentCursorPage : function(cursor) {
|
|
||||||
const lines = this.props.brew.text.split('\n').slice(1, cursor.line + 1);
|
|
||||||
const pageRegex = this.props.brew.renderer == 'V3' ? PAGEBREAK_REGEX_V3 : /\\page/;
|
|
||||||
const currentPage = lines.reduce((count, line)=>count + (pageRegex.test(line) ? 1 : 0), 1);
|
|
||||||
this.props.onCursorPageChange(currentPage);
|
|
||||||
},
|
|
||||||
|
|
||||||
updateCurrentViewPage : function(topScrollLine) {
|
|
||||||
const lines = this.props.brew.text.split('\n').slice(1, topScrollLine + 1);
|
|
||||||
const pageRegex = this.props.brew.renderer == 'V3' ? PAGEBREAK_REGEX_V3 : /\\page/;
|
|
||||||
const currentPage = lines.reduce((count, line)=>count + (pageRegex.test(line) ? 1 : 0), 1);
|
|
||||||
this.props.onViewPageChange(currentPage);
|
|
||||||
},
|
|
||||||
|
|
||||||
handleInject : function(injectText){
|
|
||||||
this.codeEditor.current?.injectText(injectText, false);
|
|
||||||
},
|
|
||||||
|
|
||||||
handleViewChange : function(newView){
|
|
||||||
this.props.setMoveArrows(newView === 'text');
|
|
||||||
|
|
||||||
this.setState({
|
|
||||||
view : newView
|
|
||||||
}, ()=>{
|
|
||||||
this.codeEditor.current?.codeMirror.focus();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
highlightCustomMarkdown : function(){
|
|
||||||
if(!this.codeEditor.current) return;
|
|
||||||
if((this.state.view === 'text') ||(this.state.view === 'snippet')) {
|
|
||||||
const codeMirror = this.codeEditor.current.codeMirror;
|
|
||||||
|
|
||||||
codeMirror.operation(()=>{ // Batch CodeMirror styling
|
|
||||||
|
|
||||||
const foldLines = [];
|
|
||||||
|
|
||||||
//reset custom text styles
|
|
||||||
const customHighlights = codeMirror.getAllMarks().filter((mark)=>{
|
|
||||||
// Record details of folded sections
|
|
||||||
if(mark.__isFold) {
|
|
||||||
const fold = mark.find();
|
|
||||||
foldLines.push({ from: fold.from?.line, to: fold.to?.line });
|
|
||||||
}
|
|
||||||
return !mark.__isFold;
|
|
||||||
}); //Don't undo code folding
|
|
||||||
|
|
||||||
for (let i=customHighlights.length - 1;i>=0;i--) customHighlights[i].clear();
|
|
||||||
|
|
||||||
let userSnippetCount = 1; // start snippet count from snippet 1
|
|
||||||
let editorPageCount = 1; // start page count from page 1
|
|
||||||
|
|
||||||
const whichSource = this.state.view === 'text' ? this.props.brew.text : this.props.brew.snippets;
|
|
||||||
_.forEach(whichSource?.split('\n'), (line, lineNumber)=>{
|
|
||||||
|
|
||||||
const tabHighlight = this.state.view === 'text' ? 'pageLine' : 'snippetLine';
|
|
||||||
const textOrSnip = this.state.view === 'text';
|
|
||||||
|
|
||||||
//reset custom line styles
|
|
||||||
codeMirror.removeLineClass(lineNumber, 'background', 'pageLine');
|
|
||||||
codeMirror.removeLineClass(lineNumber, 'background', 'snippetLine');
|
|
||||||
codeMirror.removeLineClass(lineNumber, 'text');
|
|
||||||
codeMirror.removeLineClass(lineNumber, 'wrap', 'sourceMoveFlash');
|
|
||||||
|
|
||||||
// Don't process lines inside folded text
|
|
||||||
// If the current lineNumber is inside any folded marks, skip line styling
|
|
||||||
if(foldLines.some((fold)=>lineNumber >= fold.from && lineNumber <= fold.to))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Styling for \page breaks
|
|
||||||
if((this.props.renderer == 'legacy' && line.includes('\\page')) ||
|
|
||||||
(this.props.renderer == 'V3' && line.match(textOrSnip ? PAGEBREAK_REGEX_V3 : SNIPPETBREAK_REGEX_V3))) {
|
|
||||||
|
|
||||||
if((lineNumber > 0) && (textOrSnip)) // Since \page is optional on first line of document,
|
|
||||||
editorPageCount += 1; // don't use it to increment page count; stay at 1
|
|
||||||
else if(this.state.view !== 'text') userSnippetCount += 1;
|
|
||||||
|
|
||||||
// add back the original class 'background' but also add the new class '.pageline'
|
|
||||||
codeMirror.addLineClass(lineNumber, 'background', tabHighlight);
|
|
||||||
const pageCountElement = Object.assign(document.createElement('span'), {
|
|
||||||
className : 'editor-page-count',
|
|
||||||
textContent : textOrSnip ? editorPageCount : userSnippetCount
|
|
||||||
});
|
|
||||||
codeMirror.setBookmark({ line: lineNumber, ch: line.length }, pageCountElement);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// New Codemirror styling for V3 renderer
|
|
||||||
if(this.props.renderer === 'V3') {
|
|
||||||
if(line.match(/^\\column(?:break)?$/)){
|
|
||||||
codeMirror.addLineClass(lineNumber, 'text', 'columnSplit');
|
|
||||||
}
|
|
||||||
|
|
||||||
// definition lists
|
|
||||||
if(line.includes('::')){
|
|
||||||
if(/^:*$/.test(line) == true){ return; };
|
|
||||||
const regex = /^([^\n]*?:?\s?)(::[^\n]*)(?:\n|$)/ymd; // the `d` flag, for match indices, throws an ESLint error.
|
|
||||||
let match;
|
|
||||||
while ((match = regex.exec(line)) != null){
|
|
||||||
codeMirror.markText({ line: lineNumber, ch: match.indices[0][0] }, { line: lineNumber, ch: match.indices[0][1] }, { className: 'dl-highlight' });
|
|
||||||
codeMirror.markText({ line: lineNumber, ch: match.indices[1][0] }, { line: lineNumber, ch: match.indices[1][1] }, { className: 'dt-highlight' });
|
|
||||||
codeMirror.markText({ line: lineNumber, ch: match.indices[2][0] }, { line: lineNumber, ch: match.indices[2][1] }, { className: 'dd-highlight' });
|
|
||||||
const ddIndex = match.indices[2][0];
|
|
||||||
const colons = /::/g;
|
|
||||||
const colonMatches = colons.exec(match[2]);
|
|
||||||
if(colonMatches !== null){
|
|
||||||
codeMirror.markText({ line: lineNumber, ch: colonMatches.index + ddIndex }, { line: lineNumber, ch: colonMatches.index + colonMatches[0].length + ddIndex }, { className: 'dl-colon-highlight' });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Subscript & Superscript
|
|
||||||
if(line.includes('^')) {
|
|
||||||
let startIndex = line.indexOf('^');
|
|
||||||
const superRegex = /\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^/gy;
|
|
||||||
const subRegex = /\^\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^\^/gy;
|
|
||||||
|
|
||||||
while (startIndex >= 0) {
|
|
||||||
superRegex.lastIndex = subRegex.lastIndex = startIndex;
|
|
||||||
let isSuper = false;
|
|
||||||
const match = subRegex.exec(line) || superRegex.exec(line);
|
|
||||||
if(match) {
|
|
||||||
isSuper = !subRegex.lastIndex;
|
|
||||||
codeMirror.markText({ line: lineNumber, ch: match.index }, { line: lineNumber, ch: match.index + match[0].length }, { className: isSuper ? 'superscript' : 'subscript' });
|
|
||||||
}
|
|
||||||
startIndex = line.indexOf('^', Math.max(startIndex + 1, subRegex.lastIndex, superRegex.lastIndex));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Highlight injectors {style}
|
|
||||||
if(line.includes('{') && line.includes('}')){
|
|
||||||
const regex = /(?:^|[^{\n])({(?=((?:[:=](?:"[\w,\-()#%. ]*"|[\w\-()#%.]*)|[^"':={}\s]*)*))\2})/gm;
|
|
||||||
let match;
|
|
||||||
while ((match = regex.exec(line)) != null) {
|
|
||||||
codeMirror.markText({ line: lineNumber, ch: line.indexOf(match[1]) }, { line: lineNumber, ch: line.indexOf(match[1]) + match[1].length }, { className: 'injection' });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Highlight inline spans {{content}}
|
|
||||||
if(line.includes('{{') && line.includes('}}')){
|
|
||||||
const regex = /{{(?=((?:[:=](?:"[\w,\-()#%. ]*"|[\w\-()#%.]*)|[^"':={}\s]*)*))\1 *|}}/g;
|
|
||||||
let match;
|
|
||||||
let blockCount = 0;
|
|
||||||
while ((match = regex.exec(line)) != null) {
|
|
||||||
if(match[0].startsWith('{')) {
|
|
||||||
blockCount += 1;
|
|
||||||
} else {
|
|
||||||
blockCount -= 1;
|
|
||||||
}
|
|
||||||
if(blockCount < 0) {
|
|
||||||
blockCount = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
codeMirror.markText({ line: lineNumber, ch: match.index }, { line: lineNumber, ch: match.index + match[0].length }, { className: 'inline-block' });
|
|
||||||
}
|
|
||||||
} else if(line.trimLeft().startsWith('{{') || line.trimLeft().startsWith('}}')){
|
|
||||||
// Highlight block divs {{\n Content \n}}
|
|
||||||
let endCh = line.length+1;
|
|
||||||
|
|
||||||
const match = line.match(/^ *{{(?=((?:[:=](?:"[\w,\-()#%. ]*"|[\w\-()#%.]*)|[^"':={}\s]*)*))\1 *$|^ *}}$/);
|
|
||||||
if(match)
|
|
||||||
endCh = match.index+match[0].length;
|
|
||||||
codeMirror.markText({ line: lineNumber, ch: 0 }, { line: lineNumber, ch: endCh }, { className: 'block' });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Emojis
|
|
||||||
if(line.match(/:[^\s:]+:/g)) {
|
|
||||||
let startIndex = line.indexOf(':');
|
|
||||||
const emojiRegex = /:[^\s:]+:/gy;
|
|
||||||
|
|
||||||
while (startIndex >= 0) {
|
|
||||||
emojiRegex.lastIndex = startIndex;
|
|
||||||
const match = emojiRegex.exec(line);
|
|
||||||
if(match) {
|
|
||||||
let tokens = Markdown.marked.lexer(match[0]);
|
|
||||||
tokens = tokens[0].tokens.filter((t)=>t.type == 'emoji');
|
|
||||||
if(!tokens.length)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const startPos = { line: lineNumber, ch: match.index };
|
|
||||||
const endPos = { line: lineNumber, ch: match.index + match[0].length };
|
|
||||||
|
|
||||||
// Iterate over conflicting marks and clear them
|
|
||||||
const marks = codeMirror.findMarks(startPos, endPos);
|
|
||||||
marks.forEach(function(marker) {
|
|
||||||
if(!marker.__isFold) marker.clear();
|
|
||||||
});
|
|
||||||
codeMirror.markText(startPos, endPos, { className: 'emoji' });
|
|
||||||
}
|
|
||||||
startIndex = line.indexOf(':', Math.max(startIndex + 1, emojiRegex.lastIndex));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
resizeObserver.observe(snippetBar);
|
||||||
},
|
|
||||||
|
|
||||||
brewJump : function(targetPage=this.props.currentEditorCursorPageNum, smooth=true){
|
return ()=>{
|
||||||
if(!window || !this.isText() || isJumping)
|
if(resizeObserver) resizeObserver.disconnect();
|
||||||
return;
|
|
||||||
|
|
||||||
// Get current brewRenderer scroll position and calculate target position
|
|
||||||
const brewRenderer = window.frames['BrewRenderer'].contentDocument.getElementsByClassName('brewRenderer')[0];
|
|
||||||
const currentPos = brewRenderer.scrollTop;
|
|
||||||
const targetPos = window.frames['BrewRenderer'].contentDocument.getElementById(`p${targetPage}`).getBoundingClientRect().top;
|
|
||||||
|
|
||||||
let scrollingTimeout;
|
|
||||||
const checkIfScrollComplete = ()=>{ // Prevent interrupting a scroll in progress if user clicks multiple times
|
|
||||||
clearTimeout(scrollingTimeout); // Reset the timer every time a scroll event occurs
|
|
||||||
scrollingTimeout = setTimeout(()=>{
|
|
||||||
isJumping = false;
|
|
||||||
brewRenderer.removeEventListener('scroll', checkIfScrollComplete);
|
|
||||||
}, 150); // If 150 ms pass without a brewRenderer scroll event, assume scrolling is done
|
|
||||||
};
|
|
||||||
|
|
||||||
isJumping = true;
|
|
||||||
checkIfScrollComplete();
|
|
||||||
brewRenderer.addEventListener('scroll', checkIfScrollComplete);
|
|
||||||
|
|
||||||
if(smooth) {
|
|
||||||
const bouncePos = targetPos >= 0 ? -30 : 30; //Do a little bounce before scrolling
|
|
||||||
const bounceDelay = 100;
|
|
||||||
const scrollDelay = 500;
|
|
||||||
|
|
||||||
if(!this.throttleBrewMove) {
|
|
||||||
this.throttleBrewMove = _.throttle((currentPos, bouncePos, targetPos)=>{
|
|
||||||
brewRenderer.scrollTo({ top: currentPos + bouncePos, behavior: 'smooth' });
|
|
||||||
setTimeout(()=>{
|
|
||||||
brewRenderer.scrollTo({ top: currentPos + targetPos, behavior: 'smooth', block: 'start' });
|
|
||||||
}, bounceDelay);
|
|
||||||
}, scrollDelay, { leading: true, trailing: false });
|
|
||||||
};
|
};
|
||||||
this.throttleBrewMove(currentPos, bouncePos, targetPos);
|
}, []);
|
||||||
} else {
|
|
||||||
brewRenderer.scrollTo({ top: currentPos + targetPos, behavior: 'instant', block: 'start' });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
sourceJump : function(targetPage=this.props.currentBrewRendererPageNum, smooth=true){
|
useEffect(()=>{ if(moveBrew) brewJump(); }, [moveBrew]);
|
||||||
if(!this.isText() || isJumping)
|
useEffect(()=>{ if(moveSource) sourceJump(); }, [moveSource]);
|
||||||
return;
|
useEffect(()=>{ if(liveScroll) sourceJump(currentBrewRendererPageNum, false); }, [currentBrewRendererPageNum, liveScroll]);
|
||||||
|
useEffect(()=>{ if(liveScroll) brewJump(currentEditorViewPageNum, false); }, [currentEditorViewPageNum, liveScroll]);
|
||||||
|
useEffect(()=>{ if(liveScroll) brewJump(currentEditorCursorPageNum, false); }, [currentEditorCursorPageNum, liveScroll]);
|
||||||
|
|
||||||
const textSplit = this.props.renderer == 'V3' ? PAGEBREAK_REGEX_V3 : /\\page/;
|
const handleFormatCode = ()=>{
|
||||||
const textString = this.props.brew.text.split(textSplit).slice(0, targetPage-1).join(textSplit);
|
codeEditor.current?.formatCode();
|
||||||
const targetLine = textString.match('\n') ? textString.split('\n').length - 1 : -1;
|
|
||||||
|
|
||||||
let currentY = this.codeEditor.current.codeMirror.getScrollInfo().top;
|
|
||||||
let targetY = this.codeEditor.current.codeMirror.heightAtLine(targetLine, 'local', true);
|
|
||||||
|
|
||||||
let scrollingTimeout;
|
|
||||||
const checkIfScrollComplete = ()=>{ // Prevent interrupting a scroll in progress if user clicks multiple times
|
|
||||||
clearTimeout(scrollingTimeout); // Reset the timer every time a scroll event occurs
|
|
||||||
scrollingTimeout = setTimeout(()=>{
|
|
||||||
isJumping = false;
|
|
||||||
this.codeEditor.current.codeMirror.off('scroll', checkIfScrollComplete);
|
|
||||||
}, 150); // If 150 ms pass without a scroll event, assume scrolling is done
|
|
||||||
};
|
};
|
||||||
|
|
||||||
isJumping = true;
|
const handleControlKeys = (e)=>{
|
||||||
checkIfScrollComplete();
|
if(!(e.ctrlKey && e.metaKey && e.shiftKey)) return;
|
||||||
this.codeEditor.current.codeMirror.on('scroll', checkIfScrollComplete);
|
const LEFTARROW_KEY = 37;
|
||||||
|
const RIGHTARROW_KEY = 39;
|
||||||
|
if(e.keyCode == RIGHTARROW_KEY) brewJump();
|
||||||
|
if(e.keyCode == LEFTARROW_KEY) sourceJump();
|
||||||
|
if(e.keyCode == LEFTARROW_KEY || e.keyCode == RIGHTARROW_KEY) {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if(smooth) {
|
const updateCurrentCursorPage = (pageNumber)=>{
|
||||||
//Scroll 1/10 of the way every 10ms until 1px off.
|
onCursorPageChange(pageNumber);
|
||||||
const incrementalScroll = setInterval(()=>{
|
};
|
||||||
currentY += (targetY - currentY) / 10;
|
|
||||||
this.codeEditor.current.codeMirror.scrollTo(null, currentY);
|
|
||||||
|
|
||||||
// Update target: target height is not accurate until within +-10 lines of the visible window
|
const updateCurrentViewPage = (pageNumber)=>{
|
||||||
if(Math.abs(targetY - currentY > 100))
|
onViewPageChange(pageNumber);
|
||||||
targetY = this.codeEditor.current.codeMirror.heightAtLine(targetLine, 'local', true);
|
};
|
||||||
|
|
||||||
// End when close enough
|
const handleInject = (injectText)=>{
|
||||||
if(Math.abs(targetY - currentY) < 1) {
|
codeEditor.current?.injectText(injectText);
|
||||||
this.codeEditor.current.codeMirror.scrollTo(null, targetY); // Scroll any remaining difference
|
};
|
||||||
this.codeEditor.current.setCursorPosition({ line: targetLine + 1, ch: 0 });
|
|
||||||
this.codeEditor.current.codeMirror.addLineClass(targetLine + 1, 'wrap', 'sourceMoveFlash');
|
const handleViewChange = (newView)=>{
|
||||||
clearInterval(incrementalScroll);
|
setMoveArrows(newView === 'text');
|
||||||
|
setView(newView);
|
||||||
|
};
|
||||||
|
useEffect(()=>{
|
||||||
|
codeEditor.current?.focus();
|
||||||
|
}, [view]);
|
||||||
|
|
||||||
|
const brewJump = (targetPage = currentEditorCursorPageNum, smooth = true)=>{
|
||||||
|
if(!window || !isText() || isJumping || jumpSource === 'source') return;
|
||||||
|
|
||||||
|
const brewRenderer =
|
||||||
|
window.frames['BrewRenderer'].contentDocument.getElementsByClassName('brewRenderer')[0];
|
||||||
|
|
||||||
|
const currentPos = brewRenderer.scrollTop;
|
||||||
|
|
||||||
|
const targetPos = window.frames['BrewRenderer'].contentDocument
|
||||||
|
.getElementById(`p${targetPage}`)
|
||||||
|
.getBoundingClientRect().top;
|
||||||
|
|
||||||
|
let scrollingTimeout;
|
||||||
|
|
||||||
|
const checkIfScrollComplete = ()=>{// Prevent interrupting a scroll in progress if user clicks multiple times
|
||||||
|
clearTimeout(scrollingTimeout);// Reset the timer every time a scroll event occurs
|
||||||
|
|
||||||
|
scrollingTimeout = setTimeout(()=>{
|
||||||
|
isJumping = false;
|
||||||
|
jumpSource = null;
|
||||||
|
|
||||||
|
brewRenderer.removeEventListener('scroll', checkIfScrollComplete);
|
||||||
|
}, 150);// If 150 ms pass without a brewRenderer scroll event, assume scrolling is done
|
||||||
|
};
|
||||||
|
|
||||||
|
isJumping = true;
|
||||||
|
jumpSource = 'brew';
|
||||||
|
|
||||||
|
checkIfScrollComplete();
|
||||||
|
brewRenderer.addEventListener('scroll', checkIfScrollComplete);
|
||||||
|
|
||||||
|
if(smooth) {
|
||||||
|
const bouncePos = targetPos >= 0 ? -30 : 30; //Do a little bounce before scrolling
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
|
if(now - throttleBrewMove.current >= 500) {
|
||||||
|
throttleBrewMove.current = now;
|
||||||
|
|
||||||
|
brewRenderer.scrollTo({ top: currentPos + bouncePos, behavior: 'smooth' });
|
||||||
|
|
||||||
|
setTimeout(()=>{
|
||||||
|
brewRenderer.scrollTo({ top: currentPos + targetPos, behavior: 'smooth', block: 'start' });
|
||||||
|
}, 100);
|
||||||
}
|
}
|
||||||
}, 10);
|
} else {
|
||||||
} else {
|
brewRenderer.scrollTo({ top : currentPos + targetPos, behavior : 'instant', block : 'start',
|
||||||
this.codeEditor.current.codeMirror.scrollTo(null, targetY); // Scroll any remaining difference
|
});
|
||||||
this.codeEditor.current.setCursorPosition({ line: targetLine + 1, ch: 0 });
|
}
|
||||||
this.codeEditor.current.codeMirror.addLineClass(targetLine + 1, 'wrap', 'sourceMoveFlash');
|
};
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
//Called when there are changes to the editor's dimensions
|
const sourceJump = (targetPage = currentBrewRendererPageNum, smooth = true)=>{
|
||||||
update : function(){},
|
if(!isText() || isJumping || jumpSource === 'brew') return;
|
||||||
|
|
||||||
updateEditorTheme : function(newTheme){
|
if(!codeEditor.current) return;
|
||||||
window.localStorage.setItem(EDITOR_THEME_KEY, newTheme);
|
jumpSource = 'source';
|
||||||
this.setState({
|
|
||||||
editorTheme : newTheme
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
//Called by CodeEditor after document switch, so Snippetbar can refresh UndoHistory
|
codeEditor.current.scrollToPage(targetPage);
|
||||||
rerenderParent : function (){
|
setTimeout(()=>{
|
||||||
this.forceUpdate();
|
jumpSource = null;
|
||||||
},
|
}, 200);
|
||||||
|
};
|
||||||
|
|
||||||
renderEditor : function(){
|
const updateEditorTheme = (newTheme)=>{
|
||||||
if(this.isText()){
|
window.localStorage.setItem(EDITOR_THEME_KEY, newTheme);
|
||||||
return <>
|
setEditorSettings({ ...editorSettings, editorTheme: newTheme });
|
||||||
<CodeEditor key='codeEditor'
|
};
|
||||||
ref={this.codeEditor}
|
|
||||||
language='gfm'
|
|
||||||
view={this.state.view}
|
|
||||||
value={this.props.brew.text}
|
|
||||||
onChange={this.props.onBrewChange('text')}
|
|
||||||
editorTheme={this.state.editorTheme}
|
|
||||||
rerenderParent={this.rerenderParent}
|
|
||||||
style={{ height: `calc(100% - ${this.state.snippetBarHeight}px)` }} />
|
|
||||||
</>;
|
|
||||||
}
|
|
||||||
if(this.isStyle()){
|
|
||||||
return <>
|
|
||||||
<CodeEditor key='codeEditor'
|
|
||||||
ref={this.codeEditor}
|
|
||||||
language='css'
|
|
||||||
view={this.state.view}
|
|
||||||
value={this.props.brew.style ?? DEFAULT_STYLE_TEXT}
|
|
||||||
onChange={this.props.onBrewChange('style')}
|
|
||||||
enableFolding={true}
|
|
||||||
editorTheme={this.state.editorTheme}
|
|
||||||
rerenderParent={this.rerenderParent}
|
|
||||||
style={{ height: `calc(100% - ${this.state.snippetBarHeight}px)` }} />
|
|
||||||
</>;
|
|
||||||
}
|
|
||||||
if(this.isMeta()){
|
|
||||||
return <>
|
|
||||||
<CodeEditor key='codeEditor'
|
|
||||||
view={this.state.view}
|
|
||||||
style={{ display: 'none' }}
|
|
||||||
rerenderParent={this.rerenderParent} />
|
|
||||||
<MetadataEditor
|
|
||||||
metadata={this.props.brew}
|
|
||||||
themeBundle={this.props.themeBundle}
|
|
||||||
onChange={this.props.onBrewChange('metadata')}
|
|
||||||
reportError={this.props.reportError}
|
|
||||||
userThemes={this.props.userThemes}/>
|
|
||||||
</>;
|
|
||||||
}
|
|
||||||
if(this.isSnip()){
|
|
||||||
if(!this.props.brew.snippets) { this.props.brew.snippets = DEFAULT_SNIPPET_TEXT; }
|
|
||||||
return <>
|
|
||||||
<CodeEditor key='codeEditor'
|
|
||||||
ref={this.codeEditor}
|
|
||||||
language='gfm'
|
|
||||||
view={this.state.view}
|
|
||||||
value={this.props.brew.snippets}
|
|
||||||
onChange={this.props.onBrewChange('snippets')}
|
|
||||||
enableFolding={true}
|
|
||||||
editorTheme={this.state.editorTheme}
|
|
||||||
rerenderParent={this.rerenderParent}
|
|
||||||
style={{ height: `calc(100% -${this.state.snippetBarHeight}px)` }} />
|
|
||||||
</>;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
redo : function(){
|
const updateEditorSettings = (newEditorSettings)=>{
|
||||||
return this.codeEditor.current?.redo();
|
window.localStorage.setItem(EDITOR_SETTINGS_KEY, JSON.stringify(newEditorSettings));
|
||||||
},
|
setEditorSettings(newEditorSettings);
|
||||||
|
};
|
||||||
|
|
||||||
historySize : function(){
|
const renderEditor = ()=>{
|
||||||
return this.codeEditor.current?.historySize();
|
if(isText()) {
|
||||||
},
|
return (
|
||||||
|
<>
|
||||||
|
<CodeEditor
|
||||||
|
key='codeEditor'
|
||||||
|
ref={codeEditor}
|
||||||
|
language='gfm'
|
||||||
|
tab='brewText'
|
||||||
|
view={view}
|
||||||
|
value={brew.text}
|
||||||
|
onChange={onBrewChange('text')}
|
||||||
|
onCursorChange={(page)=>updateCurrentCursorPage(page)}
|
||||||
|
onViewChange={(page)=>updateCurrentViewPage(page)}
|
||||||
|
editorTheme={editorSettings.editorTheme}
|
||||||
|
onThemeChange={setIsDark}
|
||||||
|
renderer={brew.renderer}
|
||||||
|
style={{ height: `calc(100% - ${snippetBarHeight}px)` }}
|
||||||
|
settings={editorSettings}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if(isStyle()) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<CodeEditor
|
||||||
|
key='codeEditor'
|
||||||
|
ref={codeEditor}
|
||||||
|
language='css'
|
||||||
|
tab='brewStyles'
|
||||||
|
view={view}
|
||||||
|
value={brew.style ?? DEFAULT_STYLE_TEXT}
|
||||||
|
onChange={onBrewChange('style')}
|
||||||
|
editorTheme={editorSettings.editorTheme}
|
||||||
|
onThemeChange={setIsDark}
|
||||||
|
renderer={brew.renderer}
|
||||||
|
style={{ height: `calc(100% - ${snippetBarHeight}px)` }}
|
||||||
|
settings={editorSettings}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if(isSnip()) {
|
||||||
|
if(!brew.snippets) {
|
||||||
|
brew.snippets = DEFAULT_SNIPPET_TEXT;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<CodeEditor
|
||||||
|
key='codeEditor'
|
||||||
|
ref={codeEditor}
|
||||||
|
language='gfm'
|
||||||
|
tab='brewSnippets'
|
||||||
|
view={view}
|
||||||
|
value={brew.snippets}
|
||||||
|
onChange={onBrewChange('snippets')}
|
||||||
|
enableFolding={true}
|
||||||
|
editorTheme={editorSettings.editorTheme}
|
||||||
|
onThemeChange={setIsDark}
|
||||||
|
renderer={brew.renderer}
|
||||||
|
style={{ height: `calc(100% - 25px)` }}
|
||||||
|
settings={editorSettings}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if(isMeta()) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<CodeEditor key='codeEditor' tab='brewMetadata' editorTheme={editorSettings.editorTheme} onThemeChange={setIsDark} view={view} style={{ display: 'none' }} settings={editorSettings} />
|
||||||
|
<MetadataEditor
|
||||||
|
metadata={brew}
|
||||||
|
themeBundle={themeBundle}
|
||||||
|
onChange={onBrewChange('metadata')}
|
||||||
|
reportError={reportError}
|
||||||
|
userThemes={userThemes}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if(isSettings()){
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<CodeEditor
|
||||||
|
key='codeEditor'
|
||||||
|
tab='brewSettings' //necessary or the brew object loses its contents, culprit possibly on the tab dependent useEffect in codeEditor.jsx
|
||||||
|
view={view}
|
||||||
|
style={{ display: 'none' }}
|
||||||
|
editorTheme={editorSettings.editorTheme}
|
||||||
|
onThemeChange={setIsDark}
|
||||||
|
settings={editorSettings}
|
||||||
|
/>
|
||||||
|
<SettingsEditor
|
||||||
|
settings={editorSettings}
|
||||||
|
EditorThemeNameList={EditorThemeNameList}
|
||||||
|
updateSettings={updateEditorSettings}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
undo : function(){
|
const redo = ()=>codeEditor.current?.redo();
|
||||||
return this.codeEditor.current?.undo();
|
const historySize = ()=>codeEditor.current?.historySize();
|
||||||
},
|
const undo = ()=>codeEditor.current?.undo();
|
||||||
|
const foldCode = ()=>codeEditor.current?.foldAll();
|
||||||
|
const unfoldCode = ()=>codeEditor.current?.unfoldAll();
|
||||||
|
|
||||||
foldCode : function(){
|
//Called when there are changes to the editor's dimensions
|
||||||
return this.codeEditor.current?.foldAllCode();
|
const update = ()=>{};
|
||||||
},
|
|
||||||
|
|
||||||
unfoldCode : function(){
|
useImperativeHandle(ref, ()=>({
|
||||||
return this.codeEditor.current?.unfoldAllCode();
|
update,
|
||||||
},
|
undo,
|
||||||
|
redo,
|
||||||
render : function(){
|
foldCode,
|
||||||
|
unfoldCode,
|
||||||
|
historySize,
|
||||||
|
}));
|
||||||
return (
|
return (
|
||||||
<div className='editor' ref={this.editor}>
|
<div className={`editor${isDark ? ' darkMode' : ''}`} ref={editor}>
|
||||||
<SnippetBar
|
<SnippetBar
|
||||||
brew={this.props.brew}
|
brew={brew}
|
||||||
view={this.state.view}
|
view={view}
|
||||||
onViewChange={this.handleViewChange}
|
onViewChange={handleViewChange}
|
||||||
onInject={this.handleInject}
|
onInject={handleInject}
|
||||||
showEditButtons={this.props.showEditButtons}
|
showEditButtons={showEditButtons}
|
||||||
renderer={this.props.renderer}
|
renderer={renderer}
|
||||||
theme={this.props.brew.theme}
|
theme={brew.theme}
|
||||||
undo={this.undo}
|
undo={undo}
|
||||||
redo={this.redo}
|
redo={redo}
|
||||||
foldCode={this.foldCode}
|
foldCode={foldCode}
|
||||||
unfoldCode={this.unfoldCode}
|
unfoldCode={unfoldCode}
|
||||||
historySize={this.historySize()}
|
formatCode={isStyle() ? handleFormatCode : null}
|
||||||
currentEditorTheme={this.state.editorTheme}
|
historySize={historySize()}
|
||||||
updateEditorTheme={this.updateEditorTheme}
|
currentEditorTheme={editorSettings.editorTheme}
|
||||||
themeBundle={this.props.themeBundle}
|
updateEditorTheme={updateEditorTheme}
|
||||||
cursorPos={this.codeEditor.current?.getCursorPosition() || {}}
|
themeBundle={themeBundle}
|
||||||
updateBrew={this.props.updateBrew}
|
cursorPos={codeEditor.current?.getCursorPosition() || {}}
|
||||||
|
updateBrew={updateBrew}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{this.renderEditor()}
|
{renderEditor()}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
module.exports = Editor;
|
export default Editor;
|
||||||
@@ -1,87 +1,11 @@
|
|||||||
@import 'themes/codeMirror/customEditorStyles.less';
|
@import '@sharedStyles/core.less';
|
||||||
.editor {
|
|
||||||
position : relative;
|
:where(.editor) {
|
||||||
width : 100%;
|
position : relative;
|
||||||
height : 100%;
|
width : 100%;
|
||||||
container : editor / inline-size;
|
height : 100%;
|
||||||
.codeEditor {
|
container : editor / inline-size;
|
||||||
height : calc(100% - 25px);
|
background : white;
|
||||||
.CodeMirror { height : 100%; }
|
|
||||||
.pageLine, .snippetLine {
|
|
||||||
background : #33333328;
|
|
||||||
border-top : #333399 solid 1px;
|
|
||||||
}
|
|
||||||
.editor-page-count {
|
|
||||||
float : right;
|
|
||||||
color : grey;
|
|
||||||
}
|
|
||||||
.editor-snippet-count {
|
|
||||||
float : right;
|
|
||||||
color : grey;
|
|
||||||
}
|
|
||||||
.columnSplit {
|
|
||||||
font-style : italic;
|
|
||||||
color : grey;
|
|
||||||
background-color : fade(#229999, 15%);
|
|
||||||
border-bottom : #229999 solid 1px;
|
|
||||||
}
|
|
||||||
.define {
|
|
||||||
&:not(.term):not(.definition) {
|
|
||||||
font-weight : bold;
|
|
||||||
color : #949494;
|
|
||||||
background : #E5E5E5;
|
|
||||||
border-radius : 3px;
|
|
||||||
}
|
|
||||||
&.term { color : rgb(96, 117, 143); }
|
|
||||||
&.definition { color : rgb(97, 57, 178); }
|
|
||||||
}
|
|
||||||
.block:not(.cm-comment) {
|
|
||||||
font-weight : bold;
|
|
||||||
color : purple;
|
|
||||||
//font-style: italic;
|
|
||||||
}
|
|
||||||
.inline-block:not(.cm-comment) {
|
|
||||||
font-weight : bold;
|
|
||||||
color : red;
|
|
||||||
//font-style: italic;
|
|
||||||
}
|
|
||||||
.injection:not(.cm-comment) {
|
|
||||||
font-weight : bold;
|
|
||||||
color : green;
|
|
||||||
}
|
|
||||||
.emoji:not(.cm-comment) {
|
|
||||||
padding-bottom : 1px;
|
|
||||||
margin-left : 2px;
|
|
||||||
font-weight : bold;
|
|
||||||
color : #360034;
|
|
||||||
outline : solid 2px #FF96FC;
|
|
||||||
outline-offset : -2px;
|
|
||||||
background : #FFC8FF;
|
|
||||||
border-radius : 6px;
|
|
||||||
}
|
|
||||||
.superscript:not(.cm-comment) {
|
|
||||||
font-size : 0.9em;
|
|
||||||
font-weight : bold;
|
|
||||||
vertical-align : super;
|
|
||||||
color : goldenrod;
|
|
||||||
}
|
|
||||||
.subscript:not(.cm-comment) {
|
|
||||||
font-size : 0.9em;
|
|
||||||
font-weight : bold;
|
|
||||||
vertical-align : sub;
|
|
||||||
color : rgb(123, 123, 15);
|
|
||||||
}
|
|
||||||
.dl-highlight {
|
|
||||||
&.dl-colon-highlight {
|
|
||||||
font-weight : bold;
|
|
||||||
color : #949494;
|
|
||||||
background : #E5E5E5;
|
|
||||||
border-radius : 3px;
|
|
||||||
}
|
|
||||||
&.dt-highlight { color : rgb(96, 117, 143); }
|
|
||||||
&.dd-highlight { color : rgb(97, 57, 178); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.brewJump {
|
.brewJump {
|
||||||
position : absolute;
|
position : absolute;
|
||||||
|
|||||||
@@ -1,19 +1,16 @@
|
|||||||
/* eslint-disable max-lines */
|
/* eslint-disable max-lines */
|
||||||
require('./metadataEditor.less');
|
import '../uiEditor.less';
|
||||||
const React = require('react');
|
import React, { useState } from 'react';
|
||||||
const createClass = require('create-react-class');
|
import _ from 'lodash';
|
||||||
const _ = require('lodash');
|
|
||||||
import request from '../../utils/request-middleware.js';
|
import request from '../../utils/request-middleware.js';
|
||||||
const Combobox = require('client/components/combobox.jsx');
|
import Themes from '@themes/themes.json';
|
||||||
const TagInput = require('../tagInput/tagInput.jsx');
|
import validations from './validations.js';
|
||||||
|
|
||||||
|
import Combobox from '@components/combobox.jsx';
|
||||||
|
import TagInput from '../tagInput/tagInput.jsx';
|
||||||
|
|
||||||
const Themes = require('themes/themes.json');
|
import homebreweryThumbnail from '../../thumbnail.png';
|
||||||
const validations = require('./validations.js');
|
|
||||||
|
|
||||||
const SYSTEMS = ['5e', '4e', '3.5e', 'Pathfinder'];
|
|
||||||
|
|
||||||
const homebreweryThumbnail = require('../../thumbnail.png');
|
|
||||||
|
|
||||||
const callIfExists = (val, fn, ...args)=>{
|
const callIfExists = (val, fn, ...args)=>{
|
||||||
if(val[fn]) {
|
if(val[fn]) {
|
||||||
@@ -21,48 +18,28 @@ const callIfExists = (val, fn, ...args)=>{
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const MetadataEditor = createClass({
|
const MetadataEditor = ({
|
||||||
displayName : 'MetadataEditor',
|
metadata = {
|
||||||
getDefaultProps : function() {
|
shareId : null,
|
||||||
return {
|
editId : null,
|
||||||
metadata : {
|
title : '',
|
||||||
editId : null,
|
description : '',
|
||||||
shareId : null,
|
tags : [],
|
||||||
title : '',
|
lang : 'en',
|
||||||
description : '',
|
renderer : 'legacy',
|
||||||
thumbnail : '',
|
authors : [],
|
||||||
tags : [],
|
published : false,
|
||||||
published : false,
|
thumbnail : '',
|
||||||
authors : [],
|
theme : '5ePHB',
|
||||||
systems : [],
|
|
||||||
renderer : 'legacy',
|
|
||||||
theme : '5ePHB',
|
|
||||||
lang : 'en'
|
|
||||||
},
|
|
||||||
|
|
||||||
onChange : ()=>{},
|
|
||||||
reportError : ()=>{}
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
|
onChange = ()=>{},
|
||||||
|
reportError = ()=>{},
|
||||||
|
userThemes = {},
|
||||||
|
themeBundle = {}
|
||||||
|
})=>{
|
||||||
|
const [showThumbnail, setShowThumbnail] = useState(true);
|
||||||
|
|
||||||
getInitialState : function(){
|
const handleFieldChange = (name, e)=>{
|
||||||
return {
|
|
||||||
showThumbnail : true
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
toggleThumbnailDisplay : function(){
|
|
||||||
this.setState({
|
|
||||||
showThumbnail : !this.state.showThumbnail
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
renderThumbnail : function(){
|
|
||||||
if(!this.state.showThumbnail) return;
|
|
||||||
return <img className='thumbnail-preview' src={this.props.metadata.thumbnail || homebreweryThumbnail}></img>;
|
|
||||||
},
|
|
||||||
|
|
||||||
handleFieldChange : function(name, e){
|
|
||||||
// load validation rules, and check input value against them
|
// load validation rules, and check input value against them
|
||||||
const inputRules = validations[name] ?? [];
|
const inputRules = validations[name] ?? [];
|
||||||
const validationErr = inputRules.map((rule)=>rule(e.target.value)).filter(Boolean);
|
const validationErr = inputRules.map((rule)=>rule(e.target.value)).filter(Boolean);
|
||||||
@@ -75,8 +52,8 @@ const MetadataEditor = createClass({
|
|||||||
// if no validation rules, save to props
|
// if no validation rules, save to props
|
||||||
if(validationErr.length === 0){
|
if(validationErr.length === 0){
|
||||||
callIfExists(e.target, 'setCustomValidity', '');
|
callIfExists(e.target, 'setCustomValidity', '');
|
||||||
this.props.onChange({
|
onChange({
|
||||||
...this.props.metadata,
|
...metadata,
|
||||||
[name] : e.target.value
|
[name] : e.target.value
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
@@ -86,58 +63,40 @@ const MetadataEditor = createClass({
|
|||||||
return `- ${err}`;
|
return `- ${err}`;
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
|
|
||||||
|
|
||||||
debouncedReportValidity(e.target, errMessage);
|
debouncedReportValidity(e.target, errMessage);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
const handleRenderer = (renderer, e)=>{
|
||||||
handleSystem : function(system, e){
|
|
||||||
if(e.target.checked){
|
if(e.target.checked){
|
||||||
this.props.metadata.systems.push(system);
|
metadata.renderer = renderer;
|
||||||
} else {
|
|
||||||
this.props.metadata.systems = _.without(this.props.metadata.systems, system);
|
|
||||||
}
|
|
||||||
this.props.onChange(this.props.metadata);
|
|
||||||
},
|
|
||||||
|
|
||||||
handleRenderer : function(renderer, e){
|
|
||||||
if(e.target.checked){
|
|
||||||
this.props.metadata.renderer = renderer;
|
|
||||||
if(renderer == 'legacy')
|
if(renderer == 'legacy')
|
||||||
this.props.metadata.theme = '5ePHB';
|
metadata.theme = '5ePHB';
|
||||||
}
|
}
|
||||||
this.props.onChange(this.props.metadata, 'renderer');
|
onChange(metadata, 'renderer');
|
||||||
},
|
};
|
||||||
|
const handlePublish = (val)=>{
|
||||||
handlePublish : function(val){
|
onChange({
|
||||||
this.props.onChange({
|
...metadata,
|
||||||
...this.props.metadata,
|
|
||||||
published : val
|
published : val
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
const handleTheme = (theme)=>{
|
||||||
handleTheme : function(theme){
|
metadata.renderer = theme.renderer;
|
||||||
this.props.metadata.renderer = theme.renderer;
|
metadata.theme = theme.path;
|
||||||
this.props.metadata.theme = theme.path;
|
onChange(metadata, 'theme');
|
||||||
|
};
|
||||||
this.props.onChange(this.props.metadata, 'theme');
|
const handleThemeWritein = (e)=>{
|
||||||
},
|
|
||||||
|
|
||||||
handleThemeWritein : function(e) {
|
|
||||||
const shareId = e.target.value.split('/').pop(); //Extract just the ID if a URL was pasted in
|
const shareId = e.target.value.split('/').pop(); //Extract just the ID if a URL was pasted in
|
||||||
this.props.metadata.theme = shareId;
|
metadata.theme = shareId;
|
||||||
|
onChange(metadata, 'theme');
|
||||||
this.props.onChange(this.props.metadata, 'theme');
|
};
|
||||||
},
|
const handleLanguage = (languageCode)=>{
|
||||||
|
metadata.lang = languageCode;
|
||||||
handleLanguage : function(languageCode){
|
onChange(metadata);
|
||||||
this.props.metadata.lang = languageCode;
|
};
|
||||||
this.props.onChange(this.props.metadata);
|
const handleDelete = ()=>{
|
||||||
},
|
if(metadata.authors && metadata.authors.length <= 1){
|
||||||
|
|
||||||
handleDelete : function(){
|
|
||||||
if(this.props.metadata.authors && this.props.metadata.authors.length <= 1){
|
|
||||||
if(!confirm('Are you sure you want to delete this brew? Because you are the only owner of this brew, the document will be deleted permanently.')) return;
|
if(!confirm('Are you sure you want to delete this brew? Because you are the only owner of this brew, the document will be deleted permanently.')) return;
|
||||||
if(!confirm('Are you REALLY sure? You will not be able to recover the document.')) return;
|
if(!confirm('Are you REALLY sure? You will not be able to recover the document.')) return;
|
||||||
} else {
|
} else {
|
||||||
@@ -145,73 +104,91 @@ const MetadataEditor = createClass({
|
|||||||
if(!confirm('Are you REALLY sure? You will lose editor access to this document.')) return;
|
if(!confirm('Are you REALLY sure? You will lose editor access to this document.')) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
request.delete(`/api/${this.props.metadata.googleId ?? ''}${this.props.metadata.editId}`)
|
request.delete(`/api/${metadata.googleId ?? ''}${metadata.editId}`)
|
||||||
.send()
|
.send()
|
||||||
.end((err, res)=>{
|
.end((err, res)=>{
|
||||||
if(err) {
|
if(err) {
|
||||||
this.props.reportError(err);
|
reportError(err);
|
||||||
} else {
|
} else {
|
||||||
window.location.href = '/';
|
window.location.href = '/';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
const handleDeleteAuthor = (author)=>{
|
||||||
renderSystems : function(){
|
if(!confirm('Are you sure you want to remove this author? They will lose all edit access to this brew, and it will dissapear from their userpage.')) return;
|
||||||
return _.map(SYSTEMS, (val)=>{
|
if(!metadata.authors.includes(author)) return;
|
||||||
return <label key={val}>
|
onChange({
|
||||||
<input
|
...metadata,
|
||||||
type='checkbox'
|
authors : metadata.authors.filter((a)=>a !== author)
|
||||||
checked={_.includes(this.props.metadata.systems, val)}
|
|
||||||
onChange={(e)=>this.handleSystem(val, e)} />
|
|
||||||
{val}
|
|
||||||
</label>;
|
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
const renderPublish = ()=>{
|
||||||
renderPublish : function(){
|
if(metadata.published){
|
||||||
if(this.props.metadata.published){
|
return <button id='publish-button' className='unpublish' onClick={()=>handlePublish(false)}>
|
||||||
return <button className='unpublish' onClick={()=>this.handlePublish(false)}>
|
<i className='fas fa-ban' aria-hidden='true' /> unpublish
|
||||||
<i className='fas fa-ban' /> unpublish
|
|
||||||
</button>;
|
</button>;
|
||||||
} else {
|
} else {
|
||||||
return <button className='publish' onClick={()=>this.handlePublish(true)}>
|
return <button id='publish-button' className='publish' onClick={()=>handlePublish(true)}>
|
||||||
<i className='fas fa-globe' /> publish
|
<i className='fas fa-globe' aria-hidden='true' /> publish
|
||||||
</button>;
|
</button>;
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
|
const renderAuthors = ()=>{
|
||||||
renderDelete : function(){
|
const authors = metadata.authors;
|
||||||
if(!this.props.metadata.editId) return;
|
const isOwner = global.account?.username && global.account?.username === authors[0];
|
||||||
|
if(!isOwner || authors.length < 2) return (
|
||||||
return <div className='field delete'>
|
<div className='field authors'>
|
||||||
<label>delete</label>
|
<label>authors</label>
|
||||||
<div className='value'>
|
<div className='value'>
|
||||||
<button className='publish' onClick={this.handleDelete}>
|
{authors.length > 0 && (
|
||||||
<i className='fas fa-trash-alt' /> delete brew
|
<a href={`/user/${authors[0]}`} className='author-link' target='_blank' title={`Owner - Click to open ${authors[0]}'s profile in a new tab`}>
|
||||||
</button>
|
{authors[0]}{authors.length > 1 && ', '}
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
{authors.length > 1 && authors.slice(1).map((author, i)=>(
|
||||||
|
<a href={`/user/${author}`} className='author-link' title={`Author - Click to open ${author}'s profile in a new tab`}>
|
||||||
|
{author}{i+2 < authors.length && ', '}
|
||||||
|
</a>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>;
|
);
|
||||||
},
|
return (
|
||||||
|
<div className='field authors'>
|
||||||
|
<label>Authors</label>
|
||||||
|
<ul className='list'>
|
||||||
|
{authors.length > 0 && (
|
||||||
|
<li className='tag owner' title='Owner'>
|
||||||
|
<a href={`/user/${authors[0]}`} className='author-link' title={`Owner - Click to open ${authors[0]}'s profile in a new tab`}>
|
||||||
|
{authors[0]}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
)}
|
||||||
|
|
||||||
renderAuthors : function(){
|
{authors.length > 1 && authors.slice(1).map((author, i)=>(
|
||||||
let text = 'None.';
|
<li className='tag author' key={i + 1} title='Author'>
|
||||||
if(this.props.metadata.authors && this.props.metadata.authors.length){
|
<a href={`/user/${author}`} className='author-link' title={`Author - Click to open ${authors[0]}'s profile in a new tab`}>
|
||||||
text = this.props.metadata.authors.join(', ');
|
{author}
|
||||||
}
|
</a>
|
||||||
return <div className='field authors'>
|
<button
|
||||||
<label>authors</label>
|
onClick={()=>handleDeleteAuthor(author)}
|
||||||
<div className='value'>
|
className='delete'
|
||||||
{text}
|
title={`Remove ${author} as an author`}
|
||||||
|
>
|
||||||
|
<i className='fa fa-times fa-fw' />
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>;
|
);
|
||||||
},
|
};
|
||||||
|
const renderThemeDropdown = ()=>{
|
||||||
renderThemeDropdown : function(){
|
const mergedThemes = _.merge(Themes, userThemes);
|
||||||
const mergedThemes = _.merge(Themes, this.props.userThemes);
|
|
||||||
|
|
||||||
const listThemes = (renderer)=>{
|
const listThemes = (renderer)=>{
|
||||||
return _.map(_.values(mergedThemes[renderer]), (theme)=>{
|
return _.map(_.values(mergedThemes[renderer]), (theme)=>{
|
||||||
if(theme.path == this.props.metadata.shareId) return;
|
if(theme.path == metadata.shareId) return;
|
||||||
const preview = theme.thumbnail || `/themes/${theme.renderer}/${theme.path}/dropdownPreview.png`;
|
const preview = theme.thumbnail || `/themes/${theme.renderer}/${theme.path}/dropdownPreview.png`;
|
||||||
const texture = theme.thumbnail || `/themes/${theme.renderer}/${theme.path}/dropdownTexture.png`;
|
const texture = theme.thumbnail || `/themes/${theme.renderer}/${theme.path}/dropdownTexture.png`;
|
||||||
return <div className='item' key={`${renderer}_${theme.name}`} value={`${theme.author ?? renderer} : ${theme.name}`} data={theme} title={''}>
|
return <div className='item' key={`${renderer}_${theme.name}`} value={`${theme.author ?? renderer} : ${theme.name}`} data={theme} title={''}>
|
||||||
@@ -227,8 +204,8 @@ const MetadataEditor = createClass({
|
|||||||
}).filter(Boolean);
|
}).filter(Boolean);
|
||||||
};
|
};
|
||||||
|
|
||||||
const currentRenderer = this.props.metadata.renderer;
|
const currentRenderer = metadata.renderer;
|
||||||
const currentThemeDisplay = this.props.themeBundle?.name ? `${this.props.themeBundle.author ?? currentRenderer} : ${this.props.themeBundle.name}` : 'No Theme Selected';
|
const currentThemeDisplay = themeBundle?.name ? `${themeBundle.author ?? currentRenderer} : ${themeBundle.name}` : 'No Theme Selected';
|
||||||
let dropdown;
|
let dropdown;
|
||||||
|
|
||||||
if(currentRenderer == 'legacy') {
|
if(currentRenderer == 'legacy') {
|
||||||
@@ -238,16 +215,17 @@ const MetadataEditor = createClass({
|
|||||||
</div>;
|
</div>;
|
||||||
} else {
|
} else {
|
||||||
dropdown =
|
dropdown =
|
||||||
<div className='value'>
|
<div className='value' data-tooltip-top='Select from the list below (built-in themes and brews you have tagged "meta:theme"), or paste in the Share URL or Share ID of any brew.'>
|
||||||
<Combobox trigger='click'
|
<Combobox trigger='click'
|
||||||
|
id='combobox-themes'
|
||||||
className='themes-dropdown'
|
className='themes-dropdown'
|
||||||
default={currentThemeDisplay}
|
defaultValue={currentThemeDisplay}
|
||||||
placeholder='Select from below, or enter the Share URL or ID of a brew with the meta:theme tag'
|
placeholder='Select from below, or enter the Share URL or ID of a brew with the meta:theme tag'
|
||||||
onSelect={(value)=>this.handleTheme(value)}
|
onSelect={(value)=>handleTheme(value)}
|
||||||
onEntry={(e)=>{
|
onEntry={(e)=>{
|
||||||
e.target.setCustomValidity(''); //Clear the validation popup while typing
|
e.target.setCustomValidity(''); //Clear the validation popup while typing
|
||||||
if(this.handleFieldChange('theme', e))
|
if(handleFieldChange('theme', e))
|
||||||
this.handleThemeWritein(e);
|
handleThemeWritein(e);
|
||||||
}}
|
}}
|
||||||
options={listThemes(currentRenderer)}
|
options={listThemes(currentRenderer)}
|
||||||
autoSuggest={{
|
autoSuggest={{
|
||||||
@@ -256,17 +234,15 @@ const MetadataEditor = createClass({
|
|||||||
filterOn : ['value', 'title']
|
filterOn : ['value', 'title']
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<small>Select from the list below (built-in themes and brews you have tagged "meta:theme"), or paste in the Share URL or Share ID of any brew.</small>
|
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <div className='field themes'>
|
return <div className='field themes'>
|
||||||
<label>theme</label>
|
<label htmlFor='combobox-themes'>theme</label>
|
||||||
{dropdown}
|
{dropdown}
|
||||||
</div>;
|
</div>;
|
||||||
},
|
};
|
||||||
|
const renderLanguageDropdown = ()=>{
|
||||||
renderLanguageDropdown : function(){
|
|
||||||
const langCodes = ['en', 'de', 'de-ch', 'fr', 'ja', 'es', 'it', 'sv', 'ru', 'zh-Hans', 'zh-Hant'];
|
const langCodes = ['en', 'de', 'de-ch', 'fr', 'ja', 'es', 'it', 'sv', 'ru', 'zh-Hans', 'zh-Hant'];
|
||||||
const listLanguages = ()=>{
|
const listLanguages = ()=>{
|
||||||
return _.map(langCodes.sort(), (code, index)=>{
|
return _.map(langCodes.sort(), (code, index)=>{
|
||||||
@@ -280,16 +256,19 @@ const MetadataEditor = createClass({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return <div className='field language'>
|
return <div className='field language'>
|
||||||
<label>language</label>
|
<label htmlFor='combobox-language'>language</label>
|
||||||
<div className='value'>
|
<div className='value' data-tooltip-right='Sets the HTML Lang property for your brew. May affect hyphenation or spellcheck.'>
|
||||||
<Combobox trigger='click'
|
<Combobox trigger='click'
|
||||||
|
id='combobox-language'
|
||||||
className='language-dropdown'
|
className='language-dropdown'
|
||||||
default={this.props.metadata.lang || ''}
|
defaultValue={metadata.lang || ''}
|
||||||
|
keepValueOnClose={true}
|
||||||
placeholder='en'
|
placeholder='en'
|
||||||
onSelect={(value)=>this.handleLanguage(value)}
|
valuePatterns="^[a-z]{2,3}(-[A-Z][a-z]{3})?(-[A-Z]{2})?$"
|
||||||
|
onSelect={(value)=>handleLanguage(value)}
|
||||||
onEntry={(e)=>{
|
onEntry={(e)=>{
|
||||||
e.target.setCustomValidity(''); //Clear the validation popup while typing
|
e.target.setCustomValidity(''); //Clear the validation popup while typing
|
||||||
this.handleFieldChange('lang', e);
|
handleFieldChange('lang', e);
|
||||||
}}
|
}}
|
||||||
options={listLanguages()}
|
options={listLanguages()}
|
||||||
autoSuggest={{
|
autoSuggest={{
|
||||||
@@ -298,14 +277,11 @@ const MetadataEditor = createClass({
|
|||||||
filterOn : ['value', 'detail', 'title']
|
filterOn : ['value', 'detail', 'title']
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<small>Sets the HTML Lang property for your brew. May affect hyphenation or spellcheck.</small>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>;
|
</div>;
|
||||||
},
|
};
|
||||||
|
const renderRenderOptions = ()=>{
|
||||||
renderRenderOptions : function(){
|
return <div className='field renderers'>
|
||||||
return <div className='field systems'>
|
|
||||||
<label>Renderer</label>
|
<label>Renderer</label>
|
||||||
<div className='value'>
|
<div className='value'>
|
||||||
<label key='legacy'>
|
<label key='legacy'>
|
||||||
@@ -313,8 +289,8 @@ const MetadataEditor = createClass({
|
|||||||
type='radio'
|
type='radio'
|
||||||
value = 'legacy'
|
value = 'legacy'
|
||||||
name = 'renderer'
|
name = 'renderer'
|
||||||
checked={this.props.metadata.renderer === 'legacy'}
|
checked={metadata.renderer === 'legacy'}
|
||||||
onChange={(e)=>this.handleRenderer('legacy', e)} />
|
onChange={(e)=>handleRenderer('legacy', e)} />
|
||||||
Legacy
|
Legacy
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
@@ -323,92 +299,121 @@ const MetadataEditor = createClass({
|
|||||||
type='radio'
|
type='radio'
|
||||||
value = 'V3'
|
value = 'V3'
|
||||||
name = 'renderer'
|
name = 'renderer'
|
||||||
checked={this.props.metadata.renderer === 'V3'}
|
checked={metadata.renderer === 'V3'}
|
||||||
onChange={(e)=>this.handleRenderer('V3', e)} />
|
onChange={(e)=>handleRenderer('V3', e)} />
|
||||||
V3
|
V3
|
||||||
</label>
|
</label>
|
||||||
<small><a href='/legacy' target='_blank' rel='noopener noreferrer'>Click here to see the demo page for the old Legacy renderer!</a></small>
|
<small><a href='/legacy' target='_blank' rel='noopener noreferrer'>Click here to see the demo page for the old Legacy renderer!</a></small>
|
||||||
</div>
|
</div>
|
||||||
</div>;
|
</div>;
|
||||||
},
|
};
|
||||||
|
|
||||||
render : function(){
|
return (
|
||||||
return <div className='metadataEditor'>
|
<div className='metadataEditor uiEditor'>
|
||||||
<h1>Properties Editor</h1>
|
<h1>Properties Editor</h1>
|
||||||
|
|
||||||
<div className='field title'>
|
<div className='field title'>
|
||||||
<label>title</label>
|
<label htmlFor='title_field'>title</label>
|
||||||
<input type='text' className='value'
|
<input
|
||||||
defaultValue={this.props.metadata.title}
|
type='text'
|
||||||
onChange={(e)=>this.handleFieldChange('title', e)} />
|
id='title_field'
|
||||||
|
className='value'
|
||||||
|
defaultValue={metadata.title}
|
||||||
|
onChange={(e)=>handleFieldChange('title', e)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className='field-group'>
|
<fieldset className='field-group'>
|
||||||
<div className='field-column'>
|
<div className='field-column'>
|
||||||
<div className='field description'>
|
<div className='field description'>
|
||||||
<label>description</label>
|
<label htmlFor='description_field'>description</label>
|
||||||
<textarea defaultValue={this.props.metadata.description} className='value'
|
<textarea
|
||||||
onChange={(e)=>this.handleFieldChange('description', e)} />
|
id='description_field'
|
||||||
|
defaultValue={metadata.description}
|
||||||
|
className='value'
|
||||||
|
onChange={(e)=>handleFieldChange('description', e)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className='field thumbnail'>
|
<div className='field thumbnail'>
|
||||||
<label>thumbnail</label>
|
<label htmlFor='thumbnail_field'>thumbnail</label>
|
||||||
<input type='text'
|
<input
|
||||||
defaultValue={this.props.metadata.thumbnail}
|
type='text'
|
||||||
|
id='thumbnail_field'
|
||||||
|
defaultValue={metadata.thumbnail}
|
||||||
placeholder='https://my.thumbnail.url'
|
placeholder='https://my.thumbnail.url'
|
||||||
className='value'
|
className='value'
|
||||||
onChange={(e)=>this.handleFieldChange('thumbnail', e)} />
|
onChange={(e)=>handleFieldChange('thumbnail', e)}
|
||||||
<button className='display' onClick={this.toggleThumbnailDisplay}>
|
/>
|
||||||
<i className={`fas fa-caret-${this.state.showThumbnail ? 'right' : 'left'}`} />
|
<button
|
||||||
|
className='display'
|
||||||
|
onClick={()=>setShowThumbnail(!showThumbnail)}
|
||||||
|
aria-label={`${showThumbnail ? 'hide thumbnail' : 'show thumbnail'}`}>
|
||||||
|
<i className={`fas fa-caret-${showThumbnail ? 'right' : 'left'}`} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{this.renderThumbnail()}
|
{showThumbnail && <img className='thumbnail-preview' src={metadata.thumbnail || homebreweryThumbnail}></img>}
|
||||||
</div>
|
</fieldset>
|
||||||
|
<div className='field tags'>
|
||||||
<TagInput label='tags' valuePatterns={[/^(?:(?:group|meta|system|type):)?[A-Za-z0-9][A-Za-z0-9 \/.\-]{0,40}$/]}
|
<label htmlFor='combobox-tags'>Tags</label>
|
||||||
placeholder='add tag' unique={true}
|
|
||||||
values={this.props.metadata.tags}
|
|
||||||
onChange={(e)=>this.handleFieldChange('tags', e)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div className='field systems'>
|
|
||||||
<label>systems</label>
|
|
||||||
<div className='value'>
|
<div className='value'>
|
||||||
{this.renderSystems()}
|
<TagInput
|
||||||
|
id='combobox-tags'
|
||||||
|
label='tags'
|
||||||
|
valuePatterns={/^\s*(?:(?:group|meta|system|type)\s*:\s*)?[A-Za-z0-9][A-Za-z0-9 \/\\.&_\-]{0,40}\s*$/}
|
||||||
|
placeholder='add tag'
|
||||||
|
unique={true}
|
||||||
|
values={metadata.tags}
|
||||||
|
onChange={(e)=>handleFieldChange('tags', e)}
|
||||||
|
tooltip='You may start tags with "type", "system", "group" or "meta" followed by a colon ":", these will be colored in your userpage.'
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{renderLanguageDropdown()}
|
||||||
{this.renderLanguageDropdown()}
|
{renderThemeDropdown()}
|
||||||
|
{renderRenderOptions()}
|
||||||
{this.renderThemeDropdown()}
|
|
||||||
|
|
||||||
{this.renderRenderOptions()}
|
|
||||||
|
|
||||||
<h2>Authors</h2>
|
<h2>Authors</h2>
|
||||||
|
{renderAuthors()}
|
||||||
{this.renderAuthors()}
|
<div className='field invitedAuthors'>
|
||||||
|
<label htmlFor='combobox-invited-authors'>Invited authors</label>
|
||||||
<TagInput label='invited authors' valuePatterns={[/.+/]}
|
|
||||||
validators={[(v)=>!this.props.metadata.authors?.includes(v)]}
|
|
||||||
placeholder='invite author' unique={true}
|
|
||||||
values={this.props.metadata.invitedAuthors}
|
|
||||||
notes={['Invited author usernames are case sensitive.', 'After adding an invited author, send them the edit link. There, they can choose to accept or decline the invitation.']}
|
|
||||||
onChange={(e)=>this.handleFieldChange('invitedAuthors', e)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<h2>Privacy</h2>
|
|
||||||
|
|
||||||
<div className='field publish'>
|
|
||||||
<label>publish</label>
|
|
||||||
<div className='value'>
|
<div className='value'>
|
||||||
{this.renderPublish()}
|
<TagInput
|
||||||
<small>Published brews are searchable in <a href='/vault'>the Vault</a> and visible on your user page. Unpublished brews are not indexed in the Vault or visible on your user page, but can still be shared and indexed by search engines. You can unpublish a brew any time.</small>
|
id='combobox-invited-authors'
|
||||||
|
label='invited authors'
|
||||||
|
valuePatterns={/.+/}
|
||||||
|
validators={[(v)=>!metadata.authors?.includes(v)]}
|
||||||
|
placeholder='invite author'
|
||||||
|
unique={true}
|
||||||
|
tooltip={`Invited author usernames are case sensitive.
|
||||||
|
After adding an invited author, send them the edit link. There, they can choose to accept or decline the invitation.`}
|
||||||
|
values={metadata.invitedAuthors}
|
||||||
|
onChange={(e)=>handleFieldChange('invitedAuthors', e)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{this.renderDelete()}
|
<h2>Privacy</h2>
|
||||||
|
<div className='field publish'>
|
||||||
|
<label htmlFor='publish-button'>publish</label>
|
||||||
|
<div className='value'>
|
||||||
|
{renderPublish()}
|
||||||
|
<small>
|
||||||
|
Published brews are searchable in <a href='/vault'>the Vault</a> and visible on your user page. Unpublished brews are not
|
||||||
|
indexed in the Vault or visible on your user page, but can still be shared and indexed by search engines. You can unpublish a
|
||||||
|
brew any time.
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{metadata.editId && <div className='field delete'>
|
||||||
|
<label htmlFor='delete-button'>delete</label>
|
||||||
|
<div className='value'>
|
||||||
|
<button id='delete-button' onClick={handleDelete}>
|
||||||
|
<i className='fas fa-trash-alt' /> delete brew
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
</div>;
|
export default MetadataEditor;
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = MetadataEditor;
|
|
||||||
@@ -1,317 +0,0 @@
|
|||||||
@import 'naturalcrit/styles/colors.less';
|
|
||||||
|
|
||||||
.userThemeName {
|
|
||||||
padding-right : 10px;
|
|
||||||
padding-left : 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.metadataEditor {
|
|
||||||
position : absolute;
|
|
||||||
box-sizing : border-box;
|
|
||||||
width : 100%;
|
|
||||||
height : calc(100vh - 54px); // 54px is the height of the navbar + snippet bar. probably a better way to dynamic get this.
|
|
||||||
padding : 25px;
|
|
||||||
overflow-y : auto;
|
|
||||||
font-size : 13px;
|
|
||||||
background-color : #999999;
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
margin : 0 0 40px;
|
|
||||||
font-weight : bold;
|
|
||||||
text-transform : uppercase;
|
|
||||||
}
|
|
||||||
|
|
||||||
h2 {
|
|
||||||
margin : 20px 0;
|
|
||||||
font-weight : bold;
|
|
||||||
color : #555555;
|
|
||||||
border-bottom : 2px solid gray;
|
|
||||||
}
|
|
||||||
|
|
||||||
& > div { margin-bottom : 10px; }
|
|
||||||
|
|
||||||
.field-group {
|
|
||||||
display : flex;
|
|
||||||
flex-wrap : wrap;
|
|
||||||
gap : 10px;
|
|
||||||
width : 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.field-column {
|
|
||||||
display : flex;
|
|
||||||
flex : 5 0 200px;
|
|
||||||
flex-direction : column;
|
|
||||||
gap : 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.field {
|
|
||||||
position : relative;
|
|
||||||
display : flex;
|
|
||||||
flex-wrap : wrap;
|
|
||||||
width : 100%;
|
|
||||||
min-width : 200px;
|
|
||||||
& > label {
|
|
||||||
width : 80px;
|
|
||||||
font-size : 0.9em;
|
|
||||||
font-weight : 800;
|
|
||||||
line-height : 1.8em;
|
|
||||||
text-transform : uppercase;
|
|
||||||
}
|
|
||||||
& > .value {
|
|
||||||
flex : 1 1 auto;
|
|
||||||
width : 50px;
|
|
||||||
&:invalid { background : #FFB9B9; }
|
|
||||||
small {
|
|
||||||
display : block;
|
|
||||||
font-size : 0.9em;
|
|
||||||
font-style : italic;
|
|
||||||
line-height : 1.4em;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
input[type='text'], textarea {
|
|
||||||
border : 1px solid gray;
|
|
||||||
&:focus { outline : 1px solid #444444; }
|
|
||||||
}
|
|
||||||
&.thumbnail, &.themes {
|
|
||||||
label { line-height : 2.0em; }
|
|
||||||
.value {
|
|
||||||
overflow : hidden;
|
|
||||||
text-overflow : ellipsis;
|
|
||||||
}
|
|
||||||
button {
|
|
||||||
.colorButton();
|
|
||||||
padding : 0px 5px;
|
|
||||||
color : white;
|
|
||||||
background-color : black;
|
|
||||||
border : 1px solid #999999;
|
|
||||||
&:hover { background-color : #777777; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.themes {
|
|
||||||
.value {
|
|
||||||
overflow : visible;
|
|
||||||
text-overflow : auto;
|
|
||||||
}
|
|
||||||
button {
|
|
||||||
padding-right : 5px;
|
|
||||||
padding-left : 5px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.description {
|
|
||||||
flex : 1;
|
|
||||||
textarea.value {
|
|
||||||
height : auto;
|
|
||||||
font-family : 'Open Sans', sans-serif;
|
|
||||||
resize : none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&.language .language-dropdown {
|
|
||||||
z-index : 200;
|
|
||||||
max-width : 150px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.thumbnail-preview {
|
|
||||||
position : relative;
|
|
||||||
flex : 1 1;
|
|
||||||
justify-self : center;
|
|
||||||
width : 80px;
|
|
||||||
height : min-content;
|
|
||||||
max-height : 115px;
|
|
||||||
aspect-ratio : 1 / 1;
|
|
||||||
object-fit : contain;
|
|
||||||
background-color : #AAAAAA;
|
|
||||||
}
|
|
||||||
|
|
||||||
.systems.field .value {
|
|
||||||
label {
|
|
||||||
display : inline-flex;
|
|
||||||
align-items : center;
|
|
||||||
margin-right : 15px;
|
|
||||||
font-size : 0.9em;
|
|
||||||
font-weight : 800;
|
|
||||||
vertical-align : middle;
|
|
||||||
white-space : nowrap;
|
|
||||||
cursor : pointer;
|
|
||||||
user-select : none;
|
|
||||||
}
|
|
||||||
input {
|
|
||||||
margin : 3px;
|
|
||||||
vertical-align : middle;
|
|
||||||
cursor : pointer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.publish.field .value {
|
|
||||||
position : relative;
|
|
||||||
margin-bottom : 15px;
|
|
||||||
button { width : 100%; }
|
|
||||||
button.publish {
|
|
||||||
.colorButton(@blueLight);
|
|
||||||
}
|
|
||||||
button.unpublish {
|
|
||||||
.colorButton(@silver);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.delete.field .value {
|
|
||||||
button {
|
|
||||||
.colorButton(@red);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.authors.field .value { line-height : 1.5em; }
|
|
||||||
|
|
||||||
.themes.field {
|
|
||||||
& .dropdown-container {
|
|
||||||
position : relative;
|
|
||||||
z-index : 100;
|
|
||||||
background-color : white;
|
|
||||||
}
|
|
||||||
& .dropdown-options { overflow-y : visible; }
|
|
||||||
.disabled {
|
|
||||||
font-style : italic;
|
|
||||||
color : dimgray;
|
|
||||||
background-color : darkgray;
|
|
||||||
}
|
|
||||||
.item {
|
|
||||||
position : relative;
|
|
||||||
padding : 3px 3px;
|
|
||||||
overflow : visible;
|
|
||||||
background-color : white;
|
|
||||||
border-top : 1px solid rgb(118, 118, 118);
|
|
||||||
.preview {
|
|
||||||
position : absolute;
|
|
||||||
top : 0;
|
|
||||||
right : 0;
|
|
||||||
z-index : 1;
|
|
||||||
display : flex;
|
|
||||||
flex-direction : column;
|
|
||||||
width : 200px;
|
|
||||||
overflow : hidden;
|
|
||||||
color : black;
|
|
||||||
background : #CCCCCC;
|
|
||||||
border-radius : 5px;
|
|
||||||
box-shadow : 0 0 5px black;
|
|
||||||
opacity : 0;
|
|
||||||
transition : opacity 250ms ease;
|
|
||||||
h6 {
|
|
||||||
padding-block : 0.5em;
|
|
||||||
padding-inline : 1em;
|
|
||||||
font-weight : 900;
|
|
||||||
border-bottom : 2px solid hsl(0,0%,40%);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.texture-container {
|
|
||||||
position : absolute;
|
|
||||||
top : 0;
|
|
||||||
left : 0;
|
|
||||||
width : 100%;
|
|
||||||
height : 100%;
|
|
||||||
min-height : 100%;
|
|
||||||
overflow : hidden;
|
|
||||||
> img {
|
|
||||||
position : absolute;
|
|
||||||
top : 0;
|
|
||||||
right : 0;
|
|
||||||
width : 50%;
|
|
||||||
min-height : 100%;
|
|
||||||
-webkit-mask-image : linear-gradient(90deg, transparent, black 20%);
|
|
||||||
mask-image : linear-gradient(90deg, transparent, black 20%);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
color : white;
|
|
||||||
background-color : @blue;
|
|
||||||
filter : unset;
|
|
||||||
}
|
|
||||||
&:hover > .preview { opacity : 1; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.field .list {
|
|
||||||
display : flex;
|
|
||||||
flex : 1 0;
|
|
||||||
flex-wrap : wrap;
|
|
||||||
|
|
||||||
> * { flex : 0 0 auto; }
|
|
||||||
|
|
||||||
#groupedIcon {
|
|
||||||
#backgroundColors;
|
|
||||||
position : relative;
|
|
||||||
top : -0.3em;
|
|
||||||
right : -0.3em;
|
|
||||||
display : inline-block;
|
|
||||||
min-width : 20px;
|
|
||||||
height : ~'calc(100% + 0.6em)';
|
|
||||||
color : white;
|
|
||||||
text-align : center;
|
|
||||||
cursor : pointer;
|
|
||||||
|
|
||||||
i {
|
|
||||||
position : relative;
|
|
||||||
top : 50%;
|
|
||||||
transform : translateY(-50%);
|
|
||||||
}
|
|
||||||
|
|
||||||
&:not(:last-child) { border-right : 1px solid black; }
|
|
||||||
|
|
||||||
&:last-child { border-radius : 0 0.5em 0.5em 0; }
|
|
||||||
}
|
|
||||||
|
|
||||||
.tag {
|
|
||||||
padding : 0.3em;
|
|
||||||
margin : 2px;
|
|
||||||
font-size : 0.9em;
|
|
||||||
background-color : #DDDDDD;
|
|
||||||
border-radius : 0.5em;
|
|
||||||
|
|
||||||
.icon { #groupedIcon; }
|
|
||||||
}
|
|
||||||
|
|
||||||
.input-group {
|
|
||||||
height : ~'calc(.9em + 4px + .6em)';
|
|
||||||
|
|
||||||
input { border-radius : 0.5em 0 0 0.5em; }
|
|
||||||
|
|
||||||
input:last-child { border-radius : 0.5em; }
|
|
||||||
|
|
||||||
.value {
|
|
||||||
width : 7.5vw;
|
|
||||||
min-width : 75px;
|
|
||||||
height : 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.input-group {
|
|
||||||
height : ~'calc(.9em + 4px + .6em)';
|
|
||||||
|
|
||||||
input { border-radius : 0.5em 0 0 0.5em; }
|
|
||||||
|
|
||||||
input:last-child { border-radius : 0.5em; }
|
|
||||||
|
|
||||||
.value {
|
|
||||||
width : 7.5vw;
|
|
||||||
min-width : 75px;
|
|
||||||
height : 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.invalid:focus { background-color : pink; }
|
|
||||||
|
|
||||||
.icon {
|
|
||||||
#groupedIcon;
|
|
||||||
top : -0.54em;
|
|
||||||
right : 1px;
|
|
||||||
height : 97%;
|
|
||||||
|
|
||||||
i { font-size : 1.125em; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
module.exports = {
|
export default {
|
||||||
title : [
|
title : [
|
||||||
(value)=>{
|
(value)=>{
|
||||||
return value?.length > 100 ? 'Max title length of 100 characters' : null;
|
return value?.length > 100 ? 'Max title length of 100 characters' : null;
|
||||||
|
|||||||
@@ -0,0 +1,143 @@
|
|||||||
|
import '../uiEditor.less';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
const SettingsEditor = ({ settings, updateSettings = ()=>{}, EditorThemeNameList })=>{
|
||||||
|
|
||||||
|
const validations = {};
|
||||||
|
|
||||||
|
const handleFieldChange = (setting, e)=>{
|
||||||
|
const value =
|
||||||
|
e.target.type === 'checkbox'
|
||||||
|
? e.target.checked
|
||||||
|
: e.target.value;
|
||||||
|
|
||||||
|
const inputRules = validations[setting] ?? [];
|
||||||
|
|
||||||
|
const validationErrors = inputRules
|
||||||
|
.map((rule)=>rule(value))
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
|
if(validationErrors.length > 0) {
|
||||||
|
e.target.setCustomValidity(validationErrors.join('\n'));
|
||||||
|
e.target.reportValidity();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.target.setCustomValidity('');
|
||||||
|
|
||||||
|
const updatedSettings = {
|
||||||
|
...settings,
|
||||||
|
[setting] : e.target.type === 'number'
|
||||||
|
? Number(value)
|
||||||
|
: value,
|
||||||
|
};
|
||||||
|
|
||||||
|
updateSettings(updatedSettings);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='settingsEditor uiEditor'>
|
||||||
|
<h1>Editor Settings</h1>
|
||||||
|
|
||||||
|
<div className='field'>
|
||||||
|
<label htmlFor='changeEditorTheme'>
|
||||||
|
Select your Editor Theme
|
||||||
|
</label>
|
||||||
|
<div className='value'>
|
||||||
|
<select id='changeEditorTheme' value={settings.editorTheme} onChange={(e)=>handleFieldChange('editorTheme', e)} >
|
||||||
|
{EditorThemeNameList.map((theme, key)=>{
|
||||||
|
return <option key={key} value={theme}>{theme}</option>;
|
||||||
|
})}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='field'>
|
||||||
|
<label htmlFor='autoCloseBrackets'>
|
||||||
|
Automatically close brackets
|
||||||
|
</label>
|
||||||
|
<div className='value'>
|
||||||
|
<input
|
||||||
|
id='autoCloseBrackets'
|
||||||
|
type='checkbox'
|
||||||
|
name='autoCloseBrackets'
|
||||||
|
checked={settings.autoCloseBrackets}
|
||||||
|
onChange={(e)=>handleFieldChange('autoCloseBrackets', e)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='field'>
|
||||||
|
<label htmlFor='showImagePreviews'>
|
||||||
|
Show Image Previews when hovering a link
|
||||||
|
</label>
|
||||||
|
<div className='value'>
|
||||||
|
<input
|
||||||
|
id='showImagePreviews'
|
||||||
|
type='checkbox'
|
||||||
|
name='showImagePreviews'
|
||||||
|
checked={settings.showImagePreviews}
|
||||||
|
onChange={(e)=>handleFieldChange('showImagePreviews', e)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='field'>
|
||||||
|
<label htmlFor='activeLineShading'>
|
||||||
|
Background shading of active line
|
||||||
|
</label>
|
||||||
|
<div className='value'>
|
||||||
|
<input
|
||||||
|
id='activeLineShading'
|
||||||
|
type='checkbox'
|
||||||
|
name='activeLineShading'
|
||||||
|
checked={settings.activeLineShading}
|
||||||
|
onChange={(e)=>handleFieldChange('activeLineShading', e)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='field'>
|
||||||
|
<label htmlFor='lineNumbers'>Show Line Numbers</label>
|
||||||
|
<div className='value'>
|
||||||
|
<input
|
||||||
|
id='lineNumbers'
|
||||||
|
type='checkbox'
|
||||||
|
name='lineNumbers'
|
||||||
|
checked={settings.lineNumbers}
|
||||||
|
onChange={(e)=>handleFieldChange('lineNumbers', e)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='field'>
|
||||||
|
<label htmlFor='fontSize'>
|
||||||
|
Editor Font Size
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div className='value'>
|
||||||
|
<small style={{ fontSize: `${settings.fontSize || 1}em` }}>from 7px to 26px</small>
|
||||||
|
<input
|
||||||
|
id='fontSize'
|
||||||
|
type='range'
|
||||||
|
min={.5}
|
||||||
|
step={.1}
|
||||||
|
max={2}
|
||||||
|
list='font-sizes'
|
||||||
|
name='fontSize'
|
||||||
|
title={`${Math.round(settings.fontSize * 13)}px`}
|
||||||
|
value={settings.fontSize || 1}
|
||||||
|
onChange={(e)=>handleFieldChange('fontSize', e)}
|
||||||
|
/>
|
||||||
|
<datalist id='font-sizes'>
|
||||||
|
<option value='1' />
|
||||||
|
</datalist>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SettingsEditor;
|
||||||
@@ -1,330 +1,295 @@
|
|||||||
/*eslint max-lines: ["warn", {"max": 350, "skipBlankLines": true, "skipComments": true}]*/
|
/*eslint max-lines: ["warn", {"max": 350, "skipBlankLines": true, "skipComments": true}]*/
|
||||||
require('./snippetbar.less');
|
import './snippetbar.less';
|
||||||
const React = require('react');
|
import React, { useState, useEffect } from 'react';
|
||||||
const createClass = require('create-react-class');
|
import { Dropdown } from '@components/dropdown/dropdown.jsx';
|
||||||
const _ = require('lodash');
|
|
||||||
const cx = require('classnames');
|
import _ from 'lodash';
|
||||||
|
import cx from 'classnames';
|
||||||
|
|
||||||
import { loadHistory } from '../../utils/versionHistory.js';
|
import { loadHistory } from '../../utils/versionHistory.js';
|
||||||
import { brewSnippetsToJSON } from '../../../../shared/helpers.js';
|
import { brewSnippetsToJSON } from '@shared/helpers.js';
|
||||||
|
|
||||||
//Import all themes
|
/*eslint-disable camelcase*/
|
||||||
const ThemeSnippets = {};
|
import Legacy5ePHB from '@themes/Legacy/5ePHB/snippets.js';
|
||||||
ThemeSnippets['Legacy_5ePHB'] = require('themes/Legacy/5ePHB/snippets.js');
|
import V3_5ePHB from '@themes/V3/5ePHB/snippets.js';
|
||||||
ThemeSnippets['V3_5ePHB'] = require('themes/V3/5ePHB/snippets.js');
|
import V3_5eDMG from '@themes/V3/5eDMG/snippets.js';
|
||||||
ThemeSnippets['V3_5eDMG'] = require('themes/V3/5eDMG/snippets.js');
|
import V3_Journal from '@themes/V3/Journal/snippets.js';
|
||||||
ThemeSnippets['V3_Journal'] = require('themes/V3/Journal/snippets.js');
|
import V3_Blank from '@themes/V3/Blank/snippets.js';
|
||||||
ThemeSnippets['V3_Blank'] = require('themes/V3/Blank/snippets.js');
|
|
||||||
|
|
||||||
const EditorThemes = require('build/homebrew/codeMirror/editorThemes.json');
|
const ThemeSnippets = {
|
||||||
|
Legacy_5ePHB : Legacy5ePHB,
|
||||||
|
V3_5ePHB : V3_5ePHB,
|
||||||
|
V3_5eDMG : V3_5eDMG,
|
||||||
|
V3_Journal : V3_Journal,
|
||||||
|
V3_Blank : V3_Blank,
|
||||||
|
};
|
||||||
|
/*eslint-enable camelcase */
|
||||||
|
|
||||||
const execute = function(val, props){
|
const execute = function(val, props){
|
||||||
if(_.isFunction(val)) return val(props);
|
if(_.isFunction(val)) return val(props);
|
||||||
return val;
|
return val;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Snippetbar = createClass({
|
const SnippetBar = ({
|
||||||
displayName : 'SnippetBar',
|
brew = {},
|
||||||
getDefaultProps : function() {
|
view = 'text',
|
||||||
return {
|
onViewChange = ()=>{},
|
||||||
brew : {},
|
onInject = ()=>{},
|
||||||
view : 'text',
|
onToggle = ()=>{},
|
||||||
onViewChange : ()=>{},
|
showEditButtons = true,
|
||||||
onInject : ()=>{},
|
renderer = 'legacy',
|
||||||
onToggle : ()=>{},
|
undo = ()=>{},
|
||||||
showEditButtons : true,
|
redo = ()=>{},
|
||||||
renderer : 'legacy',
|
historySize = ()=>{},
|
||||||
undo : ()=>{},
|
foldCode = ()=>{},
|
||||||
redo : ()=>{},
|
unfoldCode = ()=>{},
|
||||||
historySize : ()=>{},
|
formatCode = ()=>{},
|
||||||
foldCode : ()=>{},
|
cursorPos = {},
|
||||||
unfoldCode : ()=>{},
|
themeBundle = [],
|
||||||
updateEditorTheme : ()=>{},
|
updateBrew = ()=>{}
|
||||||
cursorPos : {},
|
})=>{
|
||||||
themeBundle : [],
|
const [snippets, setSnippets] = useState([]);
|
||||||
updateBrew : ()=>{}
|
const [historyExists, setHistoryExists] = useState(false);
|
||||||
};
|
const [historyItems, setHistoryItems] = useState([]);
|
||||||
},
|
|
||||||
|
|
||||||
getInitialState : function() {
|
useEffect(()=>{
|
||||||
return {
|
setSnippets(compileSnippets());
|
||||||
renderer : this.props.renderer,
|
}, []);
|
||||||
themeSelector : false,
|
|
||||||
snippets : [],
|
|
||||||
showHistory : false,
|
|
||||||
historyExists : false,
|
|
||||||
historyItems : []
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
componentDidMount : async function(prevState) {
|
const mergeCustomizer = (oldValue, newValue, key)=>{
|
||||||
const snippets = this.compileSnippets();
|
if(key == 'snippets') {
|
||||||
this.setState({
|
|
||||||
snippets : snippets
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
componentDidUpdate : async function(prevProps, prevState) {
|
|
||||||
if(prevProps.renderer != this.props.renderer ||
|
|
||||||
prevProps.theme != this.props.theme ||
|
|
||||||
prevProps.themeBundle != this.props.themeBundle ||
|
|
||||||
prevProps.brew.snippets != this.props.brew.snippets) {
|
|
||||||
this.setState({
|
|
||||||
snippets : this.compileSnippets()
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Update history list if it has changed
|
|
||||||
const checkHistoryItems = await loadHistory(this.props.brew);
|
|
||||||
|
|
||||||
// If all items have the noData property, there is no saved data
|
|
||||||
const checkHistoryExists = !checkHistoryItems.every((historyItem)=>{
|
|
||||||
return historyItem?.noData;
|
|
||||||
});
|
|
||||||
if(prevState.historyExists != checkHistoryExists){
|
|
||||||
this.setState({
|
|
||||||
historyExists : checkHistoryExists
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// If any history items have changed, update the list
|
|
||||||
if(checkHistoryExists && checkHistoryItems.some((historyItem, index)=>{
|
|
||||||
return index >= prevState.historyItems.length || !_.isEqual(historyItem, prevState.historyItems[index]);
|
|
||||||
})){
|
|
||||||
this.setState({
|
|
||||||
historyItems : checkHistoryItems
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
mergeCustomizer : function(oldValue, newValue, key) {
|
|
||||||
if(key == 'snippets') {
|
|
||||||
const result = _.reverse(_.unionBy(_.reverse(newValue), _.reverse(oldValue), 'name')); // Join snippets together, with preference for the child theme over the parent theme
|
const result = _.reverse(_.unionBy(_.reverse(newValue), _.reverse(oldValue), 'name')); // Join snippets together, with preference for the child theme over the parent theme
|
||||||
return result.filter((snip)=>snip.gen || snip.subsnippets);
|
return result.filter((snip)=>snip.gen || snip.subsnippets);
|
||||||
};
|
};
|
||||||
},
|
};
|
||||||
|
const compileSnippets = ()=>{
|
||||||
compileSnippets : function() {
|
|
||||||
let compiledSnippets = [];
|
let compiledSnippets = [];
|
||||||
|
|
||||||
let oldSnippets = _.keyBy(compiledSnippets, 'groupName');
|
let oldSnippets = _.keyBy(compiledSnippets, 'groupName');
|
||||||
|
|
||||||
if(this.props.themeBundle.snippets) {
|
if(themeBundle.snippets) {
|
||||||
for (let snippets of this.props.themeBundle.snippets) {
|
for (let snippets of themeBundle.snippets) {
|
||||||
if(typeof(snippets) == 'string') // load staticThemes as needed; they were sent as just a file name
|
if(typeof(snippets) == 'string') // load staticThemes as needed; they were sent as just a file name
|
||||||
snippets = ThemeSnippets[snippets];
|
snippets = ThemeSnippets[snippets];
|
||||||
|
|
||||||
const newSnippets = _.keyBy(_.cloneDeep(snippets), 'groupName');
|
const newSnippets = _.keyBy(_.cloneDeep(snippets), 'groupName');
|
||||||
compiledSnippets = _.values(_.mergeWith(oldSnippets, newSnippets, this.mergeCustomizer));
|
compiledSnippets = _.values(_.mergeWith(oldSnippets, newSnippets, mergeCustomizer));
|
||||||
|
|
||||||
oldSnippets = _.keyBy(compiledSnippets, 'groupName');
|
oldSnippets = _.keyBy(compiledSnippets, 'groupName');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const userSnippetsasJSON = brewSnippetsToJSON(this.props.brew.title || 'New Document', this.props.brew.snippets, this.props.themeBundle.snippets);
|
const userSnippetsasJSON = brewSnippetsToJSON(brew.title || 'New Document', brew.snippets, themeBundle.snippets);
|
||||||
compiledSnippets.push(userSnippetsasJSON);
|
compiledSnippets.push(userSnippetsasJSON);
|
||||||
|
|
||||||
return compiledSnippets;
|
return compiledSnippets;
|
||||||
},
|
};
|
||||||
|
|
||||||
handleSnippetClick : function(injectedText){
|
useEffect(()=>{
|
||||||
this.props.onInject(injectedText);
|
setSnippets(compileSnippets());
|
||||||
},
|
}, [renderer, themeBundle, brew.snippets]);
|
||||||
|
|
||||||
toggleThemeSelector : function(e){
|
useEffect(()=>{
|
||||||
if(e.target.tagName != 'SELECT'){
|
const updateHistory = async ()=>{
|
||||||
this.setState({
|
// Update history list if it has changed
|
||||||
themeSelector : !this.state.themeSelector
|
const checkHistoryItems = await loadHistory(brew);
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
changeTheme : function(e){
|
// If all items have the noData property, there is no saved data
|
||||||
if(e.target.value == this.props.currentEditorTheme) return;
|
const checkHistoryExists = !checkHistoryItems.every(
|
||||||
this.props.updateEditorTheme(e.target.value);
|
(historyItem)=>historyItem?.noData
|
||||||
|
);
|
||||||
|
|
||||||
this.setState({
|
if(historyExists !== checkHistoryExists) {
|
||||||
showThemeSelector : false,
|
setHistoryExists(checkHistoryExists);
|
||||||
});
|
}
|
||||||
},
|
|
||||||
|
|
||||||
renderThemeSelector : function(){
|
// If any history items have changed, update the list
|
||||||
return <div className='themeSelector'>
|
if(!_.isEqual(checkHistoryItems, historyItems)) {
|
||||||
<select value={this.props.currentEditorTheme} onChange={this.changeTheme} >
|
setHistoryItems(checkHistoryItems);
|
||||||
{EditorThemes.map((theme, key)=>{
|
}
|
||||||
return <option key={key} value={theme}>{theme}</option>;
|
};
|
||||||
})}
|
|
||||||
</select>
|
|
||||||
</div>;
|
|
||||||
},
|
|
||||||
|
|
||||||
renderSnippetGroups : function(){
|
updateHistory();
|
||||||
const snippets = this.state.snippets.filter((snippetGroup)=>snippetGroup.view === this.props.view);
|
}, [brew]);
|
||||||
if(snippets.length === 0) return null;
|
|
||||||
|
|
||||||
return <div className='snippets'>
|
const handleSnippetClick = (injectedText)=>onInject(injectedText);
|
||||||
{_.map(snippets, (snippetGroup)=>{
|
|
||||||
|
const renderSnippetGroups = ()=>{
|
||||||
|
const currentSnippets = snippets.filter((snippetGroup)=>snippetGroup.view === view);
|
||||||
|
if(currentSnippets.length === 0) return null;
|
||||||
|
|
||||||
|
return <ul className='snippets' role='menubar' aria-label='Snippets Menubar'>
|
||||||
|
{_.map(currentSnippets, (snippetGroup)=>{
|
||||||
return <SnippetGroup
|
return <SnippetGroup
|
||||||
brew={this.props.brew}
|
brew={brew}
|
||||||
groupName={snippetGroup.groupName}
|
groupName={snippetGroup.groupName}
|
||||||
icon={snippetGroup.icon}
|
icon={snippetGroup.icon}
|
||||||
snippets={snippetGroup.snippets}
|
snippets={snippetGroup.snippets}
|
||||||
key={snippetGroup.groupName}
|
key={snippetGroup.groupName}
|
||||||
onSnippetClick={this.handleSnippetClick}
|
onSnippetClick={handleSnippetClick}
|
||||||
cursorPos={this.props.cursorPos}
|
cursorPos={cursorPos}
|
||||||
/>;
|
/>;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
</div>;
|
</ul>;
|
||||||
},
|
};
|
||||||
|
|
||||||
replaceContent : function(item){
|
const replaceContent = (item)=>{
|
||||||
return this.props.updateBrew(item);
|
return updateBrew(item);
|
||||||
},
|
};
|
||||||
|
|
||||||
toggleHistoryMenu : function(){
|
const renderHistoryMenu = ()=>{
|
||||||
this.setState({
|
return (
|
||||||
showHistory : !this.state.showHistory
|
<Dropdown
|
||||||
});
|
groupName='History'
|
||||||
},
|
icon='fas fa-clock-rotate-left'
|
||||||
|
className='history'
|
||||||
|
customTrigger={<><i className='fas fa-clock-rotate-left' /></>}
|
||||||
|
disabled={!historyExists}
|
||||||
|
>
|
||||||
|
{historyExists && _.map(historyItems, (item, index)=>{
|
||||||
|
if(item.noData || !item.savedAt) return null;
|
||||||
|
|
||||||
renderHistoryItems : function() {
|
const saveTime = new Date(item.savedAt);
|
||||||
if(!this.state.historyExists) return;
|
const diffMs = new Date() - saveTime;
|
||||||
|
const diffSecs = Math.floor(diffMs / 1000);
|
||||||
|
|
||||||
return <div className='dropdown'>
|
let diffString = `about ${diffSecs} seconds ago`;
|
||||||
{_.map(this.state.historyItems, (item, index)=>{
|
|
||||||
if(item.noData || !item.savedAt) return;
|
|
||||||
|
|
||||||
const saveTime = new Date(item.savedAt);
|
if(diffSecs > 60)
|
||||||
const diffMs = new Date() - saveTime;
|
diffString = `about ${Math.floor(diffSecs / 60)} minutes ago`;
|
||||||
const diffSecs = Math.floor(diffMs / 1000);
|
if(diffSecs > (60 * 60))
|
||||||
|
diffString = `about ${Math.floor(diffSecs / (60 * 60))} hours ago`;
|
||||||
|
if(diffSecs > (24 * 60 * 60))
|
||||||
|
diffString = `about ${Math.floor(diffSecs / (24 * 60 * 60))} days ago`;
|
||||||
|
if(diffSecs > (7 * 24 * 60 * 60))
|
||||||
|
diffString = `about ${Math.floor(diffSecs / (7 * 24 * 60 * 60))} weeks ago`;
|
||||||
|
|
||||||
let diffString = `about ${diffSecs} seconds ago`;
|
return (
|
||||||
|
<li key={index} role='none'>
|
||||||
|
<button
|
||||||
|
className='menu-item'
|
||||||
|
onClick={()=>replaceContent(item)}
|
||||||
|
role='menuitem'
|
||||||
|
>
|
||||||
|
<i className={`fas fa-${index + 1}`} />
|
||||||
|
<span
|
||||||
|
className='name'
|
||||||
|
title={saveTime.toISOString()}
|
||||||
|
>
|
||||||
|
v{item.version} : {diffString}
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Dropdown>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
if(diffSecs > 60) diffString = `about ${Math.floor(diffSecs / 60)} minutes ago`;
|
const renderEditorButtons =()=>{
|
||||||
if(diffSecs > (60 * 60)) diffString = `about ${Math.floor(diffSecs / (60 * 60))} hours ago`;
|
if(!showEditButtons) return;
|
||||||
if(diffSecs > (24 * 60 * 60)) diffString = `about ${Math.floor(diffSecs / (24 * 60 * 60))} days ago`;
|
|
||||||
if(diffSecs > (7 * 24 * 60 * 60)) diffString = `about ${Math.floor(diffSecs / (7 * 24 * 60 * 60))} weeks ago`;
|
|
||||||
|
|
||||||
return <div className='snippet' key={index} onClick={()=>{this.replaceContent(item);}} >
|
|
||||||
<i className={`fas fa-${index+1}`} />
|
|
||||||
<span className='name' title={saveTime.toISOString()}>v{item.version} : {diffString}</span>
|
|
||||||
</div>;
|
|
||||||
})}
|
|
||||||
</div>;
|
|
||||||
},
|
|
||||||
|
|
||||||
renderEditorButtons : function(){
|
|
||||||
if(!this.props.showEditButtons) return;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='editors'>
|
<div className='editors'>
|
||||||
{this.props.view !== 'meta' && <><div className='historyTools'>
|
{view !== 'meta' && view !== 'settings' && <><div className='historyTools'>
|
||||||
<div className={`editorTool snippetGroup history ${this.state.historyExists ? 'active' : ''}`}
|
{renderHistoryMenu()}
|
||||||
onClick={this.toggleHistoryMenu} >
|
<button className={`editorTool undo ${historySize.done ? 'active' : ''}`}
|
||||||
<i className='fas fa-clock-rotate-left' />
|
onClick={undo} >
|
||||||
{ this.state.showHistory && this.renderHistoryItems() }
|
|
||||||
</div>
|
|
||||||
<div className={`editorTool undo ${this.props.historySize.undo ? 'active' : ''}`}
|
|
||||||
onClick={this.props.undo} >
|
|
||||||
<i className='fas fa-undo' />
|
<i className='fas fa-undo' />
|
||||||
</div>
|
</button>
|
||||||
<div className={`editorTool redo ${this.props.historySize.redo ? 'active' : ''}`}
|
<button className={`editorTool redo ${historySize.undone ? 'active' : ''}`}
|
||||||
onClick={this.props.redo} >
|
onClick={redo} >
|
||||||
<i className='fas fa-redo' />
|
<i className='fas fa-redo' />
|
||||||
</div>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div className='codeTools'>
|
<div className='codeTools'>
|
||||||
<div className={`editorTool foldAll ${this.props.foldCode ? 'active' : ''}`}
|
<button className={`editorTool foldAll ${foldCode ? 'active' : ''}`}
|
||||||
onClick={this.props.foldCode} >
|
onClick={foldCode} >
|
||||||
<i className='fas fa-compress-alt' />
|
<i className='fas fa-compress-alt' />
|
||||||
</div>
|
</button>
|
||||||
<div className={`editorTool unfoldAll ${this.props.unfoldCode ? 'active' : ''}`}
|
<button className={`editorTool unfoldAll ${unfoldCode ? 'active' : ''}`}
|
||||||
onClick={this.props.unfoldCode} >
|
onClick={unfoldCode} >
|
||||||
<i className='fas fa-expand-alt' />
|
<i className='fas fa-expand-alt' />
|
||||||
</div>
|
</button>
|
||||||
<div className={`editorTheme ${this.state.themeSelector ? 'active' : ''}`}
|
<button className={`editorTool formatCode ${formatCode ? 'active' : ''}`}
|
||||||
onClick={this.toggleThemeSelector} >
|
onClick={formatCode} >
|
||||||
<i className='fas fa-palette' />
|
<i className='fas fa-wand-magic-sparkles' />
|
||||||
{this.state.themeSelector && this.renderThemeSelector()}
|
</button>
|
||||||
</div>
|
|
||||||
</div></>}
|
</div></>}
|
||||||
|
|
||||||
<div className='tabs'>
|
<div className='tabs'>
|
||||||
<div className={cx('text', { selected: this.props.view === 'text' })}
|
<button className={cx('text', { selected: view === 'text' })}
|
||||||
onClick={()=>this.props.onViewChange('text')}>
|
onClick={()=>onViewChange('text')}>
|
||||||
<i className='fa fa-beer' />
|
<i className='fa fa-beer' />
|
||||||
</div>
|
</button>
|
||||||
<div className={cx('style', { selected: this.props.view === 'style' })}
|
<button className={cx('style', { selected: view === 'style' })}
|
||||||
onClick={()=>this.props.onViewChange('style')}>
|
onClick={()=>onViewChange('style')}>
|
||||||
<i className='fa fa-paint-brush' />
|
<i className='fa fa-paint-brush' />
|
||||||
</div>
|
</button>
|
||||||
<div className={cx('snippet', { selected: this.props.view === 'snippet' })}
|
<button className={cx('snippet', { selected: view === 'snippet' })}
|
||||||
onClick={()=>this.props.onViewChange('snippet')}>
|
onClick={()=>onViewChange('snippet')}>
|
||||||
<i className='fas fa-th-list' />
|
<i className='fas fa-th-list' />
|
||||||
</div>
|
</button>
|
||||||
<div className={cx('meta', { selected: this.props.view === 'meta' })}
|
<button className={cx('meta', { selected: view === 'meta' })}
|
||||||
onClick={()=>this.props.onViewChange('meta')}>
|
onClick={()=>onViewChange('meta')}>
|
||||||
<i className='fas fa-info-circle' />
|
<i className='fas fa-info-circle' />
|
||||||
</div>
|
</button>
|
||||||
|
<button className={cx('settings', { selected: view === 'settings' })}
|
||||||
|
onClick={()=>onViewChange('settings')}>
|
||||||
|
<i className='fas fa-gear' />
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
};
|
||||||
|
|
||||||
render : function(){
|
return <div className='snippetBar'>
|
||||||
return <div className='snippetBar'>
|
{renderSnippetGroups()}
|
||||||
{this.renderSnippetGroups()}
|
{renderEditorButtons()}
|
||||||
{this.renderEditorButtons()}
|
</div>;
|
||||||
</div>;
|
};
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = Snippetbar;
|
export default SnippetBar;
|
||||||
|
|
||||||
const SnippetGroup = createClass({
|
const SnippetGroup = (props)=>{
|
||||||
displayName : 'SnippetGroup',
|
const {
|
||||||
getDefaultProps : function() {
|
brew = {},
|
||||||
return {
|
groupName = '',
|
||||||
brew : {},
|
icon = 'fas fa-rocket',
|
||||||
groupName : '',
|
snippets = [],
|
||||||
icon : 'fas fa-rocket',
|
onSnippetClick = function(){},
|
||||||
snippets : [],
|
} = props;
|
||||||
onSnippetClick : function(){},
|
|
||||||
};
|
const handleSnippetClick = (e, snippet)=>{
|
||||||
},
|
onSnippetClick(execute(snippet.gen, props));
|
||||||
handleSnippetClick : function(e, snippet){
|
};
|
||||||
e.stopPropagation();
|
const renderSnippets = (snippets)=>{
|
||||||
this.props.onSnippetClick(execute(snippet.gen, this.props));
|
|
||||||
},
|
|
||||||
renderSnippets : function(snippets){
|
|
||||||
return _.map(snippets, (snippet)=>{
|
return _.map(snippets, (snippet)=>{
|
||||||
return <div className='snippet' key={snippet.name} onClick={(e)=>this.handleSnippetClick(e, snippet)}>
|
if(!snippet.subsnippets){
|
||||||
<i className={snippet.icon} />
|
return (
|
||||||
<span className={`name${snippet.disabled ? ' disabled' : ''}`} title={snippet.name}>{snippet.name}</span>
|
<li key={snippet.name} role='none'>
|
||||||
{snippet.experimental && <span className='beta'>beta</span>}
|
<button className='menu-item' onClick={(e)=>handleSnippetClick(e, snippet)} role='menuitem' aria-label={snippet.name} disabled={snippet.disabled}>
|
||||||
{snippet.disabled && <span className='beta' title='temporarily disabled due to large slowdown; under re-design'>disabled</span>}
|
<i className={snippet.icon} />
|
||||||
{snippet.subsnippets && <>
|
<span className={`name${snippet.disabled ? ' disabled' : ''}`} title={snippet.name}>{snippet.name}</span>
|
||||||
<i className='fas fa-caret-right'></i>
|
{snippet.experimental && <span className='status'>beta</span>}
|
||||||
<div className='dropdown side'>
|
{snippet.disabled && <span className='status' title='temporarily disabled due to large slowdown; under re-design'>disabled</span>}
|
||||||
{this.renderSnippets(snippet.subsnippets)}
|
</button>
|
||||||
</div></>}
|
</li>
|
||||||
</div>;
|
);
|
||||||
|
} else if(snippet.subsnippets){
|
||||||
|
return (
|
||||||
|
<Dropdown groupName={snippet.name} icon={snippet.icon} key={snippet.name}>
|
||||||
|
{renderSnippets(snippet.subsnippets)}
|
||||||
|
</Dropdown>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
|
|
||||||
render : function(){
|
return <Dropdown groupName={groupName} id={groupName} icon={icon}>
|
||||||
const snippetGroup = `snippetGroup snippetBarButton ${this.props.snippets.length === 0 ? 'disabledSnippets' : ''}`;
|
{renderSnippets(snippets)}
|
||||||
return <div className={snippetGroup}>
|
</Dropdown>;
|
||||||
<div className='text'>
|
};
|
||||||
<i className={this.props.icon} />
|
|
||||||
<span className='groupName'>{this.props.groupName}</span>
|
|
||||||
</div>
|
|
||||||
<div className='dropdown'>
|
|
||||||
{this.renderSnippets(this.props.snippets)}
|
|
||||||
</div>
|
|
||||||
</div>;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
@@ -1,28 +1,33 @@
|
|||||||
@import (less) './client/icons/customIcons.less';
|
@import '@sharedStyles/core.less';
|
||||||
@import (less) '././././themes/fonts/5e/fonts.less';
|
@import (less) '../../../icons/customIcons.less';
|
||||||
|
@import (less) '@themes/fonts/5e/fonts.less';
|
||||||
|
|
||||||
.snippetBar {
|
.snippetBar {
|
||||||
|
--menuColor : #DDDDDD;
|
||||||
|
--textColor : black;
|
||||||
|
--hoverMenuColor : #999999;
|
||||||
|
|
||||||
@menuHeight : 25px;
|
@menuHeight : 25px;
|
||||||
position : relative;
|
position : relative;
|
||||||
display : flex;
|
display : flex;
|
||||||
flex-wrap : wrap-reverse;
|
flex-wrap : wrap-reverse;
|
||||||
justify-content : space-between;
|
justify-content : space-between;
|
||||||
height : auto;
|
height : auto;
|
||||||
color : black;
|
font-family : 'Open Sans', sans-serif;
|
||||||
background-color : #DDDDDD;
|
font-size : 0.65rem;
|
||||||
|
font-weight : 800;
|
||||||
.snippets {
|
color : var(--textColor);
|
||||||
display : flex;
|
text-transform : uppercase;
|
||||||
justify-content : flex-start;
|
background-color : var(--menuColor);
|
||||||
min-width : 499.35px; //must be controlled every time an item is added, must be hardcoded for the wrapping as it is applied
|
reading-flow : flex-visual;
|
||||||
}
|
|
||||||
|
|
||||||
.editors {
|
.editors {
|
||||||
display : flex;
|
display : flex;
|
||||||
justify-content : flex-end;
|
justify-content : flex-end;
|
||||||
min-width : 250px; //must be controlled every time an item is added, must be hardcoded for the wrapping as it is applied
|
min-width : 275px; //must be controlled every time an item is added, must be hardcoded for the wrapping as it is applied
|
||||||
|
font-size:0.85rem;
|
||||||
&:only-child {min-width : unset; margin-left : auto;}
|
&:only-child {min-width : unset; margin-left : auto;}
|
||||||
|
reading-order : 2;
|
||||||
|
|
||||||
>div {
|
>div {
|
||||||
display : flex;
|
display : flex;
|
||||||
@@ -31,7 +36,7 @@
|
|||||||
|
|
||||||
&:first-child { border-left : none; }
|
&:first-child { border-left : none; }
|
||||||
|
|
||||||
& > div {
|
& > button, & > li {
|
||||||
position : relative;
|
position : relative;
|
||||||
width : @menuHeight;
|
width : @menuHeight;
|
||||||
height : @menuHeight;
|
height : @menuHeight;
|
||||||
@@ -39,9 +44,9 @@
|
|||||||
text-align : center;
|
text-align : center;
|
||||||
cursor : pointer;
|
cursor : pointer;
|
||||||
|
|
||||||
&.editorTool:not(.active) { cursor : not-allowed; }
|
&.editorTool:not(.active),&.editorTool:disabled { cursor : not-allowed; }
|
||||||
|
|
||||||
&:hover,&.selected { background-color : #999999; }
|
&:hover,&.selected { background-color : var(--hoverMenuColor); }
|
||||||
&.text {
|
&.text {
|
||||||
.tooltipLeft('Brew Editor');
|
.tooltipLeft('Brew Editor');
|
||||||
}
|
}
|
||||||
@@ -54,37 +59,45 @@
|
|||||||
&.snippet {
|
&.snippet {
|
||||||
.tooltipLeft('Snippets');
|
.tooltipLeft('Snippets');
|
||||||
}
|
}
|
||||||
|
&.settings {
|
||||||
|
.tooltipLeft('Settings');
|
||||||
|
}
|
||||||
&.undo {
|
&.undo {
|
||||||
.tooltipLeft('Undo');
|
.tooltipLeft('Undo');
|
||||||
font-size : 0.75em;
|
|
||||||
color : grey;
|
color : grey;
|
||||||
&.active { color : inherit; }
|
&.active { color : inherit; }
|
||||||
}
|
}
|
||||||
&.redo {
|
&.redo {
|
||||||
.tooltipLeft('Redo');
|
.tooltipLeft('Redo');
|
||||||
font-size : 0.75em;
|
|
||||||
color : grey;
|
color : grey;
|
||||||
&.active { color : inherit; }
|
&.active { color : inherit; }
|
||||||
}
|
}
|
||||||
&.foldAll {
|
&.foldAll {
|
||||||
.tooltipLeft('Fold All');
|
.tooltipLeft('Fold All');
|
||||||
font-size : 0.75em;
|
|
||||||
color : grey;
|
color : grey;
|
||||||
&.active { color : inherit; }
|
&.active { color : inherit; }
|
||||||
}
|
}
|
||||||
&.unfoldAll {
|
&.unfoldAll {
|
||||||
.tooltipLeft('Unfold All');
|
.tooltipLeft('Unfold All');
|
||||||
font-size : 0.75em;
|
color : grey;
|
||||||
|
&.active { color : inherit; }
|
||||||
|
}
|
||||||
|
&.formatCode {
|
||||||
|
.tooltipLeft('Clean your Code');
|
||||||
color : grey;
|
color : grey;
|
||||||
&.active { color : inherit; }
|
&.active { color : inherit; }
|
||||||
}
|
}
|
||||||
&.history {
|
&.history {
|
||||||
|
font-size:.70rem;
|
||||||
|
|
||||||
|
i {
|
||||||
|
min-width:auto;
|
||||||
|
}
|
||||||
.tooltipLeft('History');
|
.tooltipLeft('History');
|
||||||
position : relative;
|
position : relative;
|
||||||
font-size : 0.75em;
|
|
||||||
color : grey;
|
color : grey;
|
||||||
border : none;
|
border : none;
|
||||||
&.active { color : inherit; }
|
&:not(:disabled) { color : inherit; }
|
||||||
& > .dropdown {
|
& > .dropdown {
|
||||||
right : -1px;
|
right : -1px;
|
||||||
& > .snippet { padding-right : 10px; }
|
& > .snippet { padding-right : 10px; }
|
||||||
@@ -92,18 +105,12 @@
|
|||||||
}
|
}
|
||||||
&.editorTheme {
|
&.editorTheme {
|
||||||
.tooltipLeft('Editor Themes');
|
.tooltipLeft('Editor Themes');
|
||||||
font-size : 0.75em;
|
|
||||||
color : inherit;
|
color : inherit;
|
||||||
&.active {
|
&.active {
|
||||||
position : relative;
|
position : relative;
|
||||||
background-color : #999999;
|
background-color : #999999;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&.divider {
|
|
||||||
width : 5px;
|
|
||||||
background : linear-gradient(currentColor, currentColor) no-repeat center/1px 100%;
|
|
||||||
&:hover { background-color : inherit; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.themeSelector {
|
.themeSelector {
|
||||||
position : absolute;
|
position : absolute;
|
||||||
@@ -119,23 +126,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.snippetBarButton {
|
|
||||||
display : inline-block;
|
|
||||||
height : @menuHeight;
|
|
||||||
padding : 0px 5px;
|
|
||||||
font-size : 0.625em;
|
|
||||||
font-weight : 800;
|
|
||||||
line-height : @menuHeight;
|
|
||||||
text-transform : uppercase;
|
|
||||||
text-wrap : nowrap;
|
|
||||||
cursor : pointer;
|
|
||||||
&:hover, &.selected { background-color : #999999; }
|
|
||||||
i {
|
|
||||||
margin-right : 3px;
|
|
||||||
font-size : 1.4em;
|
|
||||||
vertical-align : middle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.toggleMeta {
|
.toggleMeta {
|
||||||
position : absolute;
|
position : absolute;
|
||||||
top : 0px;
|
top : 0px;
|
||||||
@@ -143,112 +134,106 @@
|
|||||||
border-left : 1px solid black;
|
border-left : 1px solid black;
|
||||||
.tooltipLeft('Edit Brew Properties');
|
.tooltipLeft('Edit Brew Properties');
|
||||||
}
|
}
|
||||||
.snippetGroup {
|
|
||||||
|
|
||||||
&:hover {
|
.snippets {
|
||||||
& > .dropdown { visibility : visible; }
|
display : flex;
|
||||||
|
justify-content : flex-start;
|
||||||
|
min-width : 565.95px; //must be controlled every time an item is added, must be hardcoded for the wrapping as it is applied
|
||||||
|
reading-order : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// removed caret for top level items, by request (makes buttons too wide).
|
||||||
|
.menu-wrapper .menu-item:is(.snippets > .menu-wrapper > .menu-item):first-child .caret { display : none; }
|
||||||
|
|
||||||
|
.menu-item {
|
||||||
|
position : relative;
|
||||||
|
display : flex;
|
||||||
|
align-items : center;
|
||||||
|
justify-content : space-between;
|
||||||
|
width : 100%;
|
||||||
|
min-width : max-content;
|
||||||
|
padding : 5px;
|
||||||
|
cursor : pointer;
|
||||||
|
&:is(.menu-list .menu-item) [class*='name'] {
|
||||||
|
padding-inline : 8px; // additional space between icon and name (helpful in Fonts menu especially).
|
||||||
}
|
}
|
||||||
.dropdown {
|
.menu-name {
|
||||||
position : absolute;
|
flex : 1;
|
||||||
top : 100%;
|
text-align : left;
|
||||||
z-index : 1000;
|
text-box-trim : trim-end;
|
||||||
visibility : hidden;
|
}
|
||||||
padding : 0px;
|
i {
|
||||||
margin-left : -5px;
|
min-width : 25px;
|
||||||
background-color : #DDDDDD;
|
height : 0.85rem;
|
||||||
.snippet {
|
font-size : 1.2em;
|
||||||
position : relative;
|
text-align : center;
|
||||||
display : flex;
|
&.caret { margin-right : 0; }
|
||||||
align-items : center;
|
&.caret:is(.menu-wrapper .menu-wrapper *) { text-align : right; }
|
||||||
min-width : max-content;
|
/* Fonts */
|
||||||
padding : 5px;
|
&.font {
|
||||||
font-size : 10px;
|
height : auto;
|
||||||
cursor : pointer;
|
&::before {
|
||||||
.animate(background-color);
|
font-size : 1em;
|
||||||
i {
|
content : 'ABC';
|
||||||
min-width : 25px;
|
}
|
||||||
height : 1.2em;
|
|
||||||
margin-right : 8px;
|
|
||||||
font-size : 1.2em;
|
|
||||||
text-align : center;
|
|
||||||
& ~ i {
|
|
||||||
margin-right : 0;
|
|
||||||
margin-left : 5px;
|
|
||||||
}
|
|
||||||
/* Fonts */
|
|
||||||
&.font {
|
|
||||||
height : auto;
|
|
||||||
&::before {
|
|
||||||
font-size : 1em;
|
|
||||||
content : 'ABC';
|
|
||||||
}
|
|
||||||
|
|
||||||
&.OpenSans {font-family : 'OpenSans';}
|
&.OpenSans {font-family : 'OpenSans';}
|
||||||
&.CodeBold {font-family : 'CodeBold';}
|
&.CodeBold {font-family : 'CodeBold';}
|
||||||
&.CodeLight {font-family : 'CodeLight';}
|
&.CodeLight {font-family : 'CodeLight';}
|
||||||
&.ScalySansRemake {font-family : 'ScalySansRemake';}
|
&.ScalySansRemake {font-family : 'ScalySansRemake';}
|
||||||
&.BookInsanityRemake {font-family : 'BookInsanityRemake';}
|
&.BookInsanityRemake {font-family : 'BookInsanityRemake';}
|
||||||
&.MrEavesRemake {font-family : 'MrEavesRemake';}
|
&.MrEavesRemake {font-family : 'MrEavesRemake';}
|
||||||
&.SolberaImitationRemake {font-family : 'SolberaImitationRemake';}
|
&.SolberaImitationRemake {font-family : 'SolberaImitationRemake';}
|
||||||
&.ScalySansSmallCapsRemake {font-family : 'ScalySansSmallCapsRemake';}
|
&.ScalySansSmallCapsRemake {font-family : 'ScalySansSmallCapsRemake';}
|
||||||
&.WalterTurncoat {font-family : 'WalterTurncoat';}
|
&.WalterTurncoat {font-family : 'WalterTurncoat';}
|
||||||
&.Lato {font-family : 'Lato';}
|
&.Lato {font-family : 'Lato';}
|
||||||
&.Courier {font-family : 'Courier';}
|
&.Courier {font-family : 'Courier';}
|
||||||
&.NodestoCapsCondensed {font-family : 'NodestoCapsCondensed';}
|
&.NodestoCapsCondensed {font-family : 'NodestoCapsCondensed';}
|
||||||
&.Overpass {font-family : 'Overpass';}
|
&.Overpass {font-family : 'Overpass';}
|
||||||
&.Davek {font-family : 'Davek';}
|
&.Davek {font-family : 'Davek';}
|
||||||
&.Iokharic {font-family : 'Iokharic';}
|
&.Iokharic {font-family : 'Iokharic';}
|
||||||
&.Rellanic {font-family : 'Rellanic';}
|
&.Rellanic {font-family : 'Rellanic';}
|
||||||
&.TimesNewRoman {font-family : 'Times New Roman';}
|
&.TimesNewRoman {font-family : 'Times New Roman';}
|
||||||
}
|
|
||||||
}
|
|
||||||
.name { margin-right : auto; }
|
|
||||||
.disabled { text-decoration : line-through; }
|
|
||||||
.beta {
|
|
||||||
align-self : center;
|
|
||||||
padding : 4px 6px;
|
|
||||||
margin-left : 5px;
|
|
||||||
font-family : monospace;
|
|
||||||
line-height : 1em;
|
|
||||||
color : white;
|
|
||||||
background : grey;
|
|
||||||
border-radius : 12px;
|
|
||||||
}
|
|
||||||
&:hover {
|
|
||||||
background-color : #999999;
|
|
||||||
& > .dropdown {
|
|
||||||
visibility : visible;
|
|
||||||
&.side {
|
|
||||||
top : 0%;
|
|
||||||
left : 100%;
|
|
||||||
margin-left : 0;
|
|
||||||
box-shadow : -1px 1px 2px 0px #999999;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.name { margin-right : auto; }
|
||||||
|
.status {
|
||||||
|
align-self : center;
|
||||||
|
padding : 4px 6px;
|
||||||
|
margin-left : 5px;
|
||||||
|
font-family : monospace;
|
||||||
|
line-height : 1em;
|
||||||
|
color : white;
|
||||||
|
background : grey;
|
||||||
|
border-radius : 12px;
|
||||||
|
}
|
||||||
|
&:hover { background-color : var(--hoverMenuColor); }
|
||||||
|
&:disabled {
|
||||||
|
color : gray;
|
||||||
|
cursor : not-allowed;
|
||||||
|
&:hover { background-color : unset; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.disabledSnippets {
|
|
||||||
color: grey;
|
|
||||||
cursor: not-allowed;
|
|
||||||
|
|
||||||
&:hover { background-color: #DDDDDD;}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@container editor (width < 750px) {
|
@container editor (width < 841px) {
|
||||||
.snippetBar {
|
.snippetBar {
|
||||||
.editors {
|
.editors {
|
||||||
flex : 1;
|
flex : 1;
|
||||||
justify-content : space-between;
|
justify-content : space-between;
|
||||||
border-bottom : 1px solid;
|
border-bottom : 1px solid;
|
||||||
|
reading-order : 1;
|
||||||
}
|
}
|
||||||
.snippets {
|
.snippets {
|
||||||
flex : 1;
|
flex : 1;
|
||||||
justify-content : space-evenly;
|
justify-content : space-evenly;
|
||||||
|
reading-order : 2;
|
||||||
}
|
}
|
||||||
.editors > div.history > .dropdown { right : unset; }
|
.editors > div.history > .dropdown { right : unset; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.editor.darkMode .snippetBar {
|
||||||
|
--menuColor : #666666;
|
||||||
|
--textColor : #EEEEEE;
|
||||||
|
--hoverMenuColor : #444444;
|
||||||
|
}
|
||||||
@@ -0,0 +1,219 @@
|
|||||||
|
export const tagSuggestionList = [
|
||||||
|
// ############################## Systems
|
||||||
|
// D&D
|
||||||
|
'system:D&D Original',
|
||||||
|
'system:D&D Basic',
|
||||||
|
'system:AD&D 1e',
|
||||||
|
'system:AD&D 2e',
|
||||||
|
'system:D&D 3e',
|
||||||
|
'system:D&D 3.5e',
|
||||||
|
'system:D&D 4e',
|
||||||
|
'system:D&D 5e',
|
||||||
|
'system:D&D 5e 2024',
|
||||||
|
'system:BD&D (B/X)',
|
||||||
|
'system:D&D Essentials',
|
||||||
|
|
||||||
|
// Other Famous RPGs
|
||||||
|
'system:Pathfinder 1e',
|
||||||
|
'system:Pathfinder 2e',
|
||||||
|
'system:Vampire: The Masquerade',
|
||||||
|
'system:Werewolf: The Apocalypse',
|
||||||
|
'system:Mage: The Ascension',
|
||||||
|
'system:Call of Cthulhu',
|
||||||
|
'system:Shadowrun',
|
||||||
|
'system:Star Wars RPG (D6/D20/Edge of the Empire)',
|
||||||
|
'system:Warhammer Fantasy Roleplay',
|
||||||
|
'system:Cyberpunk 2020',
|
||||||
|
'system:Blades in the Dark',
|
||||||
|
'system:Daggerheart',
|
||||||
|
'system:Draw Steel',
|
||||||
|
'system:Mutants and Masterminds',
|
||||||
|
|
||||||
|
// Meta
|
||||||
|
'meta:V3',
|
||||||
|
'meta:Legacy',
|
||||||
|
'meta:Template',
|
||||||
|
'meta:Theme',
|
||||||
|
'meta:free',
|
||||||
|
'meta:Character Sheet',
|
||||||
|
'meta:Documentation',
|
||||||
|
'meta:NPC',
|
||||||
|
'meta:Guide',
|
||||||
|
'meta:Resource',
|
||||||
|
'meta:Notes',
|
||||||
|
'meta:Example',
|
||||||
|
|
||||||
|
// Book type
|
||||||
|
'type:Campaign',
|
||||||
|
'type:Campaign Setting',
|
||||||
|
'type:Adventure',
|
||||||
|
'type:One-Shot',
|
||||||
|
'type:Setting',
|
||||||
|
'type:World',
|
||||||
|
'type:Lore',
|
||||||
|
'type:History',
|
||||||
|
'type:Dungeon Master',
|
||||||
|
'type:Encounter Pack',
|
||||||
|
'type:Encounter',
|
||||||
|
'type:Session Notes',
|
||||||
|
'type:reference',
|
||||||
|
'type:Handbook',
|
||||||
|
'type:Manual',
|
||||||
|
'type:Manuals',
|
||||||
|
'type:Compendium',
|
||||||
|
'type:Bestiary',
|
||||||
|
|
||||||
|
// ###################################### RPG Keywords
|
||||||
|
|
||||||
|
// Classes / Subclasses / Archetypes
|
||||||
|
'Class',
|
||||||
|
'Subclass',
|
||||||
|
'Archetype',
|
||||||
|
'Martial',
|
||||||
|
'Half-Caster',
|
||||||
|
'Full Caster',
|
||||||
|
'Artificer',
|
||||||
|
'Barbarian',
|
||||||
|
'Bard',
|
||||||
|
'Cleric',
|
||||||
|
'Druid',
|
||||||
|
'Fighter',
|
||||||
|
'Monk',
|
||||||
|
'Paladin',
|
||||||
|
'Rogue',
|
||||||
|
'Sorcerer',
|
||||||
|
'Warlock',
|
||||||
|
'Wizard',
|
||||||
|
|
||||||
|
// Races / Species / Lineages
|
||||||
|
'Race',
|
||||||
|
'Ancestry',
|
||||||
|
'Lineage',
|
||||||
|
'Aasimar',
|
||||||
|
'Beastfolk',
|
||||||
|
'Dragonborn',
|
||||||
|
'Dwarf',
|
||||||
|
'Elf',
|
||||||
|
'Goblin',
|
||||||
|
'Half-Elf',
|
||||||
|
'Half-Orc',
|
||||||
|
'Human',
|
||||||
|
'Kobold',
|
||||||
|
'Lizardfolk',
|
||||||
|
'Lycan',
|
||||||
|
'Orc',
|
||||||
|
'Tiefling',
|
||||||
|
'Vampire',
|
||||||
|
'Yuan-Ti',
|
||||||
|
|
||||||
|
// Magic / Spells / Items
|
||||||
|
'Magic',
|
||||||
|
'Magic Item',
|
||||||
|
'Magic Items',
|
||||||
|
'Wondrous Item',
|
||||||
|
'Magic Weapon',
|
||||||
|
'Artifact',
|
||||||
|
'Spell',
|
||||||
|
'Spells',
|
||||||
|
'Cantrip',
|
||||||
|
'Cantrips',
|
||||||
|
'Eldritch',
|
||||||
|
'Eldritch Invocation',
|
||||||
|
'Invocation',
|
||||||
|
'Invocations',
|
||||||
|
'Pact boon',
|
||||||
|
'Pact Boon',
|
||||||
|
'Spellcaster',
|
||||||
|
'Spellblade',
|
||||||
|
'Magical Tattoos',
|
||||||
|
'Enchantment',
|
||||||
|
'Enchanted',
|
||||||
|
'Attunement',
|
||||||
|
'Requires Attunement',
|
||||||
|
'Rune',
|
||||||
|
'Runes',
|
||||||
|
'Wand',
|
||||||
|
'Rod',
|
||||||
|
'Scroll',
|
||||||
|
'Potion',
|
||||||
|
'Potions',
|
||||||
|
'Item',
|
||||||
|
'Items',
|
||||||
|
'Bag of Holding',
|
||||||
|
|
||||||
|
// Monsters / Creatures / Enemies
|
||||||
|
'Monster',
|
||||||
|
'Creatures',
|
||||||
|
'Creature',
|
||||||
|
'Beast',
|
||||||
|
'Beasts',
|
||||||
|
'Humanoid',
|
||||||
|
'Undead',
|
||||||
|
'Fiend',
|
||||||
|
'Aberration',
|
||||||
|
'Ooze',
|
||||||
|
'Giant',
|
||||||
|
'Dragon',
|
||||||
|
'Monstrosity',
|
||||||
|
'Demon',
|
||||||
|
'Devil',
|
||||||
|
'Elemental',
|
||||||
|
'Construct',
|
||||||
|
'Constructs',
|
||||||
|
'Boss',
|
||||||
|
'BBEG',
|
||||||
|
|
||||||
|
// ############################# Media / Pop Culture
|
||||||
|
'One Piece',
|
||||||
|
'Dragon Ball',
|
||||||
|
'Dragon Ball Z',
|
||||||
|
'Naruto',
|
||||||
|
'Jujutsu Kaisen',
|
||||||
|
'Fairy Tail',
|
||||||
|
'Final Fantasy',
|
||||||
|
'Kingdom Hearts',
|
||||||
|
'Elder Scrolls',
|
||||||
|
'Skyrim',
|
||||||
|
'WoW',
|
||||||
|
'World of Warcraft',
|
||||||
|
'Marvel Comics',
|
||||||
|
'DC Comics',
|
||||||
|
'Pokemon',
|
||||||
|
'League of Legends',
|
||||||
|
'Runeterra',
|
||||||
|
'Arcane',
|
||||||
|
'Yu-Gi-Oh',
|
||||||
|
'Minecraft',
|
||||||
|
'Don\'t Starve',
|
||||||
|
'Witcher',
|
||||||
|
'Witcher 3',
|
||||||
|
'Cyberpunk',
|
||||||
|
'Cyberpunk 2077',
|
||||||
|
'Fallout',
|
||||||
|
'Divinity Original Sin 2',
|
||||||
|
'Fullmetal Alchemist',
|
||||||
|
'Fullmetal Alchemist Brotherhood',
|
||||||
|
'Lobotomy Corporation',
|
||||||
|
'Bloodborne',
|
||||||
|
'Dragonlance',
|
||||||
|
'Shackled City Adventure Path',
|
||||||
|
'Baldurs Gate 3',
|
||||||
|
'Library of Ruina',
|
||||||
|
'Radiant Citadel',
|
||||||
|
'Ravenloft',
|
||||||
|
'Forgotten Realms',
|
||||||
|
'Exandria',
|
||||||
|
'Critical Role',
|
||||||
|
'Star Wars',
|
||||||
|
'SW5e',
|
||||||
|
'Star Wars 5e',
|
||||||
|
];
|
||||||
|
|
||||||
|
// substrings to be normalized to the first value on the array
|
||||||
|
export const canonizationList = [
|
||||||
|
['5e 2024', '5.5e', '5e\'24', '5.24', '5e24', '5.5'],
|
||||||
|
['5e', '5th Edition'],
|
||||||
|
['Dungeons & Dragons', 'Dungeons and Dragons', 'Dungeons n dragons'],
|
||||||
|
['D&D', 'DnD', 'dnd', 'Dnd', 'dnD', 'd&d', 'd&D', 'D&d'],
|
||||||
|
['P2e', 'p2e', 'P2E', 'Pathfinder 2e'],
|
||||||
|
];
|
||||||
@@ -1,105 +1,201 @@
|
|||||||
require('./tagInput.less');
|
import './tagInput.less';
|
||||||
const React = require('react');
|
import React, { useState, useEffect } from 'react';
|
||||||
const { useState, useEffect } = React;
|
import Combobox from '@components/combobox.jsx';
|
||||||
const _ = require('lodash');
|
|
||||||
|
|
||||||
const TagInput = ({ unique = true, values = [], ...props })=>{
|
import { tagSuggestionList, canonizationList } from './curatedTagSuggestionList.js';
|
||||||
const [tempInputText, setTempInputText] = useState('');
|
|
||||||
const [tagList, setTagList] = useState(values.map((value)=>({ value, editing: false })));
|
const TagInput = ({ id, tooltip, label, valuePatterns, values = [], unique = true, placeholder = '', smallText = '', onChange })=>{
|
||||||
|
const [tagList, setTagList] = useState(
|
||||||
|
values.map((value)=>({
|
||||||
|
value,
|
||||||
|
editing : false,
|
||||||
|
draft : '',
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
handleChange(tagList.map((context)=>context.value));
|
const incoming = values || [];
|
||||||
|
const current = tagList.map((t)=>t.value);
|
||||||
|
|
||||||
|
const changed = incoming.length !== current.length || incoming.some((v, i)=>v !== current[i]);
|
||||||
|
|
||||||
|
if(changed) {
|
||||||
|
setTagList(
|
||||||
|
incoming.map((value)=>({
|
||||||
|
value,
|
||||||
|
editing : false,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, [values]);
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
onChange?.({
|
||||||
|
target : { value: tagList.map((t)=>t.value) },
|
||||||
|
});
|
||||||
}, [tagList]);
|
}, [tagList]);
|
||||||
|
|
||||||
const handleChange = (value)=>{
|
const normalizeValue = (input)=>{
|
||||||
props.onChange({
|
const lowerInput = input.toLowerCase();
|
||||||
target : { value }
|
let normalizedTag = input;
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleInputKeyDown = ({ evt, value, index, options = {} })=>{
|
for (const group of canonizationList) {
|
||||||
if(_.includes(['Enter', ','], evt.key)) {
|
for (const tag of group) {
|
||||||
evt.preventDefault();
|
if(!tag) continue;
|
||||||
submitTag(evt.target.value, value, index);
|
|
||||||
if(options.clear) {
|
const index = lowerInput.indexOf(tag.toLowerCase());
|
||||||
setTempInputText('');
|
if(index !== -1) {
|
||||||
|
normalizedTag = input.slice(0, index) + group[0] + input.slice(index + tag.length);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(normalizedTag.includes(':')) {
|
||||||
|
const [rawType, rawValue = ''] = normalizedTag.split(':');
|
||||||
|
const tagType = rawType.trim().toLowerCase();
|
||||||
|
const tagValue = rawValue.trim();
|
||||||
|
|
||||||
|
if(tagValue.length > 0) {
|
||||||
|
normalizedTag = `${tagType}:${tagValue[0].toUpperCase()}${tagValue.slice(1)}`;
|
||||||
|
}
|
||||||
|
//trims spaces around colon and capitalizes the first word after the colon
|
||||||
|
//this is preferred to users not understanding they can't put spaces in
|
||||||
|
}
|
||||||
|
|
||||||
|
return normalizedTag;
|
||||||
};
|
};
|
||||||
|
|
||||||
const submitTag = (newValue, originalValue, index)=>{
|
const submitTag = (newValue, index = null)=>{
|
||||||
setTagList((prevContext)=>{
|
const trimmed = newValue?.trim();
|
||||||
// remove existing tag
|
if(!trimmed) return;
|
||||||
if(newValue === null){
|
if(!valuePatterns.test(trimmed)) return;
|
||||||
return [...prevContext].filter((context, i)=>i !== index);
|
|
||||||
|
const normalizedTag = normalizeValue(trimmed);
|
||||||
|
|
||||||
|
setTagList((prev)=>{
|
||||||
|
const existsIndex = prev.findIndex((t)=>t.value.toLowerCase() === normalizedTag.toLowerCase());
|
||||||
|
if(unique && existsIndex !== -1) return prev;
|
||||||
|
if(index !== null) {
|
||||||
|
return prev.map((t, i)=>(i === index ? { ...t, value: normalizedTag, editing: false } : t));
|
||||||
}
|
}
|
||||||
// add new tag
|
|
||||||
if(originalValue === null){
|
return [...prev, { value: normalizedTag, editing: false }];
|
||||||
return [...prevContext, { value: newValue, editing: false }];
|
|
||||||
}
|
|
||||||
// update existing tag
|
|
||||||
return prevContext.map((context, i)=>{
|
|
||||||
if(i === index) {
|
|
||||||
return { ...context, value: newValue, editing: false };
|
|
||||||
}
|
|
||||||
return context;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const removeTag = (index)=>{
|
||||||
|
setTagList((prev)=>prev.filter((_, i)=>i !== index));
|
||||||
|
};
|
||||||
|
|
||||||
const editTag = (index)=>{
|
const editTag = (index)=>{
|
||||||
setTagList((prevContext)=>{
|
setTagList((prev)=>prev.map((t, i)=>(i === index ? { ...t, editing: true, draft: t.value } : t)));
|
||||||
return prevContext.map((context, i)=>{
|
|
||||||
if(i === index) {
|
|
||||||
return { ...context, editing: true };
|
|
||||||
}
|
|
||||||
return { ...context, editing: false };
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderReadTag = (context, index)=>{
|
const stopEditing = (index)=>{
|
||||||
return (
|
setTagList((prev)=>prev.map((t, i)=>(i === index ? { ...t, editing: false, draft: '' } : t)));
|
||||||
<li key={index}
|
|
||||||
data-value={context.value}
|
|
||||||
className='tag'
|
|
||||||
onClick={()=>editTag(index)}>
|
|
||||||
{context.value}
|
|
||||||
<button onClick={(evt)=>{evt.stopPropagation(); submitTag(null, context.value, index);}}><i className='fa fa-times fa-fw'/></button>
|
|
||||||
</li>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderWriteTag = (context, index)=>{
|
const suggestionOptions = tagSuggestionList.map((tag)=>{
|
||||||
|
const tagType = tag.split(':');
|
||||||
|
|
||||||
|
let classes = 'item';
|
||||||
|
switch (tagType[0]) {
|
||||||
|
case 'type':
|
||||||
|
classes = 'item type';
|
||||||
|
break;
|
||||||
|
case 'group':
|
||||||
|
classes = 'item group';
|
||||||
|
break;
|
||||||
|
case 'meta':
|
||||||
|
classes = 'item meta';
|
||||||
|
break;
|
||||||
|
case 'system':
|
||||||
|
classes = 'item system';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
classes = 'item';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<input type='text'
|
<div className={classes} key={`tag-${tag}`} value={tag} data={tag}>
|
||||||
key={index}
|
{tag}
|
||||||
defaultValue={context.value}
|
</div>
|
||||||
onKeyDown={(evt)=>handleInputKeyDown({ evt, value: context.value, index: index })}
|
|
||||||
autoFocus
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
};
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='field'>
|
<div className='tagInputWrap'>
|
||||||
<label>{props.label}</label>
|
<Combobox
|
||||||
<div className='value'>
|
id={id}
|
||||||
<ul className='list'>
|
trigger='click'
|
||||||
{tagList.map((context, index)=>{ return context.editing ? renderWriteTag(context, index) : renderReadTag(context, index); })}
|
className='tagInput-dropdown'
|
||||||
</ul>
|
defaultValue=''
|
||||||
|
placeholder={placeholder}
|
||||||
<input
|
options={label === 'tags' ? suggestionOptions : []}
|
||||||
type='text'
|
tooltip={tooltip}
|
||||||
className='value'
|
autoSuggest={
|
||||||
placeholder={props.placeholder}
|
label === 'tags'
|
||||||
value={tempInputText}
|
? {
|
||||||
onChange={(e)=>setTempInputText(e.target.value)}
|
suggestMethod : 'startsWith',
|
||||||
onKeyDown={(evt)=>handleInputKeyDown({ evt, value: null, options: { clear: true } })}
|
clearAutoSuggestOnClick : true,
|
||||||
/>
|
filterOn : ['value', 'title'],
|
||||||
</div>
|
}
|
||||||
|
: { suggestMethod: 'includes', clearAutoSuggestOnClick: true, filterOn: [] }
|
||||||
|
}
|
||||||
|
valuePatterns={valuePatterns.source}
|
||||||
|
onSelect={(value)=>submitTag(value)}
|
||||||
|
onEntry={(e)=>{
|
||||||
|
if(e.key === 'Enter') {
|
||||||
|
e.preventDefault();
|
||||||
|
submitTag(e.target.value);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<ul className='list'>
|
||||||
|
{tagList.map((t, i)=>t.editing ? (
|
||||||
|
<input
|
||||||
|
id={`${id}-${i}`}
|
||||||
|
key={i}
|
||||||
|
type='text'
|
||||||
|
value={t.draft} // always use draft
|
||||||
|
pattern={valuePatterns.source}
|
||||||
|
onChange={(e)=>setTagList((prev)=>prev.map((tag, idx)=>(idx === i ? { ...tag, draft: e.target.value } : tag)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onKeyDown={(e)=>{
|
||||||
|
if(e.key === 'Enter') {
|
||||||
|
e.preventDefault();
|
||||||
|
submitTag(t.draft, i); // submit draft
|
||||||
|
setTagList((prev)=>prev.map((tag, idx)=>(idx === i ? { ...tag, draft: '' } : tag)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if(e.key === 'Escape') {
|
||||||
|
stopEditing(i);
|
||||||
|
e.target.blur();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
autoFocus
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<li key={i} className='tag' onClick={()=>editTag(i)}>
|
||||||
|
{t.value}
|
||||||
|
<button
|
||||||
|
type='button'
|
||||||
|
aria-label={`remove ${t.value} tag`}
|
||||||
|
onClick={(e)=>{
|
||||||
|
e.stopPropagation();
|
||||||
|
removeTag(i);
|
||||||
|
}}>
|
||||||
|
<i className='fa fa-times fa-fw' />
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
),
|
||||||
|
)}
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = TagInput;
|
export default TagInput;
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
.tags {
|
||||||
|
|
||||||
|
.tagInputWrap {
|
||||||
|
display : grid;
|
||||||
|
grid-template-columns : 200px 3fr;
|
||||||
|
gap : 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list input { border-radius : 5px; }
|
||||||
|
|
||||||
|
.tagInput-dropdown {
|
||||||
|
.dropdown-options {
|
||||||
|
.item {
|
||||||
|
&.type { background-color : #00800035; }
|
||||||
|
&.group { background-color : #50505035; }
|
||||||
|
&.meta { background-color : #00008035; }
|
||||||
|
&.system { background-color : #80000035; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,438 @@
|
|||||||
|
@import '@themes/assets/assets.less';
|
||||||
|
@import '@sharedStyles/core.less';
|
||||||
|
|
||||||
|
.userThemeName {
|
||||||
|
padding-right : 10px;
|
||||||
|
padding-left : 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uiEditor {
|
||||||
|
--bg-clr : white;
|
||||||
|
--bg-image : @backgroundImageAlt;
|
||||||
|
--h1-clr : black;
|
||||||
|
--h2-clr : #000077;
|
||||||
|
--label-clr : black;
|
||||||
|
--input-bg : white;
|
||||||
|
--input-bg-hover : #DDDDDD;
|
||||||
|
--input-text-clr : black;
|
||||||
|
--input-placeholder-clr : grey;
|
||||||
|
|
||||||
|
position : absolute;
|
||||||
|
box-sizing : border-box;
|
||||||
|
width : 100%;
|
||||||
|
height : calc(100vh - 54px); // 54px is the height of the navbar + snippet bar. probably a better way to dynamic get this.
|
||||||
|
padding : 25px;
|
||||||
|
overflow-y : auto;
|
||||||
|
font-size : 13px;
|
||||||
|
color : var(--label-clr);
|
||||||
|
background-color : var(--bg-clr);
|
||||||
|
background-image : var(--bg-image);
|
||||||
|
background-size : cover;
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
margin : 0 0 40px;
|
||||||
|
font-size : 18px;
|
||||||
|
font-weight : bold;
|
||||||
|
color : var(--h1-clr);
|
||||||
|
text-transform : uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2 {
|
||||||
|
margin : 16px 0;
|
||||||
|
font-size : 15px;
|
||||||
|
font-weight : bold;
|
||||||
|
color : var(--h2-clr);
|
||||||
|
border-bottom : 2px solid currentColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
& > div ,& > fieldset { margin-bottom : 10px; }
|
||||||
|
|
||||||
|
.field-group {
|
||||||
|
display : flex;
|
||||||
|
flex-wrap : wrap;
|
||||||
|
gap : 10px;
|
||||||
|
width : 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-column {
|
||||||
|
display : flex;
|
||||||
|
flex : 5 0 250px;
|
||||||
|
flex-direction : column;
|
||||||
|
gap : 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field {
|
||||||
|
position : relative;
|
||||||
|
display : flex;
|
||||||
|
flex-wrap : wrap;
|
||||||
|
width : 100%;
|
||||||
|
min-width : 250px;
|
||||||
|
padding-left : 10px;
|
||||||
|
|
||||||
|
& > label {
|
||||||
|
width : 100px;
|
||||||
|
font-size : 1em;
|
||||||
|
font-weight : 800;
|
||||||
|
line-height : 1.8em;
|
||||||
|
color : inherit;
|
||||||
|
text-transform : capitalize;
|
||||||
|
}
|
||||||
|
& > .value {
|
||||||
|
flex : 1 1 auto;
|
||||||
|
width : 50px;
|
||||||
|
&[data-tooltip-right] { max-width : 380px; }
|
||||||
|
&:invalid { background : #FFB9B9; }
|
||||||
|
small {
|
||||||
|
display : block;
|
||||||
|
width : fit-content;
|
||||||
|
margin-inline : 5px;
|
||||||
|
font-size : 0.9em;
|
||||||
|
font-style : italic;
|
||||||
|
line-height : 1.4em;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='checkbox'], input[type='number'] {
|
||||||
|
float : right;
|
||||||
|
text-align : end;
|
||||||
|
}
|
||||||
|
input[type='text'], textarea, select {
|
||||||
|
color : var(--input-text-clr);
|
||||||
|
background-color : var(--input-bg);
|
||||||
|
border : 1px solid var(--input-placeholder-clr);
|
||||||
|
&:hover, :focus { outline : 1px solid var(--input-placeholder-clr); background-color : var(--input-bg-hover); }
|
||||||
|
&::placeholder { color : var(--input-placeholder-clr); }
|
||||||
|
}
|
||||||
|
|
||||||
|
input[type='range'] { color : var(--input-text-clr); }
|
||||||
|
|
||||||
|
&.description {
|
||||||
|
flex : 1;
|
||||||
|
textarea.value {
|
||||||
|
height : auto;
|
||||||
|
font-family : 'Open Sans', sans-serif;
|
||||||
|
resize : none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&.thumbnail, &.themes {
|
||||||
|
label { line-height : 2.0em; }
|
||||||
|
.value {
|
||||||
|
overflow : hidden;
|
||||||
|
text-overflow : ellipsis;
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
.colorButton();
|
||||||
|
padding : 0px 5px;
|
||||||
|
color : var(--input-text-clr);
|
||||||
|
background-color : var(--input-bg);
|
||||||
|
border : 1px solid #999999;
|
||||||
|
&:hover { background-color : #777777; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&.tags .tagInput-dropdown {
|
||||||
|
z-index : 400;
|
||||||
|
max-width : 200px;
|
||||||
|
|
||||||
|
.dropdown-options {
|
||||||
|
color : var(--input-text-clr);
|
||||||
|
background-color : var(--input-bg);
|
||||||
|
|
||||||
|
.item:hover {
|
||||||
|
color : var(--input-bg);
|
||||||
|
background-color : var(--input-text-clr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&.language .value {
|
||||||
|
z-index : 300;
|
||||||
|
max-width : 150px;
|
||||||
|
}
|
||||||
|
&.themes {
|
||||||
|
.value { overflow : visible; }
|
||||||
|
button {
|
||||||
|
padding-right : 5px;
|
||||||
|
padding-left : 5px;
|
||||||
|
}
|
||||||
|
& .dropdown-container { z-index : 200; }
|
||||||
|
& .dropdown-options { overflow-y : visible; }
|
||||||
|
.disabled {
|
||||||
|
font-style : italic;
|
||||||
|
color : dimgray;
|
||||||
|
background-color : darkgray;
|
||||||
|
}
|
||||||
|
.item.dropdown-input { border : none;}
|
||||||
|
.item {
|
||||||
|
position : relative;
|
||||||
|
overflow : visible;
|
||||||
|
color : inherit;
|
||||||
|
background-color : var(--input-bg);
|
||||||
|
border-top : 1px solid #767676;
|
||||||
|
.preview {
|
||||||
|
position : absolute;
|
||||||
|
top : 0;
|
||||||
|
right : 0;
|
||||||
|
z-index : 10;
|
||||||
|
display : flex;
|
||||||
|
flex-direction : column;
|
||||||
|
width : 200px;
|
||||||
|
overflow : hidden;
|
||||||
|
color : var(--input-text-clr);
|
||||||
|
background : var(--input-bg);
|
||||||
|
border-radius : 5px;
|
||||||
|
box-shadow : 0 0 5px var(--input-text-clr);
|
||||||
|
opacity : 0;
|
||||||
|
transition : opacity 250ms ease;
|
||||||
|
h6 {
|
||||||
|
padding-block : 0.5em;
|
||||||
|
padding-inline : 1em;
|
||||||
|
font-weight : 900;
|
||||||
|
border-bottom : 2px solid #666666;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
input { padding-right : 25px; }
|
||||||
|
|
||||||
|
.texture-container {
|
||||||
|
position : absolute;
|
||||||
|
top : 0;
|
||||||
|
left : 0;
|
||||||
|
width : 100%;
|
||||||
|
height : 100%;
|
||||||
|
min-height : 100%;
|
||||||
|
overflow : hidden;
|
||||||
|
> img {
|
||||||
|
position : absolute;
|
||||||
|
top : 0;
|
||||||
|
right : 0;
|
||||||
|
width : 50%;
|
||||||
|
min-height : 100%;
|
||||||
|
-webkit-mask-image : linear-gradient(90deg, transparent, black 20%);
|
||||||
|
mask-image : linear-gradient(90deg, transparent, black 20%);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover > .preview { opacity : 1; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&.renderers .value {
|
||||||
|
label {
|
||||||
|
display : inline-flex;
|
||||||
|
align-items : center;
|
||||||
|
margin-right : 15px;
|
||||||
|
font-size : 0.9em;
|
||||||
|
font-weight : 800;
|
||||||
|
vertical-align : middle;
|
||||||
|
white-space : nowrap;
|
||||||
|
cursor : pointer;
|
||||||
|
user-select : none;
|
||||||
|
}
|
||||||
|
input {
|
||||||
|
margin : 3px;
|
||||||
|
vertical-align : middle;
|
||||||
|
cursor : pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.authors {
|
||||||
|
.tag {
|
||||||
|
font-weight : 300;
|
||||||
|
transition : background-color 0.2s;
|
||||||
|
|
||||||
|
&.owner {
|
||||||
|
position : relative;
|
||||||
|
display : grid;
|
||||||
|
place-items : center;
|
||||||
|
min-width : 25px;
|
||||||
|
font-weight : 900;
|
||||||
|
background-color : @silverLight;
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
position : absolute;
|
||||||
|
top : 0;
|
||||||
|
left : 0;
|
||||||
|
width : 15px;
|
||||||
|
height : 15px;
|
||||||
|
font-family : 'Font Awesome 6 Free';
|
||||||
|
color : gold;
|
||||||
|
content : '\f521';
|
||||||
|
transform : scaleY(0.7);
|
||||||
|
rotate : -25deg;
|
||||||
|
translate : -30% -50%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&:has(button) a { padding-right : 5px; }
|
||||||
|
&:has(button:hover) { background : #D97D7D; }
|
||||||
|
|
||||||
|
button { color : @red; }
|
||||||
|
|
||||||
|
}
|
||||||
|
a { text-underline-offset : 0.2em; }
|
||||||
|
}
|
||||||
|
&.invitedAuthors .value {
|
||||||
|
z-index : 100;
|
||||||
|
|
||||||
|
.tagInput-dropdown { max-width : 200px; }
|
||||||
|
}
|
||||||
|
|
||||||
|
&.publish .value {
|
||||||
|
position : relative;
|
||||||
|
margin-bottom : 15px;
|
||||||
|
button { width : 100%; }
|
||||||
|
button.publish {
|
||||||
|
.colorButton(@blueLight);
|
||||||
|
}
|
||||||
|
button.unpublish {
|
||||||
|
.colorButton(@silver);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&.delete .value {
|
||||||
|
button {
|
||||||
|
.colorButton(@red);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.list {
|
||||||
|
display : flex;
|
||||||
|
flex : 1 0;
|
||||||
|
flex-wrap : wrap;
|
||||||
|
|
||||||
|
> * { flex : 0 0 auto; }
|
||||||
|
|
||||||
|
#groupedIcon {
|
||||||
|
#backgroundColors;
|
||||||
|
position : relative;
|
||||||
|
top : -0.3em;
|
||||||
|
right : -0.3em;
|
||||||
|
display : inline-block;
|
||||||
|
min-width : 20px;
|
||||||
|
height : ~'calc(100% + 0.6em)';
|
||||||
|
color : white;
|
||||||
|
text-align : center;
|
||||||
|
cursor : pointer;
|
||||||
|
|
||||||
|
i {
|
||||||
|
position : relative;
|
||||||
|
top : 50%;
|
||||||
|
transform : translateY(-50%);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:not(:last-child) { border-right : 1px solid black; }
|
||||||
|
|
||||||
|
&:last-child { border-radius : 0 0.5em 0.5em 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag {
|
||||||
|
padding : 0.35em;
|
||||||
|
margin : 2px;
|
||||||
|
font-size : 0.95em;
|
||||||
|
border-radius : 0.5em;
|
||||||
|
|
||||||
|
.icon { #groupedIcon; }
|
||||||
|
|
||||||
|
button {
|
||||||
|
cursor : pointer;
|
||||||
|
|
||||||
|
&:hover { color : @redLight; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-group {
|
||||||
|
height : ~'calc(.9em + 4px + .6em)';
|
||||||
|
|
||||||
|
input { border-radius : 0.5em 0 0 0.5em; }
|
||||||
|
|
||||||
|
input:last-child { border-radius : 0.5em; }
|
||||||
|
|
||||||
|
.value {
|
||||||
|
width : 7.5vw;
|
||||||
|
min-width : 75px;
|
||||||
|
height : 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-group {
|
||||||
|
height : ~'calc(.9em + 4px + .6em)';
|
||||||
|
|
||||||
|
input { border-radius : 0.5em 0 0 0.5em; }
|
||||||
|
|
||||||
|
input:last-child { border-radius : 0.5em; }
|
||||||
|
|
||||||
|
.value {
|
||||||
|
width : 7.5vw;
|
||||||
|
min-width : 75px;
|
||||||
|
height : 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.invalid:focus { background-color : pink; }
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
#groupedIcon;
|
||||||
|
top : -0.54em;
|
||||||
|
right : 1px;
|
||||||
|
height : 97%;
|
||||||
|
|
||||||
|
i { font-size : 1.125em; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.thumbnail-preview {
|
||||||
|
position : relative;
|
||||||
|
flex : 1 1;
|
||||||
|
justify-self : center;
|
||||||
|
width : 80px;
|
||||||
|
height : min-content;
|
||||||
|
max-height : 115px;
|
||||||
|
aspect-ratio : 1 / 1;
|
||||||
|
object-fit : contain;
|
||||||
|
background-color : #AAAAAA;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag {
|
||||||
|
color : var(--input-bg);
|
||||||
|
background : var(--input-text-clr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.settingsEditor .field {
|
||||||
|
padding-bottom : 10px;
|
||||||
|
border-bottom : 1px solid black;
|
||||||
|
|
||||||
|
.value {
|
||||||
|
|
||||||
|
display : flex;
|
||||||
|
justify-content : end;
|
||||||
|
}
|
||||||
|
|
||||||
|
> label {
|
||||||
|
width : fit-content;
|
||||||
|
max-width : calc(100% - 200px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.editor.darkMode .uiEditor {
|
||||||
|
--bg-clr : #555555;
|
||||||
|
--bg-image : @backgroundImageAltDark;
|
||||||
|
--h1-clr : white;
|
||||||
|
--h2-clr : #AAAAFF;
|
||||||
|
--label-clr : #DDDDDD;
|
||||||
|
--input-bg : #333333;
|
||||||
|
--input-bg-hover : #666666;
|
||||||
|
--input-text-clr : #EEEEEE;
|
||||||
|
--input-placeholder-clr : #AAAAAA;
|
||||||
|
|
||||||
|
.field { border-color : var(--h1-clr); }
|
||||||
|
|
||||||
|
a {
|
||||||
|
color : @blueLight;
|
||||||
|
|
||||||
|
&:visited { color : #CB8AD8; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.thumbnail-preview[src='/client/homebrew/thumbnail.png'] { filter : invert(0.8); }
|
||||||
|
button.publish {
|
||||||
|
.colorButton(#3137de) !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
/* eslint-disable camelcase */
|
import 'core-js/es/string/to-well-formed.js'; // Polyfill for older browsers
|
||||||
import 'core-js/es/string/to-well-formed.js'; //Polyfill for older browsers
|
|
||||||
import './homebrew.less';
|
import './homebrew.less';
|
||||||
import React from 'react';
|
import { BrowserRouter as Router, Routes, Route, useParams, useSearchParams } from 'react-router';
|
||||||
import { StaticRouter as Router, Route, Routes, useParams, useSearchParams } from 'react-router';
|
|
||||||
|
|
||||||
import { updateLocalStorage } from './utils/updateLocalStorage/updateLocalStorageKeys.js';
|
import { updateLocalStorage } from './utils/updateLocalStorage/updateLocalStorageKeys.js';
|
||||||
|
|
||||||
@@ -19,6 +17,7 @@ const WithRoute = ({ el: Element, ...rest })=>{
|
|||||||
const params = useParams();
|
const params = useParams();
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const queryParams = Object.fromEntries(searchParams?.entries() || []);
|
const queryParams = Object.fromEntries(searchParams?.entries() || []);
|
||||||
|
queryParams.tag = searchParams.getAll('tag');
|
||||||
return <Element {...rest} {...params} query={queryParams} />;
|
return <Element {...rest} {...params} query={queryParams} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -38,46 +37,66 @@ const Homebrew = (props)=>{
|
|||||||
lang : ''
|
lang : ''
|
||||||
},
|
},
|
||||||
userThemes,
|
userThemes,
|
||||||
brews
|
brews,
|
||||||
|
enablev4
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
global.account = account;
|
global.account = account;
|
||||||
global.version = version;
|
global.version = version;
|
||||||
global.config = config;
|
global.config = config;
|
||||||
|
global.enablev4 = enablev4;
|
||||||
|
|
||||||
const backgroundObject = ()=>{
|
const backgroundObject = ()=>{
|
||||||
if(global.config.deployment || (config.local && config.development)){
|
if(config?.deployment || config?.developmentStyle) {
|
||||||
const bgText = global.config.deployment || 'Local';
|
const bgText = config?.deployment || 'Local';
|
||||||
return {
|
return {
|
||||||
backgroundImage : `url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' height='100px' width='200px'><text x='0' y='15' fill='%23fff7' font-size='20'>${bgText}</text></svg>")`
|
backgroundImage : `url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' height='100px' width='200px'><text x='0' y='15' fill='%23fff7' font-size='20'>${bgText}</text></svg>")`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
updateLocalStorage();
|
updateLocalStorage();
|
||||||
|
|
||||||
|
if(brew.pureError) {
|
||||||
|
return (
|
||||||
|
<Router>
|
||||||
|
<div className={`homebrew${(config?.deployment || config?.developmentStyle) ? ' deployment' : ''}`} style={backgroundObject()}>
|
||||||
|
<Routes>
|
||||||
|
<Route path={brew.originalUrl} element={<WithRoute el={ErrorPage} brew={brew} />} />
|
||||||
|
</Routes>
|
||||||
|
</div>
|
||||||
|
</Router>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Router location={url}>
|
<Router>
|
||||||
<div className={`homebrew${(config.deployment || config.local) ? ' deployment' : ''}`} style={backgroundObject()}>
|
<div className={`homebrew${(config?.deployment || config?.developmentStyle) ? ' deployment' : ''}`} style={backgroundObject()}>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path='/edit/:id' element={<WithRoute el={EditPage} brew={brew} userThemes={userThemes}/>} />
|
<Route path='/' element={<WithRoute el={HomePage} brew={brew} />} />
|
||||||
<Route path='/share/:id' element={<WithRoute el={SharePage} brew={brew} />} />
|
<Route path='/*' element={<WithRoute el={HomePage} brew={brew} />} />
|
||||||
<Route path='/new/:id' element={<WithRoute el={NewPage} brew={brew} userThemes={userThemes}/>} />
|
|
||||||
<Route path='/new' element={<WithRoute el={NewPage} userThemes={userThemes}/> } />
|
|
||||||
<Route path='/user/:username' element={<WithRoute el={UserPage} brews={brews} />} />
|
|
||||||
<Route path='/vault' element={<WithRoute el={VaultPage}/>}/>
|
|
||||||
<Route path='/changelog' element={<WithRoute el={SharePage} brew={brew} disableMeta={true} />} />
|
|
||||||
<Route path='/faq' element={<WithRoute el={SharePage} brew={brew} disableMeta={true} />} />
|
|
||||||
<Route path='/migrate' element={<WithRoute el={SharePage} brew={brew} disableMeta={true} />} />
|
|
||||||
<Route path='/account' element={<WithRoute el={AccountPage} brew={brew} accountDetails={brew.accountDetails} />} />
|
|
||||||
<Route path='/legacy' element={<WithRoute el={HomePage} brew={brew} />} />
|
<Route path='/legacy' element={<WithRoute el={HomePage} brew={brew} />} />
|
||||||
<Route path='/error' element={<WithRoute el={ErrorPage} brew={brew} />} />
|
|
||||||
<Route path='/' element={<WithRoute el={HomePage} brew={brew} />} />
|
<Route path='/new/:id' element={<WithRoute el={NewPage} brew={brew} userThemes={userThemes}/>} />
|
||||||
<Route path='/*' element={<WithRoute el={HomePage} brew={brew} />} />
|
<Route path='/new' element={<WithRoute el={NewPage} userThemes={userThemes}/> } />
|
||||||
|
|
||||||
|
<Route path='/edit/:id' element={<WithRoute el={EditPage} brew={brew} userThemes={userThemes}/>} />
|
||||||
|
|
||||||
|
<Route path='/share/:id' element={<WithRoute el={SharePage} brew={brew} />} />
|
||||||
|
<Route path='/changelog' element={<WithRoute el={SharePage} brew={brew} disableMeta={true} />} />
|
||||||
|
<Route path='/faq' element={<WithRoute el={SharePage} brew={brew} disableMeta={true} />} />
|
||||||
|
<Route path='/migrate' element={<WithRoute el={SharePage} brew={brew} disableMeta={true} />} />
|
||||||
|
|
||||||
|
<Route path='/account' element={<WithRoute el={AccountPage} brew={brew} accountDetails={brew.accountDetails} />} />
|
||||||
|
<Route path='/error' element={<WithRoute el={ErrorPage} brew={brew} />} />
|
||||||
|
|
||||||
|
<Route path='/user/:username' element={<WithRoute el={UserPage} brews={brews} />} />
|
||||||
|
<Route path='/vault' element={<WithRoute el={VaultPage}/>}/>
|
||||||
</Routes>
|
</Routes>
|
||||||
</div>
|
</div>
|
||||||
</Router>
|
</Router>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Homebrew;
|
export default Homebrew;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
@import 'naturalcrit/styles/core.less';
|
@import '@sharedStyles/core.less';
|
||||||
.homebrew {
|
.homebrew {
|
||||||
height : 100%;
|
height : 100%;
|
||||||
background-color:@steel;
|
background-color : @steel;
|
||||||
&.deployment { background-color : darkred; }
|
&.deployment { background-color : darkred; }
|
||||||
|
|
||||||
.sitePage {
|
.sitePage {
|
||||||
@@ -15,21 +15,5 @@
|
|||||||
height : calc(~'100% - 29px'); //Navbar height
|
height : calc(~'100% - 29px'); //Navbar height
|
||||||
overflow-y : hidden;
|
overflow-y : hidden;
|
||||||
}
|
}
|
||||||
&.listPage .content {
|
|
||||||
overflow-y : scroll;
|
|
||||||
|
|
||||||
&::-webkit-scrollbar {
|
|
||||||
width : 20px;
|
|
||||||
&:horizontal {
|
|
||||||
width : auto;
|
|
||||||
height : 20px;
|
|
||||||
}
|
|
||||||
&-thumb {
|
|
||||||
background : linear-gradient(90deg, #D3C1AF 15px, #00000000 15px);
|
|
||||||
&:horizontal { background : linear-gradient(0deg, #D3C1AF 15px, #00000000 15px); }
|
|
||||||
}
|
|
||||||
&-corner { visibility : hidden; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { createRoot } from 'react-dom/client';
|
||||||
|
import Homebrew from './homebrew.jsx';
|
||||||
|
import { bootstrapAnchorPositioningPolyfill } from '@components/anchorPositioningPolyfill.js';
|
||||||
|
|
||||||
|
const props = window.__INITIAL_PROPS__ || {};
|
||||||
|
|
||||||
|
createRoot(document.getElementById('reactRoot')).render(<Homebrew {...props} />);
|
||||||
|
bootstrapAnchorPositioningPolyfill();
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
const React = require('react');
|
import React from 'react';
|
||||||
const createClass = require('create-react-class');
|
import createReactClass from 'create-react-class';
|
||||||
const Nav = require('client/homebrew/navbar/nav.jsx');
|
import request from 'superagent';
|
||||||
const request = require('superagent');
|
import Nav from './nav.jsx';
|
||||||
|
|
||||||
const Account = createClass({
|
const Account = createReactClass({
|
||||||
displayName : 'AccountNavItem',
|
displayName : 'AccountNavItem',
|
||||||
getInitialState : function() {
|
getInitialState : function() {
|
||||||
return {
|
return {
|
||||||
@@ -97,7 +97,7 @@ const Account = createClass({
|
|||||||
|
|
||||||
// Logged out
|
// Logged out
|
||||||
// LOCAL ONLY
|
// LOCAL ONLY
|
||||||
if(global.config.local) {
|
if(global.config?.local) {
|
||||||
return <Nav.item color='teal' icon='fas fa-sign-in-alt' onClick={this.localLogin}>
|
return <Nav.item color='teal' icon='fas fa-sign-in-alt' onClick={this.localLogin}>
|
||||||
login
|
login
|
||||||
</Nav.item>;
|
</Nav.item>;
|
||||||
@@ -111,4 +111,4 @@ const Account = createClass({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = Account;
|
export default Account;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
require('./error-navitem.less');
|
import './error-navitem.less';
|
||||||
const React = require('react');
|
import React from 'react';
|
||||||
const Nav = require('client/homebrew/navbar/nav.jsx');
|
import Nav from './nav.jsx';
|
||||||
|
|
||||||
const ErrorNavItem = ({ error = '', clearError })=>{
|
const ErrorNavItem = ({ error = '', clearError })=>{
|
||||||
const response = error.response;
|
const response = error.response;
|
||||||
@@ -144,4 +144,4 @@ const ErrorNavItem = ({ error = '', clearError })=>{
|
|||||||
</Nav.item>;
|
</Nav.item>;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = ErrorNavItem;
|
export default ErrorNavItem;
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@import '@sharedStyles/core.less';
|
||||||
|
|
||||||
.navItem.error {
|
.navItem.error {
|
||||||
position : relative;
|
position : relative;
|
||||||
background-color : @red;
|
background-color : @red;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
const React = require('react');
|
import React from 'react';
|
||||||
const dedent = require('dedent-tabs').default;
|
import dedent from 'dedent';
|
||||||
|
|
||||||
const Nav = require('client/homebrew/navbar/nav.jsx');
|
import Nav from './nav.jsx';
|
||||||
|
|
||||||
module.exports = function(props){
|
export default function(props){
|
||||||
return <Nav.dropdown>
|
return <Nav.dropdown>
|
||||||
<Nav.item color='grey' icon='fas fa-question-circle'>
|
<Nav.item color='grey' icon='fas fa-question-circle'>
|
||||||
need help?
|
need help?
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
const React = require('react');
|
import React from 'react';
|
||||||
const createClass = require('create-react-class');
|
import createReactClass from 'create-react-class';
|
||||||
const Moment = require('moment');
|
import Moment from 'moment';
|
||||||
|
|
||||||
const Nav = require('client/homebrew/navbar/nav.jsx');
|
import Nav from './nav.jsx';
|
||||||
|
|
||||||
|
|
||||||
const MetadataNav = createClass({
|
const MetadataNav = createReactClass({
|
||||||
displayName : 'MetadataNav',
|
displayName : 'MetadataNav',
|
||||||
getDefaultProps : function() {
|
getDefaultProps : function() {
|
||||||
return {
|
return {
|
||||||
@@ -46,11 +46,6 @@ const MetadataNav = createClass({
|
|||||||
</>;
|
</>;
|
||||||
},
|
},
|
||||||
|
|
||||||
getSystems : function(){
|
|
||||||
if(!this.props.brew.systems || this.props.brew.systems.length == 0) return 'No systems';
|
|
||||||
return this.props.brew.systems.join(', ');
|
|
||||||
},
|
|
||||||
|
|
||||||
renderMetaWindow : function(){
|
renderMetaWindow : function(){
|
||||||
return <div className={`window ${this.state.showMetaWindow ? 'active' : 'inactive'}`}>
|
return <div className={`window ${this.state.showMetaWindow ? 'active' : 'inactive'}`}>
|
||||||
<div className='row'>
|
<div className='row'>
|
||||||
@@ -65,10 +60,6 @@ const MetadataNav = createClass({
|
|||||||
<h4>Tags</h4>
|
<h4>Tags</h4>
|
||||||
<p>{this.getTags()}</p>
|
<p>{this.getTags()}</p>
|
||||||
</div>
|
</div>
|
||||||
<div className='row'>
|
|
||||||
<h4>Systems</h4>
|
|
||||||
<p>{this.getSystems()}</p>
|
|
||||||
</div>
|
|
||||||
<div className='row'>
|
<div className='row'>
|
||||||
<h4>Updated</h4>
|
<h4>Updated</h4>
|
||||||
<p>{Moment(this.props.brew.updatedAt).fromNow()}</p>
|
<p>{Moment(this.props.brew.updatedAt).fromNow()}</p>
|
||||||
@@ -86,4 +77,4 @@ const MetadataNav = createClass({
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = MetadataNav;
|
export default MetadataNav;
|
||||||
@@ -1,22 +1,16 @@
|
|||||||
require('client/homebrew/navbar/navbar.less');
|
import './navbar.less';
|
||||||
const React = require('react');
|
import React, { useState, useRef, useEffect } from 'react';
|
||||||
const { useState, useRef, useEffect } = React;
|
import cx from 'classnames';
|
||||||
const createClass = require('create-react-class');
|
|
||||||
const _ = require('lodash');
|
|
||||||
const cx = require('classnames');
|
|
||||||
|
|
||||||
const NaturalCritIcon = require('client/components/svg/naturalcrit-d20.svg.jsx');
|
import NaturalCritIcon from '@components/svg/naturalcrit-d20.svg.jsx';
|
||||||
|
|
||||||
const Nav = {
|
const Nav = {
|
||||||
base : createClass({
|
base : ({ children, className, ...props })=>{
|
||||||
displayName : 'Nav.base',
|
return <nav className={className}>
|
||||||
render : function(){
|
{children}
|
||||||
return <nav>
|
</nav>;
|
||||||
{this.props.children}
|
},
|
||||||
</nav>;
|
logo : ()=>{
|
||||||
}
|
|
||||||
}),
|
|
||||||
logo : function(){
|
|
||||||
return <a className='navLogo' href='https://www.naturalcrit.com'>
|
return <a className='navLogo' href='https://www.naturalcrit.com'>
|
||||||
<NaturalCritIcon />
|
<NaturalCritIcon />
|
||||||
<span className='name'>
|
<span className='name'>
|
||||||
@@ -25,50 +19,26 @@ const Nav = {
|
|||||||
</a>;
|
</a>;
|
||||||
},
|
},
|
||||||
|
|
||||||
section : createClass({
|
section : ({ children, className, ...props })=>{
|
||||||
displayName : 'Nav.section',
|
return <div className={cx([`navSection`, className])}>
|
||||||
render : function(){
|
{children}
|
||||||
return <div className={`navSection ${this.props.className ?? ''}`}>
|
</div>;
|
||||||
{this.props.children}
|
},
|
||||||
</div>;
|
|
||||||
|
item : ({ icon, href, newTab, onClick, color, children, className, ...props })=>{
|
||||||
|
const classes = cx('navItem', color, className);
|
||||||
|
if(href){
|
||||||
|
return <a className={classes} href={href} target={newTab ? '_blank' : '_self'} {...props}>
|
||||||
|
{children}
|
||||||
|
{icon && <i className={icon}></i>}
|
||||||
|
</a>;
|
||||||
|
} else {
|
||||||
|
return <button {...props} className={classes} onClick={onClick} >
|
||||||
|
{children}
|
||||||
|
{icon && <i className={icon}></i>}
|
||||||
|
</button>;
|
||||||
}
|
}
|
||||||
}),
|
},
|
||||||
|
|
||||||
item : createClass({
|
|
||||||
displayName : 'Nav.item',
|
|
||||||
getDefaultProps : function() {
|
|
||||||
return {
|
|
||||||
icon : null,
|
|
||||||
href : null,
|
|
||||||
newTab : false,
|
|
||||||
onClick : function(){},
|
|
||||||
color : null
|
|
||||||
};
|
|
||||||
},
|
|
||||||
handleClick : function(e){
|
|
||||||
this.props.onClick(e);
|
|
||||||
},
|
|
||||||
render : function(){
|
|
||||||
const classes = cx('navItem', this.props.color, this.props.className);
|
|
||||||
|
|
||||||
let icon;
|
|
||||||
if(this.props.icon) icon = <i className={this.props.icon} />;
|
|
||||||
|
|
||||||
const props = _.omit(this.props, ['newTab']);
|
|
||||||
|
|
||||||
if(this.props.href){
|
|
||||||
return <a {...props} className={classes} target={this.props.newTab ? '_blank' : '_self'} >
|
|
||||||
{this.props.children}
|
|
||||||
{icon}
|
|
||||||
</a>;
|
|
||||||
} else {
|
|
||||||
return <div {...props} className={classes} onClick={this.handleClick} >
|
|
||||||
{this.props.children}
|
|
||||||
{icon}
|
|
||||||
</div>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
|
|
||||||
dropdown : function dropdown(props) {
|
dropdown : function dropdown(props) {
|
||||||
props = Object.assign({}, props, {
|
props = Object.assign({}, props, {
|
||||||
@@ -117,4 +87,4 @@ const Nav = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports = Nav;
|
export default Nav;
|
||||||
@@ -1,52 +1,28 @@
|
|||||||
require('./navbar.less');
|
import './navbar.less';
|
||||||
const React = require('react');
|
import React from 'react';
|
||||||
const createClass = require('create-react-class');
|
|
||||||
|
|
||||||
const Nav = require('client/homebrew/navbar/nav.jsx');
|
import Nav from './nav.jsx';
|
||||||
const PatreonNavItem = require('./patreon.navitem.jsx');
|
import PatreonNavItem from './patreon.navitem.jsx';
|
||||||
|
|
||||||
const Navbar = createClass({
|
const Navbar = ({ children })=>{
|
||||||
displayName : 'Navbar',
|
const version = global.version || '0.0.0';
|
||||||
getInitialState : function() {
|
|
||||||
return {
|
|
||||||
//showNonChromeWarning : false,
|
|
||||||
ver : '0.0.0'
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
getInitialState : function() {
|
return (
|
||||||
return {
|
<Nav.base>
|
||||||
ver : global.version
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
/*
|
|
||||||
renderChromeWarning : function(){
|
|
||||||
if(!this.state.showNonChromeWarning) return;
|
|
||||||
return <Nav.item className='warning' icon='fa-exclamation-triangle'>
|
|
||||||
Optimized for Chrome
|
|
||||||
<div className='dropdown'>
|
|
||||||
If you are experiencing rendering issues, use Chrome instead
|
|
||||||
</div>
|
|
||||||
</Nav.item>
|
|
||||||
},
|
|
||||||
*/
|
|
||||||
render : function(){
|
|
||||||
return <Nav.base>
|
|
||||||
<Nav.section>
|
<Nav.section>
|
||||||
<Nav.logo />
|
<Nav.logo />
|
||||||
<Nav.item href='/' className='homebrewLogo'>
|
<Nav.item href='/' className='homebrewLogo'>
|
||||||
<div>The Homebrewery</div>
|
<div>The Homebrewery</div>
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
<Nav.item newTab={true} href='/changelog' color='purple' icon='far fa-file-alt'>
|
<Nav.item newTab={true} href='/changelog' color='purple' icon='far fa-file-alt'>
|
||||||
{`v${this.state.ver}`}
|
{`v${version}`}
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
<PatreonNavItem />
|
<PatreonNavItem />
|
||||||
{/*this.renderChromeWarning()*/}
|
{/* this.renderChromeWarning() */}
|
||||||
</Nav.section>
|
</Nav.section>
|
||||||
{this.props.children}
|
{children}
|
||||||
</Nav.base>;
|
</Nav.base>
|
||||||
}
|
);
|
||||||
});
|
};
|
||||||
|
|
||||||
module.exports = Navbar;
|
export default Navbar;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
@import 'naturalcrit/styles/colors.less';
|
@import '@sharedStyles/core.less';
|
||||||
|
|
||||||
@navbarHeight : 28px;
|
@navbarHeight : 28px;
|
||||||
@viewerToolsHeight : 32px;
|
@viewerToolsHeight : 32px;
|
||||||
@@ -39,9 +39,7 @@
|
|||||||
flex-grow : 1;
|
flex-grow : 1;
|
||||||
min-width : 300px;
|
min-width : 300px;
|
||||||
}
|
}
|
||||||
>.brewTitle {
|
>.brewTitle { cursor : auto; }
|
||||||
cursor:auto;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// "NaturalCrit" logo
|
// "NaturalCrit" logo
|
||||||
.navLogo {
|
.navLogo {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const React = require('react');
|
import React from 'react';
|
||||||
const _ = require('lodash');
|
import _ from 'lodash';
|
||||||
const Nav = require('client/homebrew/navbar/nav.jsx');
|
import Nav from './nav.jsx';
|
||||||
const { splitTextStyleAndMetadata } = require('../../../shared/helpers.js'); // Importing the function from helpers.js
|
import { splitTextStyleAndMetadata } from '@shared/helpers.js';
|
||||||
|
|
||||||
const BREWKEY = 'HB_newPage_content';
|
const BREWKEY = 'HB_newPage_content';
|
||||||
const STYLEKEY = 'HB_newPage_style';
|
const STYLEKEY = 'HB_newPage_style';
|
||||||
@@ -24,7 +24,7 @@ const NewBrew = ()=>{
|
|||||||
localStorage.setItem(BREWKEY, newBrew.text);
|
localStorage.setItem(BREWKEY, newBrew.text);
|
||||||
localStorage.setItem(STYLEKEY, newBrew.style);
|
localStorage.setItem(STYLEKEY, newBrew.style);
|
||||||
localStorage.setItem(METAKEY, JSON.stringify(
|
localStorage.setItem(METAKEY, JSON.stringify(
|
||||||
_.pick(newBrew, ['title', 'description', 'tags', 'systems', 'renderer', 'theme', 'lang'])
|
_.pick(newBrew, ['title', 'description', 'tags', 'renderer', 'theme', 'lang'])
|
||||||
));
|
));
|
||||||
window.location.href = '/new';
|
window.location.href = '/new';
|
||||||
return;
|
return;
|
||||||
@@ -100,4 +100,4 @@ const NewBrew = ()=>{
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = NewBrew;
|
export default NewBrew;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
const React = require('react');
|
import React from 'react';
|
||||||
const Nav = require('client/homebrew/navbar/nav.jsx');
|
import Nav from './nav.jsx';
|
||||||
|
|
||||||
module.exports = function(props){
|
export default function(props){
|
||||||
return <Nav.item
|
return <Nav.item
|
||||||
className='patreon'
|
className='patreon'
|
||||||
newTab={true}
|
newTab={true}
|
||||||
|
|||||||
@@ -1,9 +1,25 @@
|
|||||||
const React = require('react');
|
import React, { useState, useEffect } from 'react';
|
||||||
const Nav = require('client/homebrew/navbar/nav.jsx');
|
import Nav from './nav.jsx';
|
||||||
const { printCurrentBrew } = require('../../../shared/helpers.js');
|
import { printCurrentBrew } from '@shared/helpers.js';
|
||||||
|
|
||||||
|
export default function(){
|
||||||
|
const [printing, setPrinting] = useState(false);
|
||||||
|
|
||||||
|
// listen for print cycle events to display "loading" message since it can take some time.
|
||||||
|
useEffect(()=>{
|
||||||
|
document.addEventListener('print:startprep', handlePrintStartPrep);
|
||||||
|
document.addEventListener('print:finishedprep', handlePrintPrepFinished);
|
||||||
|
return ()=>{
|
||||||
|
document.removeEventListener('print:startprep', handlePrintStartPrep);
|
||||||
|
document.removeEventListener('print:finishedprep', handlePrintPrepFinished);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handlePrintStartPrep = ()=>{ setPrinting(true); };
|
||||||
|
|
||||||
|
const handlePrintPrepFinished = ()=>{ setPrinting(false); };
|
||||||
|
|
||||||
module.exports = function(){
|
|
||||||
return <Nav.item onClick={printCurrentBrew} color='purple' icon='far fa-file-pdf'>
|
return <Nav.item onClick={printCurrentBrew} color='purple' icon='far fa-file-pdf'>
|
||||||
get PDF
|
{printing ? 'loading' : 'get PDF'}
|
||||||
</Nav.item>;
|
</Nav.item>;
|
||||||
};
|
};
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
const React = require('react');
|
import React from 'react';
|
||||||
const createClass = require('create-react-class');
|
import createReactClass from 'create-react-class';
|
||||||
const _ = require('lodash');
|
import _ from 'lodash';
|
||||||
const Moment = require('moment');
|
import Moment from 'moment';
|
||||||
|
|
||||||
const Nav = require('client/homebrew/navbar/nav.jsx');
|
import Nav from './nav.jsx';
|
||||||
|
|
||||||
const EDIT_KEY = 'HB_nav_recentlyEdited';
|
const EDIT_KEY = 'HB_nav_recentlyEdited';
|
||||||
const VIEW_KEY = 'HB_nav_recentlyViewed';
|
const VIEW_KEY = 'HB_nav_recentlyViewed';
|
||||||
|
|
||||||
|
|
||||||
const RecentItems = createClass({
|
const RecentItems = createReactClass({
|
||||||
DisplayName : 'RecentItems',
|
DisplayName : 'RecentItems',
|
||||||
getDefaultProps : function() {
|
getDefaultProps : function() {
|
||||||
return {
|
return {
|
||||||
@@ -175,7 +175,7 @@ const RecentItems = createClass({
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
|
|
||||||
edited : (props)=>{
|
edited : (props)=>{
|
||||||
return <RecentItems
|
return <RecentItems
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import dedent from 'dedent-tabs';
|
import dedent from 'dedent';
|
||||||
import Nav from 'client/homebrew/navbar/nav.jsx';
|
import Nav from './nav.jsx';
|
||||||
|
|
||||||
const getShareId = (brew)=>(
|
const getShareId = (brew)=>(
|
||||||
brew.googleId && !brew.stubbed
|
brew.googleId && !brew.stubbed
|
||||||
@@ -17,7 +17,7 @@ const getRedditLink = (brew)=>{
|
|||||||
return `https://www.reddit.com/r/UnearthedArcana/submit?title=${encodeURIComponent(brew.title.toWellFormed())}&text=${encodeURIComponent(text)}`;
|
return `https://www.reddit.com/r/UnearthedArcana/submit?title=${encodeURIComponent(brew.title.toWellFormed())}&text=${encodeURIComponent(text)}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ({ brew })=>(
|
export default ({ brew, currentPage })=>(
|
||||||
<Nav.dropdown>
|
<Nav.dropdown>
|
||||||
<Nav.item color='teal' icon='fas fa-share-alt'>
|
<Nav.item color='teal' icon='fas fa-share-alt'>
|
||||||
share
|
share
|
||||||
@@ -28,6 +28,12 @@ export default ({ brew })=>(
|
|||||||
<Nav.item color='blue' onClick={()=>{navigator.clipboard.writeText(`${global.config.baseUrl}/share/${getShareId(brew)}`);}}>
|
<Nav.item color='blue' onClick={()=>{navigator.clipboard.writeText(`${global.config.baseUrl}/share/${getShareId(brew)}`);}}>
|
||||||
copy url
|
copy url
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
|
{currentPage > 1 &&
|
||||||
|
<Nav.item
|
||||||
|
color='blue'
|
||||||
|
onClick={()=>{navigator.clipboard.writeText(`${global.config.baseUrl}/share/${getShareId(brew)}#p${currentPage}`);}}>
|
||||||
|
copy url (page {currentPage})
|
||||||
|
</Nav.item>}
|
||||||
<Nav.item color='blue' href={getRedditLink(brew)} newTab rel='noopener noreferrer'>
|
<Nav.item color='blue' href={getRedditLink(brew)} newTab rel='noopener noreferrer'>
|
||||||
post to reddit
|
post to reddit
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const React = require('react');
|
import React from 'react';
|
||||||
|
|
||||||
const Nav = require('client/homebrew/navbar/nav.jsx');
|
import Nav from './nav.jsx';
|
||||||
|
|
||||||
module.exports = function (props) {
|
export default function (props) {
|
||||||
return (
|
return (
|
||||||
<Nav.item
|
<Nav.item
|
||||||
color='purple'
|
color='purple'
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const React = require('react');
|
import React from 'react';
|
||||||
const moment = require('moment');
|
import moment from 'moment';
|
||||||
const UIPage = require('../basePages/uiPage/uiPage.jsx');
|
import UIPage from '../basePages/uiPage/uiPage.jsx';
|
||||||
const NaturalCritIcon = require('client/components/svg/naturalcrit-d20.svg.jsx');
|
import NaturalCritIcon from '@components/svg/naturalcrit-d20.svg.jsx';
|
||||||
|
|
||||||
let SAVEKEY = '';
|
let SAVEKEY = '';
|
||||||
|
|
||||||
@@ -79,4 +79,4 @@ const AccountPage = (props)=>{
|
|||||||
</UIPage>);
|
</UIPage>);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = AccountPage;
|
export default AccountPage;
|
||||||
@@ -0,0 +1,450 @@
|
|||||||
|
import React, { useState, useEffect, useEffectEvent, useRef } from 'react';
|
||||||
|
import { printCurrentBrew, fetchThemeBundle } from '@shared/helpers.js';
|
||||||
|
import _ from 'lodash';
|
||||||
|
import { hbfm } from 'marked-hbfm';
|
||||||
|
import { md5 } from 'hash-wasm';
|
||||||
|
import { makePatches, stringifyPatches } from '@sanity/diff-match-patch';
|
||||||
|
|
||||||
|
import Headtags from '@vitreum/headtags.js';
|
||||||
|
import SplitPane from '@components/splitPane/splitPane.jsx';
|
||||||
|
import Editor from '../../../editor/editor.jsx';
|
||||||
|
import BrewRenderer from '../../../brewRenderer/brewRenderer.jsx';
|
||||||
|
import LockNotification from '../../editPage/lockNotification/lockNotification.jsx';
|
||||||
|
const Meta = Headtags.Meta;
|
||||||
|
|
||||||
|
//===---- Navbar
|
||||||
|
import Nav from '@navbar/nav.jsx';
|
||||||
|
import Navbar from '@navbar/navbar.jsx';
|
||||||
|
import NewBrewItem from '@navbar/newbrew.navitem.jsx';
|
||||||
|
import AccountNavItem from '@navbar/account.navitem.jsx';
|
||||||
|
import ErrorNavItem from '@navbar/error-navitem.jsx';
|
||||||
|
import HelpNavItem from '@navbar/help.navitem.jsx';
|
||||||
|
import VaultNavItem from '@navbar/vault.navitem.jsx';
|
||||||
|
import PrintNavItem from '@navbar/print.navitem.jsx';
|
||||||
|
import ShareNavItem from '@navbar/share.navitem.jsx';
|
||||||
|
import RecentNavItems from '@navbar/recent.navitem.jsx';
|
||||||
|
const { both: RecentNavItem } = RecentNavItems;
|
||||||
|
import googleDriveIcon from '../../../googleDrive.svg';
|
||||||
|
|
||||||
|
const AUTOSAVE_KEY = 'HB_editor_autoSaveOn';
|
||||||
|
const BREWKEY = 'HB_newPage_content';
|
||||||
|
const STYLEKEY = 'HB_newPage_style';
|
||||||
|
const SNIPKEY = 'HB_newPage_snippets';
|
||||||
|
const METAKEY = 'HB_newPage_meta';
|
||||||
|
const SAVEKEY_PREFIX = 'HB_editor_defaultSave_';
|
||||||
|
|
||||||
|
const SAVE_TIMEOUT = 10000; //Autosave 10 seconds after last change
|
||||||
|
const UNSAVED_WARNING_TIMEOUT = 900000; //Warn user afer 15 minutes of unsaved changes
|
||||||
|
const UNSAVED_WARNING_POPUP_TIMEOUT = 4000; //Show the warning for 4 seconds
|
||||||
|
|
||||||
|
const EditorPage = (props)=>{
|
||||||
|
const {
|
||||||
|
brew,
|
||||||
|
useLocalStorage,
|
||||||
|
sandbox,
|
||||||
|
showFloatingButtons,
|
||||||
|
save,
|
||||||
|
onSaveSuccess,
|
||||||
|
pageName,
|
||||||
|
showEditorButtons,
|
||||||
|
userThemes = {}
|
||||||
|
} = props;
|
||||||
|
|
||||||
|
const [currentBrew, setCurrentBrew] = useState(brew);
|
||||||
|
const [isSaving, setIsSaving] = useState(false);
|
||||||
|
const [lastSavedTime, setLastSavedTime] = useState(new Date());
|
||||||
|
const [autoSaveEnabled, setAutoSaveEnabled] = useState(!sandbox);
|
||||||
|
const [warnUnsavedChanges, setWarnUnsavedChanges] = useState(true);
|
||||||
|
const [unsavedChanges, setUnsavedChanges] = useState(false);
|
||||||
|
const [themeBundle, setThemeBundle] = useState({});
|
||||||
|
const [HTMLErrors, setHTMLErrors] = useState(hbfm.validate(currentBrew.text));
|
||||||
|
const [saveGoogle, setSaveGoogle] = useState(currentBrew.googleId);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
|
const [alertTrashedGoogleBrew, setAlertTrashedGoogleBrew] = useState(currentBrew.trashed);
|
||||||
|
const [alertNoGoogleToTransfer, setAlertNoGoogleToTransfer] = useState(false);
|
||||||
|
const [alertOwnershipToTransfer, setAlertOwnershipToTransfer] = useState(false);
|
||||||
|
const [confirmGoogleTransfer, setConfirmGoogleTransfer] = useState(false);
|
||||||
|
|
||||||
|
const [currentEditorViewPageNum, setCurrentEditorViewPageNum] = useState(1);
|
||||||
|
const [currentEditorCursorPageNum, setCurrentEditorCursorPageNum] = useState(1);
|
||||||
|
const [currentBrewRendererPageNum, setCurrentBrewRendererPageNum] = useState(1);
|
||||||
|
|
||||||
|
const unsavedChangesRef = useRef(unsavedChanges); // onBeforeUnload lives outside React and needs ref to unsavedChanges
|
||||||
|
const warnUnsavedTimeout = useRef(null); // timers live outside React and need ref to consistently track time
|
||||||
|
const lastSavedBrew = useRef(_.cloneDeep(currentBrew));
|
||||||
|
const saveTimeout = useRef(null);
|
||||||
|
const editorRef = useRef(null);
|
||||||
|
|
||||||
|
//==--------- Page setup ----------==//
|
||||||
|
useEffect(()=>{
|
||||||
|
if(useLocalStorage) loadBrewFromLocalStorage();
|
||||||
|
const autoSavePref = !sandbox && JSON.parse(localStorage.getItem(AUTOSAVE_KEY) ?? true);
|
||||||
|
setAutoSaveEnabled(autoSavePref);
|
||||||
|
setWarnUnsavedChanges(!autoSavePref);
|
||||||
|
fetchThemeBundle(setError, setThemeBundle, currentBrew.renderer, currentBrew.theme);
|
||||||
|
|
||||||
|
const handleControlKeys = (e)=>{
|
||||||
|
if(!(e.ctrlKey || e.metaKey)) return;
|
||||||
|
if(e.keyCode === 83) trySave(true, true, saveGoogle);
|
||||||
|
if(e.keyCode === 80) printCurrentBrew();
|
||||||
|
if([83, 80].includes(e.keyCode)) {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
document.addEventListener('keydown', handleControlKeys);
|
||||||
|
window.onbeforeunload = ()=>{
|
||||||
|
if(unsavedChangesRef.current)
|
||||||
|
return 'You have unsaved changes!';
|
||||||
|
};
|
||||||
|
return ()=>{
|
||||||
|
document.removeEventListener('keydown', handleControlKeys);
|
||||||
|
window.onbeforeunload = null;
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const loadBrewFromLocalStorage = ()=>{
|
||||||
|
const brew = { ...currentBrew };
|
||||||
|
if(!brew.shareId && typeof window !== 'undefined') { //Load from localStorage if in client browser
|
||||||
|
const brewStorage = localStorage.getItem(BREWKEY);
|
||||||
|
const styleStorage = localStorage.getItem(STYLEKEY);
|
||||||
|
const snipStorage = localStorage.getItem(SNIPKEY);
|
||||||
|
const metaStorage = JSON.parse(localStorage.getItem(METAKEY));
|
||||||
|
|
||||||
|
brew.title = metaStorage?.title ?? brew.title;
|
||||||
|
brew.description = metaStorage?.description ?? brew.description;
|
||||||
|
brew.tags = metaStorage?.tags ?? brew.tags;
|
||||||
|
brew.text = brewStorage ?? brew.text;
|
||||||
|
brew.style = styleStorage ?? brew.style;
|
||||||
|
brew.snippets = snipStorage ?? brew.snippets;
|
||||||
|
brew.renderer = metaStorage?.renderer ?? brew.renderer;
|
||||||
|
brew.theme = metaStorage?.theme ?? brew.theme;
|
||||||
|
brew.lang = metaStorage?.lang ?? brew.lang;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SAVEKEY = `${SAVEKEY_PREFIX}${global.account?.username}`;
|
||||||
|
const saveStorage = localStorage.getItem(SAVEKEY) || 'HOMEBREWERY';
|
||||||
|
|
||||||
|
setCurrentBrew(brew);
|
||||||
|
lastSavedBrew.current = brew;
|
||||||
|
setSaveGoogle(saveStorage == 'GOOGLE-DRIVE' && saveGoogle);
|
||||||
|
|
||||||
|
localStorage.setItem(BREWKEY, brew.text);
|
||||||
|
if(brew.style) localStorage.setItem(STYLEKEY, brew.style);
|
||||||
|
if(brew.snippets) localStorage.setItem(SNIPKEY, brew.snippets);
|
||||||
|
localStorage.setItem(METAKEY, JSON.stringify({ title: brew.title, description: brew.description, tags: brew.tags, renderer: brew.renderer, theme: brew.theme, lang: brew.lang }));
|
||||||
|
if(window.location.pathname !== '/new')
|
||||||
|
window.history.replaceState({}, window.location.title, '/new/');
|
||||||
|
};
|
||||||
|
|
||||||
|
const clearLocalStorage = ()=>{
|
||||||
|
localStorage.removeItem(BREWKEY);
|
||||||
|
localStorage.removeItem(STYLEKEY);
|
||||||
|
localStorage.removeItem(SNIPKEY);
|
||||||
|
localStorage.removeItem(METAKEY);
|
||||||
|
};
|
||||||
|
|
||||||
|
//======----- Check for unsaved changes and autosave if enabled -----======
|
||||||
|
useEffect(()=>{
|
||||||
|
const hasChange = !_.isEqual(currentBrew, lastSavedBrew.current);
|
||||||
|
setUnsavedChanges(hasChange);
|
||||||
|
unsavedChangesRef.current = hasChange;
|
||||||
|
|
||||||
|
if(autoSaveEnabled) trySave(false, hasChange, saveGoogle);
|
||||||
|
}, [currentBrew]);
|
||||||
|
|
||||||
|
const resetWarnUnsavedTimer = ()=>{
|
||||||
|
setTimeout(()=>setWarnUnsavedChanges(false), UNSAVED_WARNING_POPUP_TIMEOUT); // Hide the warning after 4 seconds
|
||||||
|
clearTimeout(warnUnsavedTimeout.current);
|
||||||
|
warnUnsavedTimeout.current = setTimeout(()=>setWarnUnsavedChanges(true), UNSAVED_WARNING_TIMEOUT); // 15 minutes between unsaved work warnings
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSplitMove = ()=>{
|
||||||
|
editorRef.current.update();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleBrewChange = (field)=>(value, subfield)=>{ //'text', 'style', 'snippets', 'metadata'
|
||||||
|
if(subfield == 'renderer' || subfield == 'theme')
|
||||||
|
fetchThemeBundle(setError, setThemeBundle, value.renderer, value.theme);
|
||||||
|
|
||||||
|
//If there are HTML errors, run the validator on every change to give quick feedback
|
||||||
|
if(HTMLErrors.length && (field == 'text' || field == 'snippets'))
|
||||||
|
setHTMLErrors(hbfm.validate(value));
|
||||||
|
|
||||||
|
if(field == 'metadata') setCurrentBrew((prev)=>({ ...prev, ...value }));
|
||||||
|
else setCurrentBrew((prev)=>({ ...prev, [field]: value }));
|
||||||
|
|
||||||
|
if(useLocalStorage) {
|
||||||
|
if(field == 'text') localStorage.setItem(BREWKEY, value);
|
||||||
|
if(field == 'style') localStorage.setItem(STYLEKEY, value);
|
||||||
|
if(field == 'snippets') localStorage.setItem(SNIPKEY, value);
|
||||||
|
if(field == 'metadata') localStorage.setItem(METAKEY, JSON.stringify({
|
||||||
|
title : value.title,
|
||||||
|
description : value.description,
|
||||||
|
tags : value.tags,
|
||||||
|
renderer : value.renderer,
|
||||||
|
theme : value.theme,
|
||||||
|
lang : value.lang
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const toggleAutoSave = ()=>{
|
||||||
|
clearTimeout(warnUnsavedTimeout.current);
|
||||||
|
clearTimeout(saveTimeout.current);
|
||||||
|
localStorage.setItem(AUTOSAVE_KEY, JSON.stringify(!autoSaveEnabled));
|
||||||
|
setAutoSaveEnabled(!autoSaveEnabled);
|
||||||
|
setWarnUnsavedChanges(autoSaveEnabled);
|
||||||
|
};
|
||||||
|
|
||||||
|
const clearError = ()=>{
|
||||||
|
setError(null);
|
||||||
|
setIsSaving(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const trySave = useEffectEvent((forceSave = false, hasChanges = true, saveToGoogle = false)=>{
|
||||||
|
clearTimeout(saveTimeout.current);
|
||||||
|
if(isSaving) return;
|
||||||
|
if(!forceSave && !hasChanges) return;
|
||||||
|
const newTimeout = forceSave ? 0 : SAVE_TIMEOUT;
|
||||||
|
|
||||||
|
saveTimeout.current = setTimeout(async ()=>{
|
||||||
|
setIsSaving(true);
|
||||||
|
setError(null);
|
||||||
|
setHTMLErrors(hbfm.validate(currentBrew.text));
|
||||||
|
|
||||||
|
//Prepare content to send to server
|
||||||
|
const snapshotBrewBeforeSave = currentBrew;
|
||||||
|
const brewToSave = {
|
||||||
|
...currentBrew,
|
||||||
|
text : currentBrew.text.normalize('NFC'),
|
||||||
|
pageCount : ((currentBrew.renderer === 'legacy' ? currentBrew.text.match(/\\page/g) : currentBrew.text.match(/^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/gm)) || []).length + 1,
|
||||||
|
patches : stringifyPatches(makePatches(encodeURI(lastSavedBrew.current.text.normalize('NFC')), encodeURI(currentBrew.text.normalize('NFC')))),
|
||||||
|
hash : await md5(lastSavedBrew.current.text.normalize('NFC')),
|
||||||
|
textBin : undefined,
|
||||||
|
version : lastSavedBrew.current.version
|
||||||
|
};
|
||||||
|
|
||||||
|
const savedBrew = await save(brewToSave, saveToGoogle)
|
||||||
|
.catch((err)=>{
|
||||||
|
console.error('Error Updating Local Brew');
|
||||||
|
setError(err);
|
||||||
|
});
|
||||||
|
if(savedBrew) {
|
||||||
|
lastSavedBrew.current = {
|
||||||
|
...snapshotBrewBeforeSave,
|
||||||
|
...savedBrew
|
||||||
|
};
|
||||||
|
|
||||||
|
setCurrentBrew((prevBrew)=>({
|
||||||
|
...prevBrew,
|
||||||
|
...savedBrew
|
||||||
|
}));
|
||||||
|
|
||||||
|
if(useLocalStorage) clearLocalStorage();
|
||||||
|
setLastSavedTime(new Date());
|
||||||
|
if(!autoSaveEnabled) resetWarnUnsavedTimer();
|
||||||
|
onSaveSuccess(savedBrew);
|
||||||
|
}
|
||||||
|
setIsSaving(false);
|
||||||
|
}, newTimeout);
|
||||||
|
});
|
||||||
|
|
||||||
|
const renderSaveButton = ()=>{
|
||||||
|
if(isSaving)
|
||||||
|
return <Nav.item className='save' icon='fas fa-spinner fa-spin'>saving...</Nav.item>;
|
||||||
|
|
||||||
|
if(unsavedChanges && warnUnsavedChanges) {
|
||||||
|
resetWarnUnsavedTimer();
|
||||||
|
const elapsedTime = Math.round((new Date() - lastSavedTime) / 1000 / 60);
|
||||||
|
const text = elapsedTime === 0
|
||||||
|
? `Autosave is OFF${sandbox ? ' for this sandbox page' : ''}.`
|
||||||
|
: `Autosave is OFF${sandbox ? ' for this sandbox page' : ''}, and you haven't saved for ${elapsedTime} minutes.`;
|
||||||
|
|
||||||
|
return <Nav.item className='save error' icon='fas fa-exclamation-circle'>
|
||||||
|
Reminder...
|
||||||
|
<div className='errorContainer'>{text}</div>
|
||||||
|
</Nav.item>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(unsavedChanges)
|
||||||
|
return <Nav.item className='save' onClick={()=>trySave(true, true, saveGoogle)} color='blue' icon='fas fa-save'>save now</Nav.item>;
|
||||||
|
|
||||||
|
if(autoSaveEnabled)
|
||||||
|
return <Nav.item className='save saved'>auto-saved</Nav.item>;
|
||||||
|
|
||||||
|
if(sandbox)
|
||||||
|
return <Nav.item className='save neverSaved' disabled={true}>save now</Nav.item>;
|
||||||
|
|
||||||
|
return <Nav.item className='save saved'>saved</Nav.item>;
|
||||||
|
};
|
||||||
|
|
||||||
|
//TODO: Candidate for refactor/rename; used with history tool to load previous verion; may overlap with snippet injection or handleBrewChange
|
||||||
|
const updateBrew = (newData)=>setCurrentBrew((prevBrew)=>({
|
||||||
|
...prevBrew,
|
||||||
|
style : newData.style,
|
||||||
|
text : newData.text,
|
||||||
|
snippets : newData.snippets
|
||||||
|
}));
|
||||||
|
|
||||||
|
//======----- Google Toggle Button -----======
|
||||||
|
const closeAlerts = (e)=>{
|
||||||
|
e.stopPropagation(); //Only handle click once so alert doesn't reopen
|
||||||
|
setAlertTrashedGoogleBrew(false);
|
||||||
|
setAlertNoGoogleToTransfer(false);
|
||||||
|
setConfirmGoogleTransfer(false);
|
||||||
|
setAlertOwnershipToTransfer(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleGoogleClick = ()=>{
|
||||||
|
if(currentBrew.authors.length > 0 && global.account?.username !== currentBrew.authors[0]) {
|
||||||
|
setAlertOwnershipToTransfer(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(!global.account?.googleId) {
|
||||||
|
setAlertNoGoogleToTransfer(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setConfirmGoogleTransfer((prev)=>!prev);
|
||||||
|
setError(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const toggleGoogleStorage = (e)=>{
|
||||||
|
closeAlerts(e);
|
||||||
|
const newSaveGoogle = !saveGoogle;
|
||||||
|
setSaveGoogle((prev)=>!prev);
|
||||||
|
setError(null);
|
||||||
|
trySave(true, true, newSaveGoogle);
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderGoogleDriveIcon = ()=>(
|
||||||
|
<Nav.item className='googleDriveStorage' onClick={handleGoogleClick}>
|
||||||
|
<img src={googleDriveIcon} className={saveGoogle ? '' : 'inactive'} alt='Google Drive icon' />
|
||||||
|
|
||||||
|
{alertOwnershipToTransfer && (
|
||||||
|
<div className='errorContainer'>
|
||||||
|
You must be the Owner to transfer between the Homebrewery and Google Drive!
|
||||||
|
The owner of this file is {currentBrew.authors[0]}.
|
||||||
|
<br></br>
|
||||||
|
<div className='confirm' onClick={closeAlerts}> Okay </div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{alertNoGoogleToTransfer && (
|
||||||
|
<div className='errorContainer'>
|
||||||
|
You must be signed in to a Google account to transfer between the Homebrewery and Google Drive!
|
||||||
|
<a target='_blank' rel='noopener noreferrer' href={`https://www.naturalcrit.com/login?redirect=${window.location.href}`}>
|
||||||
|
<div className='confirm' onClick={closeAlerts}> Sign In </div>
|
||||||
|
</a>
|
||||||
|
<div className='deny' onClick={closeAlerts}> Not Now </div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{alertTrashedGoogleBrew && (
|
||||||
|
<div className='errorContainer'>
|
||||||
|
This brew is currently in your Trash folder on Google Drive!<br />
|
||||||
|
If you want to keep it, make sure to move it before it is deleted permanently!<br />
|
||||||
|
<div className='confirm' onClick={toggleGoogleStorage}> Save my brew </div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{confirmGoogleTransfer && (
|
||||||
|
<div className='errorContainer'>
|
||||||
|
{saveGoogle
|
||||||
|
? 'Would you like to transfer this brew from your Google Drive storage back to the Homebrewery?'
|
||||||
|
: 'Would you like to transfer this brew from the Homebrewery to your personal Google Drive storage?'}
|
||||||
|
<br />
|
||||||
|
<div className='confirm' onClick={toggleGoogleStorage}> Yes </div>
|
||||||
|
<div className='deny' onClick={closeAlerts}> No </div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Nav.item>
|
||||||
|
);
|
||||||
|
|
||||||
|
//======----- Navbar -----======
|
||||||
|
const renderNavbar = ()=>(
|
||||||
|
<Navbar>
|
||||||
|
<Nav.section>
|
||||||
|
<Nav.item className='brewTitle'>{currentBrew.title}</Nav.item>
|
||||||
|
</Nav.section>
|
||||||
|
<Nav.section>
|
||||||
|
{(pageName == 'editPage') && renderGoogleDriveIcon()}
|
||||||
|
{error
|
||||||
|
? <ErrorNavItem error={error} clearError={clearError} />
|
||||||
|
: <Nav.dropdown className='save-menu'>
|
||||||
|
{renderSaveButton()}
|
||||||
|
{(pageName == 'editPage') && renderAutoSaveButton()}
|
||||||
|
</Nav.dropdown>}
|
||||||
|
<NewBrewItem />
|
||||||
|
<PrintNavItem />
|
||||||
|
<HelpNavItem />
|
||||||
|
<VaultNavItem />
|
||||||
|
{(pageName == 'editPage') && <ShareNavItem brew={currentBrew} currentPage={currentBrewRendererPageNum} />}
|
||||||
|
<RecentNavItem brew={currentBrew} storageKey={(pageName == 'editPage') ? 'edit' : undefined} />
|
||||||
|
<AccountNavItem />
|
||||||
|
</Nav.section>
|
||||||
|
</Navbar>
|
||||||
|
);
|
||||||
|
|
||||||
|
const renderAutoSaveButton = ()=>(
|
||||||
|
<Nav.item onClick={toggleAutoSave}>
|
||||||
|
Autosave <i className={autoSaveEnabled ? 'fas fa-power-off active' : 'fas fa-power-off'}></i>
|
||||||
|
</Nav.item>
|
||||||
|
);
|
||||||
|
|
||||||
|
const renderFloatingSaveButtons = ()=>(
|
||||||
|
<>
|
||||||
|
<div className={`floatingSaveButton${unsavedChanges ? ' show' : ''}`} onClick={()=>trySave(true, true, saveGoogle)}>
|
||||||
|
Save current <i className='fas fa-save' />
|
||||||
|
</div>
|
||||||
|
<a href='/new' className='floatingNewButton'>
|
||||||
|
Create your own <i className='fas fa-magic' />
|
||||||
|
</a>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className= {`${pageName} sitePage`}>
|
||||||
|
<Meta name='google-site-verification' content='NwnAQSSJZzAT7N-p5MY6ydQ7Njm67dtbu73ZSyE5Fy4' />
|
||||||
|
{(pageName == 'editPage') && <Meta name='robots' content='noindex, nofollow' />}
|
||||||
|
{renderNavbar()}
|
||||||
|
{currentBrew.lock && <LockNotification shareId={currentBrew.shareId} message={currentBrew.lock.editMessage} reviewRequested={currentBrew.lock.reviewRequested}/>}
|
||||||
|
<div className='content'>
|
||||||
|
<SplitPane onDragFinish={handleSplitMove}>
|
||||||
|
<Editor
|
||||||
|
ref={editorRef}
|
||||||
|
brew={currentBrew}
|
||||||
|
onBrewChange={handleBrewChange}
|
||||||
|
reportError={setError}
|
||||||
|
renderer={currentBrew.renderer}
|
||||||
|
userThemes={userThemes}
|
||||||
|
showEditButtons={showEditorButtons}
|
||||||
|
themeBundle={themeBundle}
|
||||||
|
updateBrew={updateBrew}
|
||||||
|
onCursorPageChange={setCurrentEditorCursorPageNum}
|
||||||
|
onViewPageChange={setCurrentEditorViewPageNum}
|
||||||
|
currentEditorViewPageNum={currentEditorViewPageNum}
|
||||||
|
currentEditorCursorPageNum={currentEditorCursorPageNum}
|
||||||
|
currentBrewRendererPageNum={currentBrewRendererPageNum}
|
||||||
|
/>
|
||||||
|
<BrewRenderer
|
||||||
|
lang={currentBrew.lang}
|
||||||
|
text={currentBrew.text}
|
||||||
|
style={currentBrew.style}
|
||||||
|
renderer={currentBrew.renderer}
|
||||||
|
themeBundle={themeBundle}
|
||||||
|
errors={HTMLErrors}
|
||||||
|
onPageChange={setCurrentBrewRendererPageNum}
|
||||||
|
currentEditorCursorPageNum={currentEditorCursorPageNum}
|
||||||
|
allowPrint={true} //TODO: candidate for cleanup in brewRenderer. Homepage only place where allowPrint = false. Vote OK to allow print everywhere
|
||||||
|
/>
|
||||||
|
</SplitPane>
|
||||||
|
</div>
|
||||||
|
{showFloatingButtons && renderFloatingSaveButtons()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default EditorPage;
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
require('./brewItem.less');
|
import './brewItem.less';
|
||||||
const React = require('react');
|
import React, { useCallback, useState } from 'react';
|
||||||
const { useCallback } = React;
|
import moment from 'moment';
|
||||||
const moment = require('moment');
|
|
||||||
import request from '../../../../utils/request-middleware.js';
|
import request from '../../../../utils/request-middleware.js';
|
||||||
|
|
||||||
const googleDriveIcon = require('../../../../googleDrive.svg');
|
import googleDriveIcon from '../../../../googleDrive.svg';
|
||||||
const homebreweryIcon = require('../../../../thumbnail.svg');
|
import homebreweryIconWhite from '@themes/assets/naturalCritLogoWhite.svg';
|
||||||
const dedent = require('dedent-tabs').default;
|
import homebreweryIconBlack from '@themes/assets/naturalCritLogoBlack.svg';
|
||||||
|
import dedent from 'dedent';
|
||||||
|
|
||||||
const BrewItem = ({
|
const BrewItem = ({
|
||||||
brew = {
|
brew = {
|
||||||
@@ -17,9 +17,12 @@ const BrewItem = ({
|
|||||||
},
|
},
|
||||||
updateListFilter = ()=>{},
|
updateListFilter = ()=>{},
|
||||||
reportError = ()=>{},
|
reportError = ()=>{},
|
||||||
|
theme,
|
||||||
renderStorage = true,
|
renderStorage = true,
|
||||||
})=>{
|
})=>{
|
||||||
|
|
||||||
|
const [detailsOpen, setDetailsOpen] = useState(false);
|
||||||
|
|
||||||
const deleteBrew = useCallback(()=>{
|
const deleteBrew = useCallback(()=>{
|
||||||
if(brew.authors.length <= 1) {
|
if(brew.authors.length <= 1) {
|
||||||
if(!window.confirm('Are you sure you want to delete this brew? Because you are the only owner of this brew, the document will be deleted permanently.')) return;
|
if(!window.confirm('Are you sure you want to delete this brew? Because you are the only owner of this brew, the document will be deleted permanently.')) return;
|
||||||
@@ -34,15 +37,13 @@ const BrewItem = ({
|
|||||||
});
|
});
|
||||||
}, [brew, reportError]);
|
}, [brew, reportError]);
|
||||||
|
|
||||||
const updateFilter = useCallback((type, term)=>updateListFilter(type, term), [updateListFilter]);
|
|
||||||
|
|
||||||
const renderDeleteBrewLink = ()=>{
|
const renderDeleteBrewLink = ()=>{
|
||||||
if(!brew.editId) return null;
|
if(!brew.editId) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<a className='deleteLink' onClick={deleteBrew}>
|
<button aria-label={`Delete ${brew.title}`} className='deleteLink' onClick={deleteBrew}>
|
||||||
<i className='fas fa-trash-alt' title='Delete' />
|
<i className='fas fa-trash-alt' aria-hidden='true' title='Delete' />
|
||||||
</a>
|
</button>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -53,7 +54,7 @@ const BrewItem = ({
|
|||||||
if(brew.googleId && !brew.stubbed) editLink = brew.googleId + editLink;
|
if(brew.googleId && !brew.stubbed) editLink = brew.googleId + editLink;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<a className='editLink' href={`/edit/${editLink}`} target='_blank' rel='noopener noreferrer'>
|
<a className='editLink' href={`/edit/${editLink}`} aria-label={`Edit ${brew.title}`} target='_blank' rel='noopener noreferrer'>
|
||||||
<i className='fas fa-pencil-alt' title='Edit' />
|
<i className='fas fa-pencil-alt' title='Edit' />
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
@@ -68,7 +69,7 @@ const BrewItem = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<a className='shareLink' href={`/share/${shareLink}`} target='_blank' rel='noopener noreferrer'>
|
<a className='shareLink' href={`/share/${shareLink}`} aria-label={`Share ${brew.title}`} target='_blank' rel='noopener noreferrer'>
|
||||||
<i className='fas fa-share-alt' title='Share' />
|
<i className='fas fa-share-alt' title='Share' />
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
@@ -83,7 +84,7 @@ const BrewItem = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<a className='downloadLink' href={`/download/${shareLink}`}>
|
<a className='downloadLink' aria-label={`Download ${brew.title}`} href={`/download/${shareLink}`}>
|
||||||
<i className='fas fa-download' title='Download' />
|
<i className='fas fa-download' title='Download' />
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
@@ -93,17 +94,16 @@ const BrewItem = ({
|
|||||||
if(!renderStorage) return null;
|
if(!renderStorage) return null;
|
||||||
if(brew.googleId) {
|
if(brew.googleId) {
|
||||||
return (
|
return (
|
||||||
<span title={brew.webViewLink ? 'Your Google Drive Storage' : 'Another User\'s Google Drive Storage'}>
|
<span className='storage' title={brew.webViewLink ? 'Your Google Drive Storage' : 'Another User\'s Google Drive Storage'}>
|
||||||
<a href={brew.webViewLink} target='_blank'>
|
<a href={brew.webViewLink} target='_blank'>
|
||||||
<img className='googleDriveIcon' src={googleDriveIcon} alt='googleDriveIcon' />
|
<img className='googleDriveIcon' src={googleDriveIcon} alt='Google Drive Storage' />
|
||||||
</a>
|
</a>
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span title='Homebrewery Storage'>
|
<span className='storage' title='Homebrewery Storage'>
|
||||||
<img className='homebreweryIcon' src={homebreweryIcon} alt='homebreweryIcon' />
|
<img className='homebreweryIcon' src={theme === 'light' ? homebreweryIconBlack : homebreweryIconWhite} alt='Homebrewery Storage' />
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -118,24 +118,23 @@ const BrewItem = ({
|
|||||||
const dateFormatString = 'YYYY-MM-DD HH:mm:ss';
|
const dateFormatString = 'YYYY-MM-DD HH:mm:ss';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='brewItem'>
|
<div className={`brewItem${detailsOpen ? ' detailsOpen' : ''}`} onClick={() => setDetailsOpen(!detailsOpen)} >
|
||||||
{brew.thumbnail && <div className='thumbnail' style={{ backgroundImage: `url(${brew.thumbnail})` }}></div>}
|
{brew.thumbnail && <div className='thumbnail' style={{ backgroundImage: `url(${brew.thumbnail})` }}></div>}
|
||||||
<div className='text'>
|
<div className='text'>
|
||||||
<h2>{brew.title}</h2>
|
<h2 title={brew.title}>{brew.title}</h2>
|
||||||
<p className='description'>{brew.description}</p>
|
<p className='description'>{brew.description}</p>
|
||||||
</div>
|
</div>
|
||||||
<hr />
|
|
||||||
<div className='info'>
|
<div className='info'>
|
||||||
{brew.tags?.length ? (
|
{brew.tags?.length ? (
|
||||||
<div className='brewTags' title={`${brew.tags.length} tags:\n${brew.tags.join('\n')}`}>
|
<div className='brewTags' title={`${brew.tags.length} tags:\n${brew.tags.join('\n')}`}>
|
||||||
<i className='fas fa-tags' />
|
<i className='fas fa-tags' />
|
||||||
{brew.tags.map((tag, idx)=>{
|
{brew.tags.map((tag, idx)=>{
|
||||||
const matches = tag.match(/^(?:([^:]+):)?([^:]+)$/);
|
const matches = tag.match(/^(?:([^:]+):)?([^:]+)$/);
|
||||||
return <span key={idx} className={matches[1]} onClick={()=>updateFilter(tag)}>{matches[2]}</span>;
|
return <span key={idx} className={matches[1]} onClick={()=>updateListFilter(tag)}>{matches[2]}</span>;
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
<span title={`Authors:\n${brew.authors?.join('\n')}`}>
|
<div className='brewAuthors' title={`Authors:\n${brew.authors?.join('\n')}`}>
|
||||||
<i className='fas fa-user' />{' '}
|
<i className='fas fa-user' />{' '}
|
||||||
{brew.authors?.map((author, index)=>(
|
{brew.authors?.map((author, index)=>(
|
||||||
<React.Fragment key={index}>
|
<React.Fragment key={index}>
|
||||||
@@ -147,21 +146,22 @@ const BrewItem = ({
|
|||||||
{index < brew.authors.length - 1 && ', '}
|
{index < brew.authors.length - 1 && ', '}
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
))}
|
))}
|
||||||
</span>
|
</div>
|
||||||
<br />
|
|
||||||
<span title={`Last viewed: ${moment(brew.lastViewed).local().format(dateFormatString)}`}>
|
|
||||||
<i className='fas fa-eye' /> {brew.views}
|
|
||||||
</span>
|
|
||||||
{brew.pageCount && (
|
{brew.pageCount && (
|
||||||
<span title={`Page count: ${brew.pageCount}`}>
|
<span className='brewPages' aria-label={`${brew.pageCount} pages`} title={`Page count: ${brew.pageCount}`}>
|
||||||
<i className='far fa-file' /> {brew.pageCount}
|
<span aria-hidden='true'><i className='far fa-file' /> {brew.pageCount}</span>
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
|
<span className='lastViewed' aria-label={`Viewed ${brew.views} times`} title={`Last viewed: ${moment(brew.lastViewed).local().format(dateFormatString)}`}>
|
||||||
|
<span aria-hidden='true'><i className='fas fa-eye' /> {brew.views}</span>
|
||||||
|
</span>
|
||||||
<span
|
<span
|
||||||
|
className='lastUpdated'
|
||||||
|
aria-label={`Last updated ${moment(brew.updatedAt).fromNow()}`}
|
||||||
title={dedent` Created: ${moment(brew.createdAt).local().format(dateFormatString)}
|
title={dedent` Created: ${moment(brew.createdAt).local().format(dateFormatString)}
|
||||||
Last updated: ${moment(brew.updatedAt).local().format(dateFormatString)}`}
|
Last updated: ${moment(brew.updatedAt).local().format(dateFormatString)}`}
|
||||||
>
|
>
|
||||||
<i className='fas fa-sync-alt' /> {moment(brew.updatedAt).fromNow()}
|
<i className='fas fa-sync-alt' /><span aria-hidden='true'> {moment(brew.updatedAt).fromNow()}</span>
|
||||||
</span>
|
</span>
|
||||||
{renderStorageIcon()}
|
{renderStorageIcon()}
|
||||||
</div>
|
</div>
|
||||||
@@ -176,4 +176,4 @@ const BrewItem = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = BrewItem;
|
export default BrewItem;
|
||||||
@@ -1,29 +1,32 @@
|
|||||||
|
@import '@sharedStyles/core.less';
|
||||||
|
@import '@themes/assets/assets.less';
|
||||||
|
@import url('https://fonts.googleapis.com/css2?family=Alata&display=swap');
|
||||||
|
|
||||||
.brewItem {
|
.brewItem {
|
||||||
|
--bg-clr : #EEEEEE;
|
||||||
|
--bg-image : @backgroundImageAlt;
|
||||||
|
--text-clr : black;
|
||||||
|
--text-shadow-clr : white;
|
||||||
|
--hb-logo: url('@themes/assets/naturalCritLogoBlack.svg');
|
||||||
|
|
||||||
position : relative;
|
position : relative;
|
||||||
box-sizing : border-box;
|
display : flex;
|
||||||
display : inline-block;
|
flex-direction : column;
|
||||||
width : 48%;
|
|
||||||
min-height : 105px;
|
|
||||||
padding : 5px 15px 2px 6px;
|
|
||||||
padding-right : 15px;
|
|
||||||
margin-right : 15px;
|
|
||||||
margin-bottom : 15px;
|
|
||||||
overflow : hidden;
|
overflow : hidden;
|
||||||
vertical-align : top;
|
font-size : 15px;
|
||||||
background-color : #CAB2802E;
|
color : var(--text-clr);
|
||||||
border : 1px solid #C9AD6A;
|
background-color : var(--bg-clr);
|
||||||
border-radius : 5px;
|
background-image : var(--bg-image);
|
||||||
box-shadow : 0px 4px 5px 0px #333333;
|
background-size : cover;
|
||||||
|
isolation : isolate;
|
||||||
break-inside : avoid;
|
break-inside : avoid;
|
||||||
-webkit-column-break-inside : avoid;
|
-webkit-column-break-inside : avoid;
|
||||||
page-break-inside : avoid;
|
|
||||||
.thumbnail {
|
.thumbnail {
|
||||||
position : absolute;
|
position : absolute;
|
||||||
top : 0;
|
top : 0;
|
||||||
right : 0;
|
right : 30px;
|
||||||
z-index : -1;
|
z-index : -1;
|
||||||
width : 150px;
|
width : 155px;
|
||||||
height : 100%;
|
height : 100%;
|
||||||
background-repeat : no-repeat;
|
background-repeat : no-repeat;
|
||||||
background-position : right top;
|
background-position : right top;
|
||||||
@@ -33,17 +36,14 @@
|
|||||||
mask-image : linear-gradient(80deg, #00000000 20%, #005500 40%);
|
mask-image : linear-gradient(80deg, #00000000 20%, #005500 40%);
|
||||||
}
|
}
|
||||||
.text {
|
.text {
|
||||||
min-height : 54px;
|
h2 {
|
||||||
h4 {
|
font-family : 'Alata';
|
||||||
margin-bottom : 5px;
|
font-size : 1.25em;
|
||||||
font-size : 2.2em;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.info {
|
.info {
|
||||||
position : initial;
|
a { color : inherit; }
|
||||||
bottom : 2px;
|
font-size : 0.9em;
|
||||||
font-family : "ScalySansRemake";
|
|
||||||
font-size : 1.2em;
|
|
||||||
& > span {
|
& > span {
|
||||||
margin-right : 12px;
|
margin-right : 12px;
|
||||||
line-height : 1.5em;
|
line-height : 1.5em;
|
||||||
@@ -58,72 +58,404 @@
|
|||||||
font-weight : bold;
|
font-weight : bold;
|
||||||
white-space : nowrap;
|
white-space : nowrap;
|
||||||
cursor : pointer;
|
cursor : pointer;
|
||||||
background-color : #C8AC6E3B;
|
color:black;
|
||||||
border : 1px solid #C8AC6E;
|
background : hsl(from currentColor h 20% 80%);
|
||||||
border-color : currentColor;
|
border : 1px solid currentColor;
|
||||||
border-radius : 4px;
|
border-radius : 4px;
|
||||||
|
|
||||||
&::before {
|
&::before {
|
||||||
margin-right : 3px;
|
margin-right : 3px;
|
||||||
font-family : 'Font Awesome 6 Free';
|
font-family : 'Font Awesome 6 Free';
|
||||||
font-size : 12px;
|
font-size : 12px;
|
||||||
}
|
}
|
||||||
|
--tag-base : #C8AC6E;
|
||||||
|
--tag-type : #008000;
|
||||||
|
--tag-group : #000000;
|
||||||
|
--tag-meta : #000080;
|
||||||
|
--tag-system : #800000;
|
||||||
&.type {
|
&.type {
|
||||||
color : #008000;
|
color : var(--tag-type);
|
||||||
background-color : #0080003B;
|
|
||||||
&::before { content : '\f0ad'; }
|
&::before { content : '\f0ad'; }
|
||||||
}
|
}
|
||||||
&.group {
|
&.group {
|
||||||
color : #000000;
|
color : var(--tag-group);
|
||||||
background-color : #5050503B;
|
|
||||||
&::before { content : '\f500'; }
|
&::before { content : '\f500'; }
|
||||||
}
|
}
|
||||||
&.meta {
|
&.meta {
|
||||||
color : #000080;
|
color : var(--tag-meta);
|
||||||
background-color : #0000803B;
|
|
||||||
&::before { content : '\f05a'; }
|
&::before { content : '\f05a'; }
|
||||||
}
|
}
|
||||||
&.system {
|
&.system {
|
||||||
color : #800000;
|
color : var(--tag-system);
|
||||||
background-color : #8000003B;
|
|
||||||
&::before { content : '\f518'; }
|
&::before { content : '\f518'; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&:hover {
|
&:nth-child(2n + 1) { margin-right : 0; }
|
||||||
.links { opacity : 1; }
|
|
||||||
}
|
|
||||||
&:nth-child(2n + 1) { margin-right : 0px; }
|
|
||||||
.links {
|
|
||||||
.animate(opacity);
|
|
||||||
position : absolute;
|
|
||||||
top : 0px;
|
|
||||||
right : 0px;
|
|
||||||
width : 2em;
|
|
||||||
height : 100%;
|
|
||||||
text-align : center;
|
|
||||||
background-color : fade(black, 60%);
|
|
||||||
opacity : 0;
|
|
||||||
a {
|
|
||||||
.animate(opacity);
|
|
||||||
display : block;
|
|
||||||
margin : 8px 0px;
|
|
||||||
font-size : 1.3em;
|
|
||||||
color : white;
|
|
||||||
text-decoration : unset;
|
|
||||||
opacity : 0.6;
|
|
||||||
&:hover { opacity : 1; }
|
|
||||||
i { cursor : pointer; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.googleDriveIcon {
|
.googleDriveIcon {
|
||||||
padding : 0px;
|
|
||||||
margin : -5px;
|
|
||||||
height : 18px;
|
height : 18px;
|
||||||
|
padding : 0;
|
||||||
|
margin : -5px;
|
||||||
}
|
}
|
||||||
.homebreweryIcon {
|
.homebreweryIcon {
|
||||||
position : relative;
|
position : relative;
|
||||||
padding : 0px;
|
|
||||||
top : 5px;
|
top : 5px;
|
||||||
left : -7.5px;
|
left : -7.5px;
|
||||||
height : 18px;
|
height : 18px;
|
||||||
|
padding : 0;
|
||||||
|
}
|
||||||
|
.links {
|
||||||
|
position : absolute;
|
||||||
|
right : 0;
|
||||||
|
display : flex;
|
||||||
|
height : 100%;
|
||||||
|
a,
|
||||||
|
button {
|
||||||
|
display : block;
|
||||||
|
align-content : center;
|
||||||
|
width : 100%;
|
||||||
|
height : 100%;
|
||||||
|
font-size : 1.3em;
|
||||||
|
text-align : center;
|
||||||
|
text-decoration : unset;
|
||||||
|
cursor : pointer;
|
||||||
|
&:hover { background-color : hsl(from currentColor h 30% 90%); }
|
||||||
|
}
|
||||||
|
.shareLink { color : @yellow; }
|
||||||
|
.editLink { color : @green; }
|
||||||
|
.downloadLink { color : @blueLight; }
|
||||||
|
.deleteLink { color : @red; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.darkMode .brewItem {
|
||||||
|
--bg-clr : #444;
|
||||||
|
--bg-image : @backgroundImageAltDark;
|
||||||
|
--text-clr : #ddd;
|
||||||
|
--text-shadow-clr : black;
|
||||||
|
--hb-logo: url('@themes/assets/naturalCritLogoWhite.svg');
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid > .brewItem {
|
||||||
|
justify-content : space-between;
|
||||||
|
width : clamp(300px, 48%, 500px);
|
||||||
|
min-height : 125px;
|
||||||
|
padding : 7px 17px 7px 8px;
|
||||||
|
padding-right : 30px;
|
||||||
|
border-radius : 5px;
|
||||||
|
box-shadow : 0 4px 5px 0 #333333;
|
||||||
|
.text {
|
||||||
|
min-height : 54px;
|
||||||
|
padding-left : 5px;
|
||||||
|
h2 { margin-bottom : 5px; }
|
||||||
|
}
|
||||||
|
.info { padding-left : 5px; }
|
||||||
|
.links {
|
||||||
|
top : 0;
|
||||||
|
flex-direction : column;
|
||||||
|
width : 2em;
|
||||||
|
a,
|
||||||
|
button {
|
||||||
|
display : block;
|
||||||
|
width : 100%;
|
||||||
|
font-size : 1.1em;
|
||||||
|
i { cursor : pointer; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.card > .brewItem {
|
||||||
|
gap : 5px;
|
||||||
|
justify-content : flex-end;
|
||||||
|
width : 300px;
|
||||||
|
height : 400px;
|
||||||
|
padding : 100px 10px 50px;
|
||||||
|
background-image : var(--hb-logo), var(--bg-image);
|
||||||
|
background-repeat : no-repeat;
|
||||||
|
background-position : center 20%, center;
|
||||||
|
background-size : 50%, cover;
|
||||||
|
border : 3px solid;
|
||||||
|
border-radius : 10px;
|
||||||
|
box-shadow : 0 4px 5px #222222;
|
||||||
|
&::before {
|
||||||
|
position : absolute;
|
||||||
|
right : 0;
|
||||||
|
bottom : 0;
|
||||||
|
left : 0;
|
||||||
|
z-index : -1;
|
||||||
|
display : block;
|
||||||
|
height : 50%;
|
||||||
|
content : '';
|
||||||
|
background-image : linear-gradient(0deg, var(--bg-clr) 0, hsl(from var(--bg-clr) h s l / 0) 90%);
|
||||||
|
transition : height @defaultDuration;
|
||||||
|
}
|
||||||
|
&:hover {
|
||||||
|
&::before {
|
||||||
|
height : 100%;
|
||||||
|
background-image : linear-gradient(0deg, var(--bg-clr) 0, var(--bg-clr) 55%, hsl(from var(--bg-clr) h s l / 0) 65%);
|
||||||
|
}
|
||||||
|
.text .description { height : fit-content; }
|
||||||
|
}
|
||||||
|
.thumbnail {
|
||||||
|
position : absolute;
|
||||||
|
top : 0;
|
||||||
|
left : 0;
|
||||||
|
z-index : -2;
|
||||||
|
width : 100%;
|
||||||
|
height : 100%;
|
||||||
|
background-repeat : no-repeat;
|
||||||
|
background-position : center top;
|
||||||
|
background-size : cover;
|
||||||
|
opacity : 1;
|
||||||
|
mask-image : unset;
|
||||||
|
}
|
||||||
|
.text {
|
||||||
|
filter : drop-shadow(0 1px 4px var(--text-shadow-clr));
|
||||||
|
h2 { font-weight : 900; }
|
||||||
|
.description {
|
||||||
|
height : 0;
|
||||||
|
overflow : hidden;
|
||||||
|
transition : height @defaultDuration;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.info {
|
||||||
|
display : grid;
|
||||||
|
grid-template-areas : 'tags tags tags tags'
|
||||||
|
'authors authors authors authors'
|
||||||
|
'pages views . .'
|
||||||
|
'update update storage .';
|
||||||
|
grid-template-columns : 1fr 1fr 1fr 30px;
|
||||||
|
height : 110px;
|
||||||
|
filter : drop-shadow(0 1px 2px var(--text-shadow-clr));
|
||||||
|
.brewTags {
|
||||||
|
grid-area : tags;
|
||||||
|
color : inherit;
|
||||||
|
i { color : inherit;}
|
||||||
|
}
|
||||||
|
.brewAuthors { grid-area : authors; }
|
||||||
|
.brewPages { grid-area : pages; }
|
||||||
|
.lastViewed { grid-area : views; }
|
||||||
|
.lastUpdated { grid-area : update; }
|
||||||
|
.storage { grid-area : storage; }
|
||||||
|
}
|
||||||
|
.links {
|
||||||
|
bottom : 0;
|
||||||
|
left : 0;
|
||||||
|
height : 40px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.darkMode .card .brewItem {
|
||||||
|
border-width:2px;
|
||||||
|
}
|
||||||
|
.list > .brewItem {
|
||||||
|
display : grid;
|
||||||
|
grid-template-columns : 35% 3fr 150px;
|
||||||
|
gap : 10px;
|
||||||
|
align-items : center;
|
||||||
|
width : 100%;
|
||||||
|
height : 50px;
|
||||||
|
.thumbnail { display : none; }
|
||||||
|
.text {
|
||||||
|
padding-left : 10px;
|
||||||
|
h2 {
|
||||||
|
.ellipsis();
|
||||||
|
align-content : center;
|
||||||
|
min-height : 1.4em;
|
||||||
|
}
|
||||||
|
.description { display : none; }
|
||||||
|
}
|
||||||
|
.info {
|
||||||
|
display : grid;
|
||||||
|
grid-template-areas : 'tags authors pages views update storage';
|
||||||
|
grid-template-columns : 2fr 150px 0.7fr 65px 1.5fr 20px;
|
||||||
|
align-content : space-around;
|
||||||
|
align-items : center;
|
||||||
|
justify-content : end;
|
||||||
|
width : clamp(400px, 100%, 650px);
|
||||||
|
br { display : none; }
|
||||||
|
span { display : inline-block; margin : 0; }
|
||||||
|
.brewTags {
|
||||||
|
display : inline-flex;
|
||||||
|
flex-wrap : wrap;
|
||||||
|
grid-area : tags;
|
||||||
|
align-items : center;
|
||||||
|
width : 100%;
|
||||||
|
i, span { margin-right : 5px; }
|
||||||
|
&:has(span:nth-of-type(3)) {
|
||||||
|
position : relative;
|
||||||
|
display : flex;
|
||||||
|
flex-wrap : wrap;
|
||||||
|
overflow : hidden;
|
||||||
|
span:nth-of-type(n + 3) { display : none; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.brewAuthors {
|
||||||
|
.ellipsis();
|
||||||
|
display : -webkit-box;
|
||||||
|
grid-area : authors;
|
||||||
|
align-content : center;
|
||||||
|
width : 150px;
|
||||||
|
height : 40px;
|
||||||
|
padding-right : 5px;
|
||||||
|
-webkit-line-clamp : 3;
|
||||||
|
line-clamp : 3;
|
||||||
|
-webkit-box-orient : vertical;
|
||||||
|
&:has(a:only-of-type) { width : fit-content; }
|
||||||
|
}
|
||||||
|
.lastViewed {
|
||||||
|
grid-area : views;
|
||||||
|
min-width : 50px;
|
||||||
|
}
|
||||||
|
.brewPages {
|
||||||
|
grid-area : pages;
|
||||||
|
min-width : 40px;
|
||||||
|
}
|
||||||
|
.lastUpdated {
|
||||||
|
display : flex;
|
||||||
|
grid-area : update;
|
||||||
|
gap : 5px;
|
||||||
|
align-items : center;
|
||||||
|
}
|
||||||
|
.storage {
|
||||||
|
grid-area : storage;
|
||||||
|
filter : drop-shadow(0 0 10px var(--text-shadow-clr));
|
||||||
|
.homebreweryIcon {
|
||||||
|
top : 3px;
|
||||||
|
left : -5px;
|
||||||
|
height : 20px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.links {
|
||||||
|
position : relative;
|
||||||
|
a, button {
|
||||||
|
align-content : center;
|
||||||
|
height : 100%;
|
||||||
|
text-align : center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//these media queries are just for the list layout and could be moved inside it, not sure it is a good idea
|
||||||
|
@container (max-width : 1400px) {
|
||||||
|
.brewCollection .brewGroup.list {
|
||||||
|
.brewItem:not(.detailsOpen) {
|
||||||
|
.info {
|
||||||
|
grid-template-areas : 'tags update storage';
|
||||||
|
grid-template-columns : 2fr 1fr 20px;
|
||||||
|
width : clamp(200px, 100%, 650px);
|
||||||
|
}
|
||||||
|
.brewPages,
|
||||||
|
.lastViewed,
|
||||||
|
.brewAuthors { display : none; }
|
||||||
|
}
|
||||||
|
.brewItem {
|
||||||
|
cursor : pointer;
|
||||||
|
transition : height @defaultDuration;
|
||||||
|
&:hover {
|
||||||
|
box-shadow : 0 0 5px var(--bg-clr);
|
||||||
|
filter : brightness(0.97);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.detailsOpen {
|
||||||
|
grid-template-columns : 25% 3fr 150px;
|
||||||
|
height : 70px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@container (max-width : 1200px) {
|
||||||
|
.brewCollection .brewGroup.list {
|
||||||
|
.brewItem:not(.detailsOpen) {
|
||||||
|
grid-template-columns : 35% 3fr 150px;
|
||||||
|
.info {
|
||||||
|
grid-template-areas : 'tags storage';
|
||||||
|
grid-template-columns : 1fr 20px;
|
||||||
|
}
|
||||||
|
.brewAuthors,
|
||||||
|
.lastUpdated { display : none; }
|
||||||
|
}
|
||||||
|
.detailsOpen {
|
||||||
|
height : 100px;
|
||||||
|
.info {
|
||||||
|
grid-template-areas : 'tags views pages .'
|
||||||
|
'authors update update storage';
|
||||||
|
grid-template-rows : 1fr 1fr;
|
||||||
|
grid-template-columns : 2fr 1fr 1fr 30px;
|
||||||
|
width : clamp(200px, 100%, 650px);
|
||||||
|
}
|
||||||
|
.lastUpdated {
|
||||||
|
.ellipsis();
|
||||||
|
max-width : 120px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@container (max-width : 800px) {
|
||||||
|
.brewCollection .brewGroup.list {
|
||||||
|
.brewItem:not(.detailsOpen) {
|
||||||
|
.info {
|
||||||
|
grid-template-areas : 'tags';
|
||||||
|
grid-template-columns : 1fr;
|
||||||
|
width : clamp(200px, 100%, 650px);
|
||||||
|
}
|
||||||
|
.storage { display : none; }
|
||||||
|
}
|
||||||
|
.brewItem {
|
||||||
|
h2 {
|
||||||
|
width : 200px;
|
||||||
|
font-size : 1em;
|
||||||
|
}
|
||||||
|
transition : height @defaultDuration;
|
||||||
|
}
|
||||||
|
.detailsOpen {
|
||||||
|
display : grid;
|
||||||
|
grid-template-columns : 1fr 4fr 30px;
|
||||||
|
height : 100px;
|
||||||
|
padding : 5px;
|
||||||
|
.text {
|
||||||
|
height : 100%;
|
||||||
|
padding : 0;
|
||||||
|
h2 {
|
||||||
|
display : -webkit-box;
|
||||||
|
height : fit-content;
|
||||||
|
overflow : hidden;
|
||||||
|
text-overflow : ellipsis;
|
||||||
|
-webkit-line-clamp : 3;
|
||||||
|
line-clamp : 3;
|
||||||
|
white-space : wrap;
|
||||||
|
-webkit-box-orient : vertical;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.info {
|
||||||
|
display : grid;
|
||||||
|
grid-template-areas :
|
||||||
|
'tags pages views views'
|
||||||
|
'authors update update storage';
|
||||||
|
grid-template-columns : 2fr 1fr 1fr 20px;
|
||||||
|
width : 100%;
|
||||||
|
height : 100%;
|
||||||
|
}
|
||||||
|
.links {
|
||||||
|
display : flex;
|
||||||
|
flex-direction : column;
|
||||||
|
gap : 5px;
|
||||||
|
a,
|
||||||
|
button { margin : 0; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@container (max-width : 650px) {
|
||||||
|
.brewCollection .brewGroup.list {
|
||||||
|
.brewItem:not(.detailsOpen) {
|
||||||
|
grid-template-columns : 3fr 2fr;
|
||||||
|
.info { display : none; }
|
||||||
|
}
|
||||||
|
.detailsOpen {
|
||||||
|
.info {
|
||||||
|
.lastUpdated {
|
||||||
|
.ellipsis();
|
||||||
|
width : 100px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,282 +1,277 @@
|
|||||||
/*eslint max-lines: ["warn", {"max": 300, "skipBlankLines": true, "skipComments": true}]*/
|
/*eslint max-lines: ["warn", {"max": 300, "skipBlankLines": true, "skipComments": true}]*/
|
||||||
require('./listPage.less');
|
import './listPage.less';
|
||||||
const React = require('react');
|
import React, { useEffect, useState, useMemo } from 'react';
|
||||||
const createClass = require('create-react-class');
|
import moment from 'moment';
|
||||||
const _ = require('lodash');
|
import _ from 'lodash';
|
||||||
const moment = require('moment');
|
|
||||||
|
|
||||||
const BrewItem = require('./brewItem/brewItem.jsx');
|
import BrewItem from './brewItem/brewItem.jsx';
|
||||||
|
|
||||||
const USERPAGE_SORT_DIR = 'HB_listPage_sortDir';
|
const USERPAGE_SORT_DIR = 'HB_listPage_sortDir';
|
||||||
const USERPAGE_SORT_TYPE = 'HB_listPage_sortType';
|
const USERPAGE_SORT_TYPE = 'HB_listPage_sortType';
|
||||||
const USERPAGE_GROUP_VISIBILITY_PREFIX = 'HB_listPage_visibility_group';
|
const USERPAGE_GROUP_VISIBILITY_PREFIX = 'HB_listPage_visibility_group';
|
||||||
|
const USERPAGE_LAYOUT_MODE = 'HB_listPage_layout_mode';
|
||||||
|
const USERPAGE_THEME_MODE = 'HB_listPage_theme_mode';
|
||||||
|
|
||||||
const DEFAULT_SORT_TYPE = 'alpha';
|
const DEFAULT_SORT_TYPE = 'alpha';
|
||||||
const DEFAULT_SORT_DIR = 'asc';
|
const DEFAULT_SORT_DIR = 'asc';
|
||||||
|
const DEFAULT_LAYOUT_MODE = 'grid';
|
||||||
|
const DEFAULT_THEME_MODE = 'light';
|
||||||
|
|
||||||
const ListPage = createClass({
|
const brewSorters = {
|
||||||
displayName : 'ListPage',
|
'alpha' : (brew)=>_.deburr(brew.title).trim().toLowerCase(),
|
||||||
getDefaultProps : function() {
|
'created' : (brew)=>moment(brew.createdAt).format(),
|
||||||
return {
|
'updated' : (brew)=>moment(brew.updatedAt).format(),
|
||||||
brewCollection : [
|
'views' : (brew)=>brew.views
|
||||||
{
|
};
|
||||||
title : '',
|
|
||||||
class : '',
|
|
||||||
brews : []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
navItems : <></>,
|
|
||||||
reportError : null
|
|
||||||
};
|
|
||||||
},
|
|
||||||
getInitialState : function() {
|
|
||||||
// HIDE ALL GROUPS UNTIL LOADED
|
|
||||||
const brewCollection = this.props.brewCollection.map((brewGroup)=>{
|
|
||||||
brewGroup.visible = false;
|
|
||||||
return brewGroup;
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
const ListPage = ({ brewCollection = [{ title: '', class: '', brews: [] }], navItems = <></>, reportError = null, query })=>{
|
||||||
filterString : this.props.query?.filter || '',
|
const [filterString, setFilterString] = useState(query?.filter || '');
|
||||||
filterTags : [],
|
const [filterTags, setFilterTags] = useState(query?.tag || []);
|
||||||
sortType : this.props.query?.sort || null,
|
const [sortType, setSortType] = useState(query?.sort || null);
|
||||||
sortDir : this.props.query?.dir || null,
|
const [sortDir, setSortDir] = useState(query?.dir || null);
|
||||||
query : this.props.query,
|
const [groupVisibility, setGroupVisibility] = useState({});
|
||||||
brewCollection : brewCollection
|
const [layoutMode, setLayoutMode] = useState(DEFAULT_LAYOUT_MODE);
|
||||||
};
|
const [themeMode, setThemeMode] = useState(DEFAULT_THEME_MODE);
|
||||||
},
|
|
||||||
|
|
||||||
componentDidMount : function() {
|
useEffect(()=>{
|
||||||
// SAVE TO LOCAL STORAGE WHEN LEAVING PAGE
|
if(typeof window === 'undefined') return;
|
||||||
window.onbeforeunload = this.saveToLocalStorage;
|
|
||||||
|
|
||||||
// LOAD FROM LOCAL STORAGE
|
const newSortType = sortType ?? (localStorage.getItem(USERPAGE_SORT_TYPE) || DEFAULT_SORT_TYPE);
|
||||||
if(typeof window !== 'undefined') {
|
const newSortDir = sortDir ?? (localStorage.getItem(USERPAGE_SORT_DIR) || DEFAULT_SORT_DIR);
|
||||||
const newSortType = (this.state.sortType ?? (localStorage.getItem(USERPAGE_SORT_TYPE) || DEFAULT_SORT_TYPE));
|
const newLayoutMode = localStorage.getItem(USERPAGE_LAYOUT_MODE) || DEFAULT_LAYOUT_MODE;
|
||||||
const newSortDir = (this.state.sortDir ?? (localStorage.getItem(USERPAGE_SORT_DIR) || DEFAULT_SORT_DIR));
|
const newThemeMode = localStorage.getItem(USERPAGE_THEME_MODE) || DEFAULT_THEME_MODE;
|
||||||
this.updateUrl(this.state.filterString, newSortType, newSortDir);
|
|
||||||
|
|
||||||
const brewCollection = this.props.brewCollection.map((brewGroup)=>{
|
const initialGroupVisibility = brewCollection.reduce((visibility, brewGroup)=>{
|
||||||
brewGroup.visible = (localStorage.getItem(`${USERPAGE_GROUP_VISIBILITY_PREFIX}_${brewGroup.class}`) ?? 'true')=='true';
|
visibility[brewGroup.class] = (localStorage.getItem(`${USERPAGE_GROUP_VISIBILITY_PREFIX}_${brewGroup.class}`) ?? 'true') == 'true';
|
||||||
return brewGroup;
|
return visibility;
|
||||||
});
|
}, {});
|
||||||
|
|
||||||
this.setState({
|
setGroupVisibility(initialGroupVisibility);
|
||||||
brewCollection : brewCollection,
|
setSortType(newSortType);
|
||||||
sortType : newSortType,
|
setSortDir(newSortDir);
|
||||||
sortDir : newSortDir
|
setLayoutMode(newLayoutMode);
|
||||||
});
|
setThemeMode(newThemeMode);
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
componentWillUnmount : function() {
|
updateUrl(filterString, newSortType, newSortDir, filterTags);
|
||||||
window.onbeforeunload = function(){};
|
}, []);
|
||||||
},
|
|
||||||
|
|
||||||
saveToLocalStorage : function() {
|
const updateUrl = (filterTerm, sortType, sortDir, filterTags)=>{
|
||||||
this.state.brewCollection.map((brewGroup)=>{
|
|
||||||
localStorage.setItem(`${USERPAGE_GROUP_VISIBILITY_PREFIX}_${brewGroup.class}`, `${brewGroup.visible}`);
|
|
||||||
});
|
|
||||||
localStorage.setItem(USERPAGE_SORT_TYPE, this.state.sortType);
|
|
||||||
localStorage.setItem(USERPAGE_SORT_DIR, this.state.sortDir);
|
|
||||||
},
|
|
||||||
|
|
||||||
renderBrews : function(brews){
|
|
||||||
if(!brews || !brews.length) return <div className='noBrews'>No Brews.</div>;
|
|
||||||
|
|
||||||
return _.map(brews, (brew, idx)=>{
|
|
||||||
return <BrewItem brew={brew} key={idx} reportError={this.props.reportError} updateListFilter={ (tag)=>{ this.updateUrl(this.state.filterString, this.state.sortType, this.state.sortDir, tag); }}/>;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
sortBrewOrder : function(brew){
|
|
||||||
if(!brew.title){brew.title = 'No Title';}
|
|
||||||
const mapping = {
|
|
||||||
'alpha' : _.deburr(brew.title.trim().toLowerCase()),
|
|
||||||
'created' : moment(brew.createdAt).format(),
|
|
||||||
'updated' : moment(brew.updatedAt).format(),
|
|
||||||
'views' : brew.views,
|
|
||||||
'latest' : moment(brew.lastViewed).format()
|
|
||||||
};
|
|
||||||
return mapping[this.state.sortType];
|
|
||||||
},
|
|
||||||
|
|
||||||
handleSortOptionChange : function(event){
|
|
||||||
this.updateUrl(this.state.filterString, event.target.value, this.state.sortDir);
|
|
||||||
this.setState({
|
|
||||||
sortType : event.target.value
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
handleSortDirChange : function(event){
|
|
||||||
const newDir = this.state.sortDir == 'asc' ? 'desc' : 'asc';
|
|
||||||
|
|
||||||
this.updateUrl(this.state.filterString, this.state.sortType, newDir);
|
|
||||||
this.setState({
|
|
||||||
sortDir : newDir
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
renderSortOption : function(sortTitle, sortValue){
|
|
||||||
return <div className={`sort-option ${(this.state.sortType == sortValue ? 'active' : '')}`}>
|
|
||||||
<button
|
|
||||||
value={`${sortValue}`}
|
|
||||||
onClick={this.state.sortType == sortValue ? this.handleSortDirChange : this.handleSortOptionChange}
|
|
||||||
>
|
|
||||||
{`${sortTitle}`}
|
|
||||||
</button>
|
|
||||||
{this.state.sortType == sortValue &&
|
|
||||||
<i className={`sortDir fas ${this.state.sortDir == 'asc' ? 'fa-sort-up' : 'fa-sort-down'}`}></i>
|
|
||||||
}
|
|
||||||
</div>;
|
|
||||||
},
|
|
||||||
|
|
||||||
handleFilterTextChange : function(e){
|
|
||||||
this.setState({
|
|
||||||
filterString : e.target.value,
|
|
||||||
});
|
|
||||||
this.updateUrl(e.target.value, this.state.sortType, this.state.sortDir);
|
|
||||||
return;
|
|
||||||
},
|
|
||||||
|
|
||||||
updateUrl : function(filterTerm, sortType, sortDir, filterTag=''){
|
|
||||||
const url = new URL(window.location.href);
|
const url = new URL(window.location.href);
|
||||||
const urlParams = new URLSearchParams(url.search);
|
|
||||||
|
|
||||||
urlParams.set('sort', sortType);
|
url.searchParams.set('sort', sortType);
|
||||||
urlParams.set('dir', sortDir);
|
url.searchParams.set('dir', sortDir);
|
||||||
|
|
||||||
let filterTags = urlParams.getAll('tag');
|
// Add tags to URL in alphabetical order
|
||||||
if(filterTag != '') {
|
url.searchParams.delete('tag');
|
||||||
if(filterTags.findIndex((tag)=>{return tag.toLowerCase()==filterTag.toLowerCase();}) == -1){
|
filterTags.forEach((tag)=>url.searchParams.append('tag', tag));
|
||||||
filterTags.push(filterTag);
|
|
||||||
} else {
|
|
||||||
filterTags = filterTags.filter((tag)=>{ return tag.toLowerCase() != filterTag.toLowerCase(); });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
urlParams.delete('tag');
|
|
||||||
// Add tags to URL in the order they were clicked
|
|
||||||
filterTags.forEach((tag)=>{ urlParams.append('tag', tag); });
|
|
||||||
// Sort tags before updating state
|
|
||||||
filterTags.sort((a, b)=>{
|
|
||||||
return a.indexOf(':') - b.indexOf(':') != 0 ? a.indexOf(':') - b.indexOf(':') : a.toLowerCase().localeCompare(b.toLowerCase());
|
|
||||||
});
|
|
||||||
|
|
||||||
this.setState({
|
if(!filterTerm) url.searchParams.delete('filter');
|
||||||
filterTags
|
else url.searchParams.set('filter', filterTerm);
|
||||||
});
|
|
||||||
|
|
||||||
if(!filterTerm)
|
|
||||||
urlParams.delete('filter');
|
|
||||||
else
|
|
||||||
urlParams.set('filter', filterTerm);
|
|
||||||
|
|
||||||
url.search = urlParams;
|
|
||||||
window.history.replaceState(null, null, url);
|
window.history.replaceState(null, null, url);
|
||||||
},
|
};
|
||||||
|
|
||||||
renderFilterOption : function(){
|
const renderBrews = (brews)=>{
|
||||||
return <div className='filter-option'>
|
if(!brews.length) return <div className='noBrews'>No Brews.</div>;
|
||||||
|
|
||||||
|
return brews.map((brew, idx)=>(
|
||||||
|
<BrewItem
|
||||||
|
brew={brew}
|
||||||
|
key={idx}
|
||||||
|
reportError={reportError}
|
||||||
|
theme={themeMode}
|
||||||
|
updateListFilter={handleFilterTagChange}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSortOptionChange = (event)=>{
|
||||||
|
updateUrl(filterString, event.target.value, sortDir, filterTags);
|
||||||
|
setSortType(event.target.value);
|
||||||
|
localStorage.setItem(USERPAGE_SORT_TYPE, event.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSortDirChange = ()=>{
|
||||||
|
const newDir = sortDir == 'asc' ? 'desc' : 'asc';
|
||||||
|
|
||||||
|
updateUrl(filterString, sortType, newDir, filterTags);
|
||||||
|
setSortDir(newDir);
|
||||||
|
localStorage.setItem(USERPAGE_SORT_DIR, newDir);
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderSortOption = (sortTitle, sortValue)=>(
|
||||||
|
<label className={`option ${sortType == sortValue ? 'active' : ''}`}>
|
||||||
|
<button value={sortValue} onClick={sortType == sortValue ? handleSortDirChange : handleSortOptionChange}>
|
||||||
|
{sortTitle}
|
||||||
|
</button>
|
||||||
|
{sortType == sortValue && <i className={`sortDir fas ${sortDir == 'asc' ? 'fa-sort-up' : 'fa-sort-down'}`}></i>}
|
||||||
|
</label>
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleFilterTextChange = (e)=>{
|
||||||
|
setFilterString(e.target.value);
|
||||||
|
updateUrl(e.target.value, sortType, sortDir, filterTags);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleFilterTagChange = (newTag)=>{
|
||||||
|
const alreadyExists = filterTags.some((t)=>t.toLowerCase() == newTag.toLowerCase());
|
||||||
|
|
||||||
|
const newFilterTags = alreadyExists
|
||||||
|
? filterTags.filter((t)=>t.toLowerCase() != newTag.toLowerCase()) //Remove tag if it already exists
|
||||||
|
: [...filterTags, newTag]; //Add tag if it doesn't exist
|
||||||
|
|
||||||
|
newFilterTags.sort((a, b)=>a.indexOf(':') - b.indexOf(':') || a.toLowerCase().localeCompare(b.toLowerCase()));
|
||||||
|
|
||||||
|
setFilterTags(newFilterTags);
|
||||||
|
updateUrl(filterString, sortType, sortDir, newFilterTags);
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderFilterOption = ()=>(
|
||||||
|
<div className='filter-option'>
|
||||||
<label>
|
<label>
|
||||||
<i className='fas fa-search'></i>
|
<i className='fas fa-search'></i>
|
||||||
<input
|
<input type='search' placeholder='filter title/description/tags' onChange={handleFilterTextChange} value={filterString} />
|
||||||
type='search'
|
|
||||||
placeholder='filter title/description'
|
|
||||||
onChange={this.handleFilterTextChange}
|
|
||||||
value={this.state.filterString}
|
|
||||||
/>
|
|
||||||
</label>
|
</label>
|
||||||
</div>;
|
</div>
|
||||||
},
|
);
|
||||||
|
|
||||||
renderTagsOptions : function(){
|
const renderTagsOptions = ()=>{
|
||||||
if(this.state.filterTags?.length == 0) return;
|
if(!filterTags.length) return;
|
||||||
return <div className='tags-container'>
|
return (
|
||||||
{_.map(this.state.filterTags, (tag, idx)=>{
|
<div className='tags-container'>
|
||||||
const matches = tag.match(/^(?:([^:]+):)?([^:]+)$/);
|
Tags:
|
||||||
return <span key={idx} className={matches[1]} onClick={()=>{ this.updateUrl(this.state.filterString, this.state.sortType, this.state.sortDir, tag); }}>{matches[2]}</span>;
|
{filterTags.map((tag, idx)=>{
|
||||||
})}
|
const matches = tag.match(/^(?:([^:]+):)?([^:]+)$/);
|
||||||
</div>;
|
return (
|
||||||
},
|
<span
|
||||||
|
key={idx}
|
||||||
renderSortOptions : function(){
|
className={matches[1]}
|
||||||
return <div className='sort-container'>
|
onClick={()=>handleFilterTagChange(tag)}>
|
||||||
<h6>Sort by :</h6>
|
{matches[2]}
|
||||||
{this.renderSortOption('Title', 'alpha')}
|
</span>
|
||||||
{this.renderSortOption('Created Date', 'created')}
|
);
|
||||||
{this.renderSortOption('Updated Date', 'updated')}
|
})}
|
||||||
{this.renderSortOption('Views', 'views')}
|
|
||||||
{/* {this.renderSortOption('Latest', 'latest')} */}
|
|
||||||
|
|
||||||
{this.renderFilterOption()}
|
|
||||||
</div>;
|
|
||||||
},
|
|
||||||
|
|
||||||
getSortedBrews : function(brews){
|
|
||||||
const testString = _.deburr(this.state.filterString).toLowerCase();
|
|
||||||
|
|
||||||
brews = _.filter(brews, (brew)=>{
|
|
||||||
// Filter by user entered text
|
|
||||||
const brewStrings = _.deburr([
|
|
||||||
brew.title,
|
|
||||||
brew.description,
|
|
||||||
brew.tags].join('\n')
|
|
||||||
.toLowerCase());
|
|
||||||
|
|
||||||
const filterTextTest = brewStrings.includes(testString);
|
|
||||||
|
|
||||||
// Filter by user selected tags
|
|
||||||
let filterTagTest = true;
|
|
||||||
if(this.state.filterTags.length > 0){
|
|
||||||
filterTagTest = Array.isArray(brew.tags) && this.state.filterTags?.every((tag)=>{
|
|
||||||
return brew.tags.findIndex((brewTag)=>{
|
|
||||||
return brewTag.toLowerCase() == tag.toLowerCase();
|
|
||||||
}) >= 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return filterTextTest && filterTagTest;
|
|
||||||
});
|
|
||||||
|
|
||||||
return _.orderBy(brews, (brew)=>{ return this.sortBrewOrder(brew); }, this.state.sortDir);
|
|
||||||
},
|
|
||||||
|
|
||||||
toggleBrewCollectionState : function(brewGroupClass) {
|
|
||||||
this.setState((prevState)=>({
|
|
||||||
brewCollection : prevState.brewCollection.map(
|
|
||||||
(brewGroup)=>brewGroup.class === brewGroupClass ? { ...brewGroup, visible: !brewGroup.visible } : brewGroup
|
|
||||||
)
|
|
||||||
}));
|
|
||||||
},
|
|
||||||
|
|
||||||
renderBrewCollection : function(brewCollection){
|
|
||||||
if(brewCollection == []) return <div className='brewCollection'>
|
|
||||||
<h1>No Brews</h1>
|
|
||||||
</div>;
|
|
||||||
return _.map(brewCollection, (brewGroup, idx)=>{
|
|
||||||
return <div key={idx} className={`brewCollection ${brewGroup.class ?? ''}`}>
|
|
||||||
<h1 className={brewGroup.visible ? 'active' : 'inactive'} onClick={()=>{this.toggleBrewCollectionState(brewGroup.class);}}>{brewGroup.title || 'No Title'}</h1>
|
|
||||||
{brewGroup.visible ? this.renderBrews(this.getSortedBrews(brewGroup.brews)) : <></>}
|
|
||||||
</div>;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
render : function(){
|
|
||||||
return <div className='listPage sitePage'>
|
|
||||||
{/*<style>@layer V3_5ePHB, bundle;</style>*/}
|
|
||||||
<link href='/themes/V3/Blank/style.css' type='text/css' rel='stylesheet'/>
|
|
||||||
<link href='/themes/V3/5ePHB/style.css' type='text/css' rel='stylesheet'/>
|
|
||||||
{this.props.navItems}
|
|
||||||
{this.renderSortOptions()}
|
|
||||||
{this.renderTagsOptions()}
|
|
||||||
|
|
||||||
<div className='content V3'>
|
|
||||||
<div className='page'>
|
|
||||||
{this.renderBrewCollection(this.state.brewCollection)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>;
|
);
|
||||||
}
|
};
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = ListPage;
|
const renderSortOptions = ()=>(
|
||||||
|
<div className='radio-toggle sort-container'>
|
||||||
|
<h6>Sort by :</h6>
|
||||||
|
{renderSortOption('Title', 'alpha')}
|
||||||
|
{renderSortOption('Created Date', 'created')}
|
||||||
|
{renderSortOption('Updated Date', 'updated')}
|
||||||
|
{renderSortOption('Views', 'views')}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
const getSortedBrews = (brews)=>{
|
||||||
|
const testString = _.deburr(filterString).toLowerCase();
|
||||||
|
|
||||||
|
return _.orderBy(_.filter(brews, (brew)=>{
|
||||||
|
const brewStrings = _.deburr([brew.title, brew.description, brew.tags].join('\n').toLowerCase());
|
||||||
|
|
||||||
|
// Collect all brews that match the filter string and all of the filter tags
|
||||||
|
return brewStrings.includes(testString) && filterTags.every((tag)=>
|
||||||
|
Array.isArray(brew.tags) && //TODO: brew.tags should be converted to array at load so we don't have to catch it here
|
||||||
|
brew.tags.some((brewTag)=>brewTag.toLowerCase() == tag.toLowerCase())
|
||||||
|
);
|
||||||
|
}), brewSorters[sortType], sortDir);
|
||||||
|
};
|
||||||
|
|
||||||
|
const sortedBrewCollection = useMemo(()=>{
|
||||||
|
return brewCollection.map((brewGroup)=>({ ...brewGroup, brews: getSortedBrews(brewGroup.brews) }));
|
||||||
|
}, [brewCollection, filterString, filterTags, sortType, sortDir]);
|
||||||
|
|
||||||
|
const toggleBrewCollectionState = (brewGroupClass)=>{
|
||||||
|
const visible = !groupVisibility[brewGroupClass];
|
||||||
|
localStorage.setItem(`${USERPAGE_GROUP_VISIBILITY_PREFIX}_${brewGroupClass}`, visible);
|
||||||
|
setGroupVisibility({...groupVisibility, [brewGroupClass]: visible});
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderBrewCollection = ()=>{
|
||||||
|
if(sortedBrewCollection.length === 0)
|
||||||
|
return <h1>No Brews</h1>;
|
||||||
|
|
||||||
|
return sortedBrewCollection.map((brewGroup, idx)=>{
|
||||||
|
const visible = groupVisibility[brewGroup.class];
|
||||||
|
|
||||||
|
return (<>
|
||||||
|
<h1
|
||||||
|
className={visible ? 'active' : 'inactive'}
|
||||||
|
onClick={()=>toggleBrewCollectionState(brewGroup.class)}>
|
||||||
|
{brewGroup.title || 'No Title'}
|
||||||
|
</h1>
|
||||||
|
<div key={idx} className={`brewGroup ${brewGroup.class ?? ''} ${layoutMode}`}>
|
||||||
|
{visible ? renderBrews(brewGroup.brews) : <></>}
|
||||||
|
</div>
|
||||||
|
</>);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleLayoutChange = (mode)=>{
|
||||||
|
setLayoutMode(mode);
|
||||||
|
localStorage.setItem(USERPAGE_LAYOUT_MODE, mode);
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderLayoutModeOptions = ()=>(
|
||||||
|
<div className='radio-toggle layout-container'>
|
||||||
|
<h6>View:</h6>
|
||||||
|
<label className='option' title='grid'>
|
||||||
|
<input name='layout-mode' type='radio' onChange={()=>handleLayoutChange('grid')} checked={layoutMode === 'grid'} />
|
||||||
|
<i className='fac compressed-grid'></i>
|
||||||
|
</label>
|
||||||
|
<label className='option' title='list'>
|
||||||
|
<input name='layout-mode' type='radio' onChange={()=>handleLayoutChange('list')} checked={layoutMode === 'list'} />
|
||||||
|
<i className='fas fa-bars'></i>
|
||||||
|
</label>
|
||||||
|
<label className='option' title='card'>
|
||||||
|
<input name='layout-mode' type='radio' onChange={()=>handleLayoutChange('card')} checked={layoutMode === 'card'} />
|
||||||
|
<i className='fac format-card'></i>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleThemeChange = (mode)=>{
|
||||||
|
setThemeMode(mode);
|
||||||
|
localStorage.setItem(USERPAGE_THEME_MODE, mode);
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderThemePicker = ()=>(
|
||||||
|
<div className='radio-toggle theme-container'>
|
||||||
|
<h6>Theme:</h6>
|
||||||
|
<label className='option'>
|
||||||
|
<input type='radio' name='theme' onChange={()=>handleThemeChange('light')} checked={themeMode === 'light'}/>
|
||||||
|
<i className='fas fa-sun'/>
|
||||||
|
</label>
|
||||||
|
<label className='option'>
|
||||||
|
<input type='radio' name='theme' onChange={()=>handleThemeChange('dark')} checked={themeMode === 'dark'}/>
|
||||||
|
<i className='fas fa-moon'/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
const renderNav = ()=>(
|
||||||
|
<div className='listPageNav'>
|
||||||
|
{renderLayoutModeOptions()}
|
||||||
|
{renderThemePicker()}
|
||||||
|
{renderSortOptions()}
|
||||||
|
{renderFilterOption()}
|
||||||
|
{renderTagsOptions()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='sitePage listPage'>
|
||||||
|
{navItems}
|
||||||
|
|
||||||
|
{renderNav()}
|
||||||
|
|
||||||
|
<div className={`content V3 ${`${themeMode}Mode`}`}>
|
||||||
|
<div className='brewCollection'>{renderBrewCollection()}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ListPage;
|
||||||
@@ -1,163 +1,242 @@
|
|||||||
|
@import url('https://fonts.googleapis.com/css2?family=Alata&display=swap');
|
||||||
|
@import '@sharedStyles/colors.less';
|
||||||
|
@import '../../../../icons/customIcons.less';
|
||||||
|
|
||||||
.noColumns() {
|
.noColumns() {
|
||||||
column-count : auto;
|
-webkit-column-width : auto;
|
||||||
column-fill : auto;
|
-moz-column-width : auto;
|
||||||
column-gap : normal;
|
|
||||||
column-width : auto;
|
column-width : auto;
|
||||||
-webkit-column-count : auto;
|
-webkit-column-count : auto;
|
||||||
-moz-column-count : auto;
|
-moz-column-count : auto;
|
||||||
-webkit-column-width : auto;
|
column-count : auto;
|
||||||
-moz-column-width : auto;
|
column-fill : auto;
|
||||||
-webkit-column-gap : normal;
|
-webkit-column-gap : normal;
|
||||||
-moz-column-gap : normal;
|
-moz-column-gap : normal;
|
||||||
|
column-gap : normal;
|
||||||
height : auto;
|
height : auto;
|
||||||
min-height : 279.4mm;
|
min-height : 279.4mm;
|
||||||
margin : 20px auto;
|
margin : 20px auto;
|
||||||
contain : unset;
|
contain : unset;
|
||||||
}
|
}
|
||||||
.listPage {
|
|
||||||
|
.sitePage.listPage {
|
||||||
|
--bg-clr : white;
|
||||||
|
container-type: inline-size;
|
||||||
.content {
|
.content {
|
||||||
z-index : 1;
|
padding : clamp(20px, 5vh, 200px) clamp(20px, 20cqi, 200px);
|
||||||
.page {
|
overflow-y : scroll;
|
||||||
.noColumns() !important; //Needed to override PHB Theme since this is on a lower @layer
|
scrollbar-gutter : stable;
|
||||||
&::after { display : none; }
|
@container (max-width : 1200px) {
|
||||||
.noBrews {
|
padding : clamp(20px, 5vh, 200px) clamp(20px, 10cqi, 200px);
|
||||||
margin : 10px 0px;
|
}
|
||||||
font-size : 1.3em;
|
@container (max-width : 800px) {
|
||||||
font-style : italic;
|
padding : clamp(20px, 5vh, 200px) clamp(20px, 5cqi, 200px);
|
||||||
|
}
|
||||||
|
|
||||||
|
&::-webkit-scrollbar {
|
||||||
|
width : 15px;
|
||||||
|
&:horizontal {
|
||||||
|
width : auto;
|
||||||
|
height : 20px;
|
||||||
}
|
}
|
||||||
.brewCollection {
|
&-thumb {
|
||||||
h1:hover { cursor : pointer; }
|
background : linear-gradient(90deg, var(--bg-clr) 12px, #00000000 12px);
|
||||||
.active::before, .inactive::before {
|
&:horizontal { background : linear-gradient(0deg, var(--bg-clr) 15px, #00000000 15px); }
|
||||||
|
}
|
||||||
|
&-corner { visibility : hidden; }
|
||||||
|
}
|
||||||
|
|
||||||
|
.noBrews {
|
||||||
|
margin : 10px 0px;
|
||||||
|
font-size : 1.3em;
|
||||||
|
font-style : italic;
|
||||||
|
font-weight : 900;
|
||||||
|
color : white;
|
||||||
|
}
|
||||||
|
.brewCollection {
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
width : fit-content;
|
||||||
|
margin-bottom : 20px;
|
||||||
|
font-size : 25px;
|
||||||
|
color : #DDDDDD;
|
||||||
|
|
||||||
|
&.active::before,
|
||||||
|
&.inactive::before {
|
||||||
padding-right : 0.5em;
|
padding-right : 0.5em;
|
||||||
font-family : 'Font Awesome 6 Free';
|
font-family : 'Font Awesome 6 Free';
|
||||||
font-size : 0.6cm;
|
font-size : 0.6cm;
|
||||||
font-weight : 900;
|
font-weight : 900;
|
||||||
}
|
}
|
||||||
.active { color : var(--HB_Color_HeaderText); }
|
&.active {
|
||||||
.active::before { content : '\f107'; }
|
color : white;
|
||||||
.inactive { color : #707070; }
|
&::before { content : '\f107'; }
|
||||||
.inactive::before { content : '\f105'; }
|
}
|
||||||
|
&.inactive::before { content : '\f105'; }
|
||||||
|
}
|
||||||
|
h1:hover { cursor : pointer; }
|
||||||
|
|
||||||
|
.brewGroup {
|
||||||
|
margin-bottom : 20px;
|
||||||
|
&.grid {
|
||||||
|
display : flex;
|
||||||
|
flex-wrap : wrap;
|
||||||
|
gap : 20px;
|
||||||
|
justify-content : center;
|
||||||
|
width : fit-content;
|
||||||
|
min-width : 200px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.list {
|
||||||
|
display : flex;
|
||||||
|
flex-direction : column;
|
||||||
|
gap : 2px;
|
||||||
|
}
|
||||||
|
&.card {
|
||||||
|
--columns : 4;
|
||||||
|
display : grid;
|
||||||
|
grid-template-columns : repeat(var(--columns), 1fr);
|
||||||
|
gap : 20px;
|
||||||
|
justify-items : center;
|
||||||
|
|
||||||
|
@container (max-width : 1700px) {--columns : 3;}
|
||||||
|
@container (max-width : 1400px) {--columns : 2;}
|
||||||
|
@container (max-width : 900px) {--columns : 1;}
|
||||||
|
h1 { position : absolute; }
|
||||||
|
|
||||||
|
&:not(:has(.brewItem:last-child:nth-child(3n))) {
|
||||||
|
.brewItem:last-child {
|
||||||
|
margin-right : auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.sort-container {
|
|
||||||
position : sticky;
|
.listPageNav {
|
||||||
top : 0;
|
position : relative;
|
||||||
left : 0;
|
display : flex;
|
||||||
z-index : 1;
|
flex-wrap : wrap;
|
||||||
display : flex;
|
row-gap : 10px;
|
||||||
flex-wrap : wrap;
|
column-gap : 20px;
|
||||||
row-gap : 5px;
|
align-items : center;
|
||||||
column-gap : 15px;
|
justify-content : center;
|
||||||
align-items : baseline;
|
width : 100%;
|
||||||
justify-content : center;
|
height : fit-content;
|
||||||
width : 100%;
|
font-family : 'Open Sans', sans-serif;
|
||||||
height : 30px;
|
color : white;
|
||||||
font-family : 'Open Sans', sans-serif;
|
background : #555555;
|
||||||
color : white;
|
border-top : 1px solid #666666;
|
||||||
text-align : center;
|
border-bottom : 1px solid #666666;
|
||||||
background-color : #555555;
|
row-rule : 1px solid #666666;
|
||||||
border-top : 1px solid #666666;
|
|
||||||
border-bottom : 1px solid #666666;
|
> div {
|
||||||
h6 {
|
width : fit-content;
|
||||||
font-family : 'Open Sans', sans-serif;
|
height : 30px;
|
||||||
font-size : 11px;
|
padding-inline : 10px;
|
||||||
font-weight : bold;
|
|
||||||
text-transform : uppercase;
|
|
||||||
}
|
}
|
||||||
.sort-option {
|
|
||||||
display : flex;
|
|
||||||
align-items : center;
|
|
||||||
height : 100%;
|
|
||||||
padding : 0 8px;
|
|
||||||
color : #CCCCCC;
|
|
||||||
|
|
||||||
&:hover { background-color : #444444; }
|
.radio-toggle {
|
||||||
|
z-index : 1;
|
||||||
&.active {
|
display : flex;
|
||||||
font-weight : bold;
|
flex-wrap : wrap;
|
||||||
color : #DDDDDD;
|
row-gap : 5px;
|
||||||
background-color : #333333;
|
align-items : center;
|
||||||
|
justify-content : center;
|
||||||
button {
|
text-align : center;
|
||||||
height : 100%;
|
h6 {
|
||||||
font-weight : 800;
|
font-size : 14px;
|
||||||
color : white;
|
margin-right:5px;
|
||||||
& + .sortDir { padding-left : 5px; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.option {
|
||||||
|
display : flex;
|
||||||
|
align-items : center;
|
||||||
|
height : 100%;
|
||||||
|
padding : 0 8px;
|
||||||
|
color : #CCCCCC;
|
||||||
|
|
||||||
|
input[type='radio'] { display : none; }
|
||||||
|
|
||||||
|
button {
|
||||||
|
padding : 0;
|
||||||
|
font-size : 11px;
|
||||||
|
font-weight : normal;
|
||||||
|
text-transform : uppercase;
|
||||||
|
background-color : transparent;
|
||||||
|
}
|
||||||
|
&:hover { background-color : #444444; }
|
||||||
|
|
||||||
|
&.active, &:has(input:checked) {
|
||||||
|
font-weight : bold;
|
||||||
|
color : white;
|
||||||
|
background-color : #333333;
|
||||||
|
|
||||||
|
button {
|
||||||
|
height : 100%;
|
||||||
|
font-weight : 800;
|
||||||
|
& + .sortDir { padding-left : 5px; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.filter-option {
|
.filter-option {
|
||||||
margin-left : 20px;
|
display : grid;
|
||||||
|
place-items : center;
|
||||||
font-size : 11px;
|
font-size : 11px;
|
||||||
background-color : transparent !important;
|
background-color : transparent !important;
|
||||||
i { padding-right : 5px; }
|
i { padding-right : 5px; }
|
||||||
}
|
}
|
||||||
button {
|
.tags-container {
|
||||||
padding : 0;
|
display : flex;
|
||||||
font-family : 'Open Sans', sans-serif;
|
flex-wrap : wrap;
|
||||||
font-size : 11px;
|
row-gap : 5px;
|
||||||
font-weight : normal;
|
column-gap : 15px;
|
||||||
color : #CCCCCC;
|
align-items : center;
|
||||||
text-transform : uppercase;
|
justify-content : center;
|
||||||
background-color : transparent;
|
height : 30px;
|
||||||
}
|
span {
|
||||||
|
padding : 3px;
|
||||||
|
font-family : 'Open Sans', sans-serif;
|
||||||
}
|
font-size : 11px;
|
||||||
.tags-container {
|
font-weight : bold;
|
||||||
display : flex;
|
color : #DFDFDF;
|
||||||
flex-wrap : wrap;
|
cursor : pointer;
|
||||||
row-gap : 5px;
|
border : 1px solid;
|
||||||
column-gap : 15px;
|
border-radius : 3px;
|
||||||
align-items : center;
|
&::before {
|
||||||
justify-content : center;
|
margin-right : 3px;
|
||||||
height : 30px;
|
font-family : 'Font Awesome 6 Free';
|
||||||
color : white;
|
font-size : 12px;
|
||||||
background-color : #555555;
|
}
|
||||||
border-top : 1px solid #666666;
|
&::after {
|
||||||
border-bottom : 1px solid #666666;
|
margin-left : 3px;
|
||||||
span {
|
font-family : 'Font Awesome 6 Free';
|
||||||
padding : 3px;
|
font-size : 12px;
|
||||||
font-family : 'Open Sans', sans-serif;
|
content : '\f00d';
|
||||||
font-size : 11px;
|
}
|
||||||
font-weight : bold;
|
&.type {
|
||||||
color : #DFDFDF;
|
background-color : #008000;
|
||||||
cursor : pointer;
|
border-color : #00A000;
|
||||||
border : 1px solid;
|
&::before { content : '\f0ad'; }
|
||||||
border-radius : 3px;
|
}
|
||||||
&::before {
|
&.group {
|
||||||
margin-right : 3px;
|
background-color : #505050;
|
||||||
font-family : 'Font Awesome 6 Free';
|
border-color : #000000;
|
||||||
font-size : 12px;
|
&::before { content : '\f500'; }
|
||||||
}
|
}
|
||||||
&::after {
|
&.meta {
|
||||||
margin-left : 3px;
|
background-color : #000080;
|
||||||
font-family : 'Font Awesome 6 Free';
|
border-color : #0000A0;
|
||||||
font-size : 12px;
|
&::before { content : '\f05a'; }
|
||||||
content : '\f00d';
|
}
|
||||||
}
|
&.system {
|
||||||
&.type {
|
background-color : #800000;
|
||||||
background-color : #008000;
|
border-color : #A00000;
|
||||||
border-color : #00A000;
|
&::before { content : '\f518'; }
|
||||||
&::before { content : '\f0ad'; }
|
}
|
||||||
}
|
|
||||||
&.group {
|
|
||||||
background-color : #505050;
|
|
||||||
border-color : #000000;
|
|
||||||
&::before { content : '\f500'; }
|
|
||||||
}
|
|
||||||
&.meta {
|
|
||||||
background-color : #000080;
|
|
||||||
border-color : #0000A0;
|
|
||||||
&::before { content : '\f05a'; }
|
|
||||||
}
|
|
||||||
&.system {
|
|
||||||
background-color : #800000;
|
|
||||||
border-color : #A00000;
|
|
||||||
&::before { content : '\f518'; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,38 +1,28 @@
|
|||||||
require('./uiPage.less');
|
import './uiPage.less';
|
||||||
const React = require('react');
|
import Nav from '../../../navbar/nav.jsx';
|
||||||
const createClass = require('create-react-class');
|
import Navbar from '../../../navbar/navbar.jsx';
|
||||||
|
import NewBrewItem from '../../../navbar/newbrew.navitem.jsx';
|
||||||
|
import HelpNavItem from '../../../navbar/help.navitem.jsx';
|
||||||
|
import RecentNavItems from '../../../navbar/recent.navitem.jsx';
|
||||||
|
const { both: RecentNavItem } = RecentNavItems;
|
||||||
|
import Account from '../../../navbar/account.navitem.jsx';
|
||||||
|
|
||||||
const Nav = require('client/homebrew/navbar/nav.jsx');
|
const UIPage = ({ brew, children })=><div className='sitePage uiPage'>
|
||||||
const Navbar = require('client/homebrew/navbar/navbar.jsx');
|
<Navbar>
|
||||||
const NewBrewItem = require('client/homebrew/navbar/newbrew.navitem.jsx');
|
<Nav.section>
|
||||||
const HelpNavItem = require('client/homebrew/navbar/help.navitem.jsx');
|
<Nav.item className='brewTitle'>{brew?.title}</Nav.item>
|
||||||
const RecentNavItem = require('client/homebrew/navbar/recent.navitem.jsx').both;
|
</Nav.section>
|
||||||
const Account = require('client/homebrew/navbar/account.navitem.jsx');
|
<Nav.section>
|
||||||
|
<NewBrewItem />
|
||||||
|
<HelpNavItem />
|
||||||
|
<RecentNavItem />
|
||||||
|
<Account />
|
||||||
|
</Nav.section>
|
||||||
|
</Navbar>
|
||||||
|
|
||||||
|
<div className='content'>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</div>;
|
||||||
|
|
||||||
const UIPage = createClass({
|
export default UIPage;
|
||||||
displayName : 'UIPage',
|
|
||||||
|
|
||||||
render : function(){
|
|
||||||
return <div className='uiPage sitePage'>
|
|
||||||
<Navbar>
|
|
||||||
<Nav.section>
|
|
||||||
<Nav.item className='brewTitle'>{this.props.brew.title}</Nav.item>
|
|
||||||
</Nav.section>
|
|
||||||
|
|
||||||
<Nav.section>
|
|
||||||
<NewBrewItem />
|
|
||||||
<HelpNavItem />
|
|
||||||
<RecentNavItem />
|
|
||||||
<Account />
|
|
||||||
</Nav.section>
|
|
||||||
</Navbar>
|
|
||||||
|
|
||||||
<div className='content'>
|
|
||||||
{this.props.children}
|
|
||||||
</div>
|
|
||||||
</div>;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = UIPage;
|
|
||||||
@@ -1,53 +1,14 @@
|
|||||||
/* eslint-disable max-lines */
|
|
||||||
import './editPage.less';
|
import './editPage.less';
|
||||||
|
|
||||||
// Common imports
|
import React from 'react';
|
||||||
import React, { useState, useEffect, useRef } from 'react';
|
import request from '../../utils/request-middleware.js';
|
||||||
import request from '../../utils/request-middleware.js';
|
import _ from 'lodash';
|
||||||
import Markdown from 'markdown.js';
|
import EditorPage from '../basePages/editPage/editorPage.jsx';
|
||||||
import _ from 'lodash';
|
import { DEFAULT_BREW_LOAD } from '../../../../server/brewDefaults.js';
|
||||||
|
|
||||||
import { DEFAULT_BREW_LOAD } from '../../../../server/brewDefaults.js';
|
|
||||||
import { printCurrentBrew, fetchThemeBundle, splitTextStyleAndMetadata } from '../../../../shared/helpers.js';
|
|
||||||
|
|
||||||
import SplitPane from 'client/components/splitPane/splitPane.jsx';
|
|
||||||
import Editor from '../../editor/editor.jsx';
|
|
||||||
import BrewRenderer from '../../brewRenderer/brewRenderer.jsx';
|
|
||||||
|
|
||||||
import Nav from 'client/homebrew/navbar/nav.jsx';
|
|
||||||
import Navbar from 'client/homebrew/navbar/navbar.jsx';
|
|
||||||
import NewBrewItem from 'client/homebrew/navbar/newbrew.navitem.jsx';
|
|
||||||
import AccountNavItem from 'client/homebrew/navbar/account.navitem.jsx';
|
|
||||||
import ErrorNavItem from 'client/homebrew/navbar/error-navitem.jsx';
|
|
||||||
import HelpNavItem from 'client/homebrew/navbar/help.navitem.jsx';
|
|
||||||
import VaultNavItem from 'client/homebrew/navbar/vault.navitem.jsx';
|
|
||||||
import PrintNavItem from 'client/homebrew/navbar/print.navitem.jsx';
|
|
||||||
import { both as RecentNavItem } from 'client/homebrew/navbar/recent.navitem.jsx';
|
|
||||||
|
|
||||||
// Page specific imports
|
// Page specific imports
|
||||||
import { Meta } from 'vitreum/headtags';
|
|
||||||
import { md5 } from 'hash-wasm';
|
|
||||||
import { gzipSync, strToU8 } from 'fflate';
|
import { gzipSync, strToU8 } from 'fflate';
|
||||||
import { makePatches, stringifyPatches } from '@sanity/diff-match-patch';
|
|
||||||
|
|
||||||
import ShareNavItem from 'client/homebrew/navbar/share.navitem.jsx';
|
|
||||||
import LockNotification from './lockNotification/lockNotification.jsx';
|
|
||||||
import { updateHistory, versionHistoryGarbageCollection } from '../../utils/versionHistory.js';
|
import { updateHistory, versionHistoryGarbageCollection } from '../../utils/versionHistory.js';
|
||||||
import googleDriveIcon from '../../googleDrive.svg';
|
|
||||||
|
|
||||||
const SAVE_TIMEOUT = 10000;
|
|
||||||
const UNSAVED_WARNING_TIMEOUT = 900000; //Warn user afer 15 minutes of unsaved changes
|
|
||||||
const UNSAVED_WARNING_POPUP_TIMEOUT = 4000; //Show the warning for 4 seconds
|
|
||||||
|
|
||||||
|
|
||||||
const AUTOSAVE_KEY = 'HB_editor_autoSaveOn';
|
|
||||||
const BREWKEY = 'HB_newPage_content';
|
|
||||||
const STYLEKEY = 'HB_newPage_style';
|
|
||||||
const SNIPKEY = 'HB_newPage_snippets';
|
|
||||||
const METAKEY = 'HB_newPage_meta';
|
|
||||||
|
|
||||||
const useLocalStorage = false;
|
|
||||||
const neverSaved = false;
|
|
||||||
|
|
||||||
const EditPage = (props)=>{
|
const EditPage = (props)=>{
|
||||||
props = {
|
props = {
|
||||||
@@ -55,364 +16,46 @@ const EditPage = (props)=>{
|
|||||||
...props
|
...props
|
||||||
};
|
};
|
||||||
|
|
||||||
const [currentBrew , setCurrentBrew ] = useState(props.brew);
|
|
||||||
const [isSaving , setIsSaving ] = useState(false);
|
|
||||||
const [lastSavedTime , setLastSavedTime ] = useState(new Date());
|
|
||||||
const [saveGoogle , setSaveGoogle ] = useState(!!props.brew.googleId);
|
|
||||||
const [error , setError ] = useState(null);
|
|
||||||
const [HTMLErrors , setHTMLErrors ] = useState(Markdown.validate(props.brew.text));
|
|
||||||
const [currentEditorViewPageNum , setCurrentEditorViewPageNum ] = useState(1);
|
|
||||||
const [currentEditorCursorPageNum, setCurrentEditorCursorPageNum] = useState(1);
|
|
||||||
const [currentBrewRendererPageNum, setCurrentBrewRendererPageNum] = useState(1);
|
|
||||||
const [themeBundle , setThemeBundle ] = useState({});
|
|
||||||
const [unsavedChanges , setUnsavedChanges ] = useState(false);
|
|
||||||
const [alertTrashedGoogleBrew , setAlertTrashedGoogleBrew ] = useState(props.brew.trashed);
|
|
||||||
const [alertLoginToTransfer , setAlertLoginToTransfer ] = useState(false);
|
|
||||||
const [confirmGoogleTransfer , setConfirmGoogleTransfer ] = useState(false);
|
|
||||||
const [autoSaveEnabled , setAutoSaveEnabled ] = useState(true);
|
|
||||||
const [warnUnsavedChanges , setWarnUnsavedChanges ] = useState(true);
|
|
||||||
|
|
||||||
const editorRef = useRef(null);
|
|
||||||
const lastSavedBrew = useRef(_.cloneDeep(props.brew));
|
|
||||||
const saveTimeout = useRef(null);
|
|
||||||
const warnUnsavedTimeout = useRef(null);
|
|
||||||
const trySaveRef = useRef(trySave); // CTRL+S listener lives outside React and needs ref to use trySave with latest copy of brew
|
|
||||||
const unsavedChangesRef = useRef(unsavedChanges); // Similarly, onBeforeUnload lives outside React and needs ref to unsavedChanges
|
|
||||||
|
|
||||||
useEffect(()=>{
|
|
||||||
const autoSavePref = JSON.parse(localStorage.getItem(AUTOSAVE_KEY) ?? true);
|
|
||||||
setAutoSaveEnabled(autoSavePref);
|
|
||||||
setWarnUnsavedChanges(!autoSavePref);
|
|
||||||
setHTMLErrors(Markdown.validate(currentBrew.text));
|
|
||||||
fetchThemeBundle(setError, setThemeBundle, currentBrew.renderer, currentBrew.theme);
|
|
||||||
|
|
||||||
const handleControlKeys = (e)=>{
|
|
||||||
if(!(e.ctrlKey || e.metaKey)) return;
|
|
||||||
if(e.keyCode === 83) trySaveRef.current(true);
|
|
||||||
if(e.keyCode === 80) printCurrentBrew();
|
|
||||||
if([83, 80].includes(e.keyCode)) {
|
|
||||||
e.stopPropagation();
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
document.addEventListener('keydown', handleControlKeys);
|
|
||||||
window.onbeforeunload = ()=>{
|
|
||||||
if(unsavedChangesRef.current)
|
|
||||||
return 'You have unsaved changes!';
|
|
||||||
};
|
|
||||||
return ()=>{
|
|
||||||
document.removeEventListener('keydown', handleControlKeys);
|
|
||||||
window.onBeforeUnload = null;
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(()=>{
|
|
||||||
trySaveRef.current = trySave;
|
|
||||||
unsavedChangesRef.current = unsavedChanges;
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(()=>{
|
|
||||||
const hasChange = !_.isEqual(currentBrew, lastSavedBrew.current);
|
|
||||||
setUnsavedChanges(hasChange);
|
|
||||||
|
|
||||||
if(autoSaveEnabled) trySave(false, hasChange);
|
|
||||||
}, [currentBrew]);
|
|
||||||
|
|
||||||
useEffect(()=>{
|
|
||||||
trySave(true);
|
|
||||||
}, [saveGoogle]);
|
|
||||||
|
|
||||||
const handleSplitMove = ()=>{
|
|
||||||
editorRef.current?.update();
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleBrewChange = (field)=>(value, subfield)=>{ //'text', 'style', 'snippets', 'metadata'
|
|
||||||
if(subfield == 'renderer' || subfield == 'theme')
|
|
||||||
fetchThemeBundle(setError, setThemeBundle, value.renderer, value.theme);
|
|
||||||
|
|
||||||
//If there are HTML errors, run the validator on every change to give quick feedback
|
|
||||||
if(HTMLErrors.length && (field == 'text' || field == 'snippets'))
|
|
||||||
setHTMLErrors(Markdown.validate(value));
|
|
||||||
|
|
||||||
if(field == 'metadata') setCurrentBrew((prev)=>({ ...prev, ...value }));
|
|
||||||
else setCurrentBrew((prev)=>({ ...prev, [field]: value }));
|
|
||||||
|
|
||||||
if(useLocalStorage) {
|
|
||||||
if(field == 'text') localStorage.setItem(BREWKEY, value);
|
|
||||||
if(field == 'style') localStorage.setItem(STYLEKEY, value);
|
|
||||||
if(field == 'snippets') localStorage.setItem(SNIPKEY, value);
|
|
||||||
if(field == 'metadata') localStorage.setItem(METAKEY, JSON.stringify({
|
|
||||||
renderer : value.renderer,
|
|
||||||
theme : value.theme,
|
|
||||||
lang : value.lang
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateBrew = (newData)=>setCurrentBrew((prevBrew)=>({
|
|
||||||
...prevBrew,
|
|
||||||
style : newData.style,
|
|
||||||
text : newData.text,
|
|
||||||
snippets : newData.snippets
|
|
||||||
}));
|
|
||||||
|
|
||||||
const resetWarnUnsavedTimer = ()=>{
|
|
||||||
setTimeout(()=>setWarnUnsavedChanges(false), UNSAVED_WARNING_POPUP_TIMEOUT); // Hide the warning after 4 seconds
|
|
||||||
clearTimeout(warnUnsavedTimeout.current);
|
|
||||||
warnUnsavedTimeout.current = setTimeout(()=>setWarnUnsavedChanges(true), UNSAVED_WARNING_TIMEOUT); // 15 minutes between unsaved work warnings
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleGoogleClick = ()=>{
|
|
||||||
if(!global.account?.googleId) {
|
|
||||||
setAlertLoginToTransfer(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setConfirmGoogleTransfer((prev)=>!prev);
|
|
||||||
setError(null);
|
|
||||||
};
|
|
||||||
|
|
||||||
const closeAlerts = (e)=>{
|
|
||||||
e.stopPropagation(); //Only handle click once so alert doesn't reopen
|
|
||||||
setAlertTrashedGoogleBrew(false);
|
|
||||||
setAlertLoginToTransfer(false);
|
|
||||||
setConfirmGoogleTransfer(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const toggleGoogleStorage = ()=>{
|
|
||||||
setSaveGoogle((prev)=>!prev);
|
|
||||||
setError(null);
|
|
||||||
};
|
|
||||||
|
|
||||||
const trySave = (immediate = false, hasChanges = true)=>{
|
|
||||||
clearTimeout(saveTimeout.current);
|
|
||||||
if(isSaving) return;
|
|
||||||
if(!hasChanges && !immediate) return;
|
|
||||||
const newTimeout = immediate ? 0 : SAVE_TIMEOUT;
|
|
||||||
|
|
||||||
saveTimeout.current = setTimeout(async ()=>{
|
|
||||||
setIsSaving(true);
|
|
||||||
setError(null);
|
|
||||||
await save(currentBrew, saveGoogle)
|
|
||||||
.catch((err)=>{
|
|
||||||
setError(err);
|
|
||||||
});
|
|
||||||
setIsSaving(false);
|
|
||||||
setLastSavedTime(new Date());
|
|
||||||
if(!autoSaveEnabled) resetWarnUnsavedTimer();
|
|
||||||
}, newTimeout);
|
|
||||||
};
|
|
||||||
|
|
||||||
const save = async (brew, saveToGoogle)=>{
|
const save = async (brew, saveToGoogle)=>{
|
||||||
setHTMLErrors(Markdown.validate(brew.text));
|
|
||||||
|
|
||||||
await updateHistory(brew).catch(console.error);
|
await updateHistory(brew).catch(console.error);
|
||||||
await versionHistoryGarbageCollection().catch(console.error);
|
await versionHistoryGarbageCollection().catch(console.error);
|
||||||
|
|
||||||
//Prepare content to send to server
|
const compressedBrew = gzipSync(strToU8(JSON.stringify(brew)));
|
||||||
const brewToSave = {
|
|
||||||
...brew,
|
|
||||||
text : brew.text.normalize('NFC'),
|
|
||||||
pageCount : ((brew.renderer === 'legacy' ? brew.text.match(/\\page/g) : brew.text.match(/^\\page$/gm)) || []).length + 1,
|
|
||||||
patches : stringifyPatches(makePatches(encodeURI(lastSavedBrew.current.text.normalize('NFC')), encodeURI(brew.text.normalize('NFC')))),
|
|
||||||
hash : await md5(lastSavedBrew.current.text),
|
|
||||||
textBin : undefined,
|
|
||||||
version : lastSavedBrew.current.version
|
|
||||||
};
|
|
||||||
|
|
||||||
const compressedBrew = gzipSync(strToU8(JSON.stringify(brewToSave)));
|
|
||||||
const transfer = saveToGoogle === _.isNil(brew.googleId);
|
const transfer = saveToGoogle === _.isNil(brew.googleId);
|
||||||
const params = transfer ? `?${saveToGoogle ? 'saveToGoogle' : 'removeFromGoogle'}=true` : '';
|
const params = transfer ? `?${saveToGoogle ? 'saveToGoogle' : 'removeFromGoogle'}=true` : '';
|
||||||
|
|
||||||
const res = await request
|
const res = await request
|
||||||
.put(`/api/update/${brewToSave.editId}${params}`)
|
.put(`/api/update/${brew.editId}${params}`)
|
||||||
.set('Content-Encoding', 'gzip')
|
.set('Content-Encoding', 'gzip')
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.send(compressedBrew)
|
.send(compressedBrew);
|
||||||
.catch((err)=>{
|
|
||||||
console.error('Error Updating Local Brew');
|
|
||||||
setError(err);
|
|
||||||
});
|
|
||||||
if(!res) return;
|
|
||||||
|
|
||||||
const updatedFields = {
|
const updatedFields = {
|
||||||
googleId : res.body.googleId ?? null,
|
googleId : res.body.googleId ?? null, //TODO: investigate if we can set googleId:null in server/update instead of undefined
|
||||||
editId : res.body.editId,
|
editId : res.body.editId, //then, editPage can just apply res.body instead of breaking out these fields.
|
||||||
shareId : res.body.shareId,
|
shareId : res.body.shareId,
|
||||||
version : res.body.version
|
version : res.body.version
|
||||||
};
|
};
|
||||||
|
|
||||||
lastSavedBrew.current = {
|
return updatedFields;
|
||||||
...brew,
|
|
||||||
...updatedFields
|
|
||||||
};
|
|
||||||
|
|
||||||
setCurrentBrew((prevBrew)=>({
|
|
||||||
...prevBrew,
|
|
||||||
...updatedFields
|
|
||||||
}));
|
|
||||||
|
|
||||||
history.replaceState(null, null, `/edit/${res.body.editId}`);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderGoogleDriveIcon = ()=>(
|
const onSaveSuccess = (savedBrew)=>{
|
||||||
<Nav.item className='googleDriveStorage' onClick={handleGoogleClick}>
|
history.replaceState(null, null, `/edit/${savedBrew.editId}`);;
|
||||||
<img src={googleDriveIcon} className={saveGoogle ? '' : 'inactive'} alt='Google Drive icon' />
|
|
||||||
|
|
||||||
{confirmGoogleTransfer && (
|
|
||||||
<div className='errorContainer' onClick={closeAlerts}>
|
|
||||||
{saveGoogle
|
|
||||||
? 'Would you like to transfer this brew from your Google Drive storage back to the Homebrewery?'
|
|
||||||
: 'Would you like to transfer this brew from the Homebrewery to your personal Google Drive storage?'}
|
|
||||||
<br />
|
|
||||||
<div className='confirm' onClick={toggleGoogleStorage}> Yes </div>
|
|
||||||
<div className='deny'> No </div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{alertLoginToTransfer && (
|
|
||||||
<div className='errorContainer' onClick={closeAlerts}>
|
|
||||||
You must be signed in to a Google account to transfer between the homebrewery and Google Drive!
|
|
||||||
<a target='_blank' rel='noopener noreferrer' href={`https://www.naturalcrit.com/login?redirect=${window.location.href}`}>
|
|
||||||
<div className='confirm'> Sign In </div>
|
|
||||||
</a>
|
|
||||||
<div className='deny'> Not Now </div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{alertTrashedGoogleBrew && (
|
|
||||||
<div className='errorContainer' onClick={closeAlerts}>
|
|
||||||
This brew is currently in your Trash folder on Google Drive!<br />
|
|
||||||
If you want to keep it, make sure to move it before it is deleted permanently!<br />
|
|
||||||
<div className='confirm'> OK </div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</Nav.item>
|
|
||||||
);
|
|
||||||
|
|
||||||
const renderSaveButton = ()=>{
|
|
||||||
// #1 - Currently saving, show SAVING
|
|
||||||
if(isSaving)
|
|
||||||
return <Nav.item className='save' icon='fas fa-spinner fa-spin'>saving...</Nav.item>;
|
|
||||||
|
|
||||||
// #2 - Unsaved changes exist, autosave is OFF and warning timer has expired, show AUTOSAVE WARNING
|
|
||||||
if(unsavedChanges && warnUnsavedChanges) {
|
|
||||||
resetWarnUnsavedTimer();
|
|
||||||
const elapsedTime = Math.round((new Date() - lastSavedTime) / 1000 / 60);
|
|
||||||
const text = elapsedTime === 0
|
|
||||||
? 'Autosave is OFF.'
|
|
||||||
: `Autosave is OFF, and you haven't saved for ${elapsedTime} minutes.`;
|
|
||||||
|
|
||||||
return <Nav.item className='save error' icon='fas fa-exclamation-circle'>
|
|
||||||
Reminder...
|
|
||||||
<div className='errorContainer'>{text}</div>
|
|
||||||
</Nav.item>;
|
|
||||||
}
|
|
||||||
|
|
||||||
// #3 - Unsaved changes exist, click to save, show SAVE NOW
|
|
||||||
if(unsavedChanges)
|
|
||||||
return <Nav.item className='save' onClick={()=>trySave(true)} color='blue' icon='fas fa-save'>save now</Nav.item>;
|
|
||||||
|
|
||||||
// #4 - No unsaved changes, autosave is ON, show AUTO-SAVED
|
|
||||||
if(autoSaveEnabled)
|
|
||||||
return <Nav.item className='save saved'>auto-saved</Nav.item>;
|
|
||||||
|
|
||||||
// #5 - No unsaved changes, and has never been saved, hide the button
|
|
||||||
if(neverSaved)
|
|
||||||
return <Nav.item className='save neverSaved'>save now</Nav.item>;
|
|
||||||
|
|
||||||
// DEFAULT - No unsaved changes, show SAVED
|
|
||||||
return <Nav.item className='save saved'>saved</Nav.item>;
|
|
||||||
};
|
|
||||||
|
|
||||||
const toggleAutoSave = ()=>{
|
|
||||||
clearTimeout(warnUnsavedTimeout.current);
|
|
||||||
clearTimeout(saveTimeout.current);
|
|
||||||
localStorage.setItem(AUTOSAVE_KEY, JSON.stringify(!autoSaveEnabled));
|
|
||||||
setAutoSaveEnabled(!autoSaveEnabled);
|
|
||||||
setWarnUnsavedChanges(autoSaveEnabled);
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderAutoSaveButton = ()=>(
|
|
||||||
<Nav.item onClick={toggleAutoSave}>
|
|
||||||
Autosave <i className={autoSaveEnabled ? 'fas fa-power-off active' : 'fas fa-power-off'}></i>
|
|
||||||
</Nav.item>
|
|
||||||
);
|
|
||||||
|
|
||||||
const clearError = ()=>{
|
|
||||||
setError(null);
|
|
||||||
setIsSaving(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderNavbar = ()=>{
|
|
||||||
return <Navbar>
|
|
||||||
<Nav.section>
|
|
||||||
<Nav.item className='brewTitle'>{currentBrew.title}</Nav.item>
|
|
||||||
</Nav.section>
|
|
||||||
|
|
||||||
<Nav.section>
|
|
||||||
{renderGoogleDriveIcon()}
|
|
||||||
{error
|
|
||||||
? <ErrorNavItem error={error} clearError={clearError} />
|
|
||||||
: <Nav.dropdown className='save-menu'>
|
|
||||||
{renderSaveButton()}
|
|
||||||
{renderAutoSaveButton()}
|
|
||||||
</Nav.dropdown>}
|
|
||||||
<NewBrewItem />
|
|
||||||
<PrintNavItem />
|
|
||||||
<HelpNavItem />
|
|
||||||
<VaultNavItem />
|
|
||||||
<ShareNavItem brew={currentBrew} />
|
|
||||||
<RecentNavItem brew={currentBrew} storageKey='edit' />
|
|
||||||
<AccountNavItem/>
|
|
||||||
</Nav.section>
|
|
||||||
</Navbar>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='editPage sitePage'>
|
<EditorPage
|
||||||
<Meta name='robots' content='noindex, nofollow' />
|
useLocalStorage = {false}
|
||||||
|
sandbox = {false}
|
||||||
{renderNavbar()}
|
showFloatingButtons = {false}
|
||||||
|
showEditorButtons = {true}
|
||||||
{currentBrew.lock && <LockNotification shareId={currentBrew.shareId} message={currentBrew.lock.editMessage} reviewRequested={currentBrew.lock.reviewRequested}/>}
|
pageName = {'editPage'}
|
||||||
|
brew = {props.brew}
|
||||||
<div className='content'>
|
userThemes = {props.userThemes}
|
||||||
<SplitPane onDragFinish={handleSplitMove}>
|
save = {save}
|
||||||
<Editor
|
onSaveSuccess = {onSaveSuccess}
|
||||||
ref={editorRef}
|
></EditorPage>);
|
||||||
brew={currentBrew}
|
|
||||||
onBrewChange={handleBrewChange}
|
|
||||||
reportError={setError}
|
|
||||||
renderer={currentBrew.renderer}
|
|
||||||
userThemes={props.userThemes}
|
|
||||||
themeBundle={themeBundle}
|
|
||||||
updateBrew={updateBrew}
|
|
||||||
onCursorPageChange={setCurrentEditorCursorPageNum}
|
|
||||||
onViewPageChange={setCurrentEditorViewPageNum}
|
|
||||||
currentEditorViewPageNum={currentEditorViewPageNum}
|
|
||||||
currentEditorCursorPageNum={currentEditorCursorPageNum}
|
|
||||||
currentBrewRendererPageNum={currentBrewRendererPageNum}
|
|
||||||
/>
|
|
||||||
<BrewRenderer
|
|
||||||
text={currentBrew.text}
|
|
||||||
style={currentBrew.style}
|
|
||||||
renderer={currentBrew.renderer}
|
|
||||||
theme={currentBrew.theme}
|
|
||||||
themeBundle={themeBundle}
|
|
||||||
errors={HTMLErrors}
|
|
||||||
lang={currentBrew.lang}
|
|
||||||
onPageChange={setCurrentBrewRendererPageNum}
|
|
||||||
currentEditorViewPageNum={currentEditorViewPageNum}
|
|
||||||
currentEditorCursorPageNum={currentEditorCursorPageNum}
|
|
||||||
currentBrewRendererPageNum={currentBrewRendererPageNum}
|
|
||||||
allowPrint={true}
|
|
||||||
/>
|
|
||||||
</SplitPane>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = EditPage;
|
export default EditPage;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import './lockNotification.less';
|
import './lockNotification.less';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import request from '../../../utils/request-middleware.js';
|
import request from '../../../utils/request-middleware.js';
|
||||||
import Dialog from '../../../../components/dialog.jsx';
|
import Dialog from '@components/dialog.jsx';
|
||||||
|
|
||||||
function LockNotification(props) {
|
function LockNotification(props) {
|
||||||
props = {
|
props = {
|
||||||
@@ -40,4 +40,4 @@ function LockNotification(props) {
|
|||||||
</Dialog>;
|
</Dialog>;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = LockNotification;
|
export default LockNotification;
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
require('./errorPage.less');
|
import './errorPage.less';
|
||||||
const React = require('react');
|
import React from 'react';
|
||||||
const UIPage = require('../basePages/uiPage/uiPage.jsx');
|
import UIPage from '../basePages/uiPage/uiPage.jsx';
|
||||||
import Markdown from '../../../../shared/markdown.js';
|
import { hbfm } from 'marked-hbfm';
|
||||||
const ErrorIndex = require('./errors/errorIndex.js');
|
import ErrorIndex from './errors/errorIndex.js';
|
||||||
|
|
||||||
const ErrorPage = ({ brew })=>{
|
const ErrorPage = ({ brew })=>{
|
||||||
// Retrieving the error text based on the brew's error code from ErrorIndex
|
// Retrieving the error text based on the brew's error code from ErrorIndex
|
||||||
@@ -16,10 +16,10 @@ const ErrorPage = ({ brew })=>{
|
|||||||
<h4>{brew?.text || 'No error text'}</h4>
|
<h4>{brew?.text || 'No error text'}</h4>
|
||||||
</div>
|
</div>
|
||||||
<hr />
|
<hr />
|
||||||
<div dangerouslySetInnerHTML={{ __html: Markdown.render(errorText) }} />
|
<div dangerouslySetInnerHTML={{ __html: hbfm.render(errorText) }} />
|
||||||
</div>
|
</div>
|
||||||
</UIPage>
|
</UIPage>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = ErrorPage;
|
export default ErrorPage;
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
.homebrew {
|
.homebrew {
|
||||||
.uiPage.sitePage {
|
.uiPage.sitePage:has(.errorTitle) {
|
||||||
.errorTitle {
|
.errorTitle {
|
||||||
//background-color: @orange;
|
|
||||||
color : #D02727;
|
color : #D02727;
|
||||||
text-align : center;
|
text-align : center;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const dedent = require('dedent-tabs').default;
|
import dedent from 'dedent';
|
||||||
|
|
||||||
const loginUrl = 'https://www.naturalcrit.com/login';
|
const loginUrl = 'https://www.naturalcrit.com/login';
|
||||||
|
|
||||||
@@ -268,4 +268,4 @@ const errorIndex = (props)=>{
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = errorIndex;
|
export default errorIndex;
|
||||||
@@ -1,233 +1,42 @@
|
|||||||
/* eslint-disable max-lines */
|
|
||||||
import './homePage.less';
|
import './homePage.less';
|
||||||
|
|
||||||
// Common imports
|
import React from 'react';
|
||||||
import React, { useState, useEffect, useRef } from 'react';
|
import request from '../../utils/request-middleware.js';
|
||||||
import request from '../../utils/request-middleware.js';
|
import _ from 'lodash';
|
||||||
import Markdown from 'markdown.js';
|
import EditorPage from '../basePages/editPage/editorPage.jsx';
|
||||||
import _ from 'lodash';
|
import { DEFAULT_BREW } from '../../../../server/brewDefaults.js';
|
||||||
|
|
||||||
import { DEFAULT_BREW } from '../../../../server/brewDefaults.js';
|
|
||||||
import { printCurrentBrew, fetchThemeBundle, splitTextStyleAndMetadata } from '../../../../shared/helpers.js';
|
|
||||||
|
|
||||||
import SplitPane from 'client/components/splitPane/splitPane.jsx';
|
|
||||||
import Editor from '../../editor/editor.jsx';
|
|
||||||
import BrewRenderer from '../../brewRenderer/brewRenderer.jsx';
|
|
||||||
|
|
||||||
import Nav from 'client/homebrew/navbar/nav.jsx';
|
|
||||||
import Navbar from 'client/homebrew/navbar/navbar.jsx';
|
|
||||||
import NewBrewItem from 'client/homebrew/navbar/newbrew.navitem.jsx';
|
|
||||||
import AccountNavItem from 'client/homebrew/navbar/account.navitem.jsx';
|
|
||||||
import ErrorNavItem from 'client/homebrew/navbar/error-navitem.jsx';
|
|
||||||
import HelpNavItem from 'client/homebrew/navbar/help.navitem.jsx';
|
|
||||||
import VaultNavItem from 'client/homebrew/navbar/vault.navitem.jsx';
|
|
||||||
import PrintNavItem from 'client/homebrew/navbar/print.navitem.jsx';
|
|
||||||
import { both as RecentNavItem } from 'client/homebrew/navbar/recent.navitem.jsx';
|
|
||||||
|
|
||||||
// Page specific imports
|
|
||||||
import { Meta } from 'vitreum/headtags';
|
|
||||||
|
|
||||||
const BREWKEY = 'homebrewery-new';
|
|
||||||
const STYLEKEY = 'homebrewery-new-style';
|
|
||||||
const SNIPKEY = 'homebrewery-new-snippets';
|
|
||||||
const METAKEY = 'homebrewery-new-meta';
|
|
||||||
|
|
||||||
const useLocalStorage = false;
|
|
||||||
const neverSaved = true;
|
|
||||||
|
|
||||||
const HomePage =(props)=>{
|
const HomePage =(props)=>{
|
||||||
props = {
|
props = {
|
||||||
brew : DEFAULT_BREW,
|
brew : DEFAULT_BREW,
|
||||||
ver : '0.0.0',
|
|
||||||
...props
|
...props
|
||||||
};
|
};
|
||||||
|
|
||||||
const [currentBrew , setCurrentBrew] = useState(props.brew);
|
const save = async (brew, saveToGoogle)=>{
|
||||||
const [error , setError] = useState(undefined);
|
const res = await request
|
||||||
const [HTMLErrors , setHTMLErrors] = useState(Markdown.validate(props.brew.text));
|
.post(`/api${saveToGoogle ? '?saveToGoogle=true' : ''}`)
|
||||||
const [currentEditorViewPageNum , setCurrentEditorViewPageNum] = useState(1);
|
.send(brew);
|
||||||
const [currentEditorCursorPageNum, setCurrentEditorCursorPageNum] = useState(1);
|
|
||||||
const [currentBrewRendererPageNum, setCurrentBrewRendererPageNum] = useState(1);
|
|
||||||
const [themeBundle , setThemeBundle] = useState({});
|
|
||||||
const [unsavedChanges , setUnsavedChanges] = useState(false);
|
|
||||||
const [isSaving , setIsSaving] = useState(false);
|
|
||||||
const [autoSaveEnabled , setAutoSaveEnable] = useState(false);
|
|
||||||
|
|
||||||
const editorRef = useRef(null);
|
return res.body;
|
||||||
const lastSavedBrew = useRef(_.cloneDeep(props.brew));
|
|
||||||
const unsavedChangesRef = useRef(unsavedChanges);
|
|
||||||
|
|
||||||
useEffect(()=>{
|
|
||||||
fetchThemeBundle(setError, setThemeBundle, currentBrew.renderer, currentBrew.theme);
|
|
||||||
|
|
||||||
const handleControlKeys = (e)=>{
|
|
||||||
if(!(e.ctrlKey || e.metaKey)) return;
|
|
||||||
if(e.keyCode === 83) trySaveRef.current(true);
|
|
||||||
if(e.keyCode === 80) printCurrentBrew();
|
|
||||||
if([83, 80].includes(e.keyCode)) {
|
|
||||||
e.stopPropagation();
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
document.addEventListener('keydown', handleControlKeys);
|
|
||||||
window.onbeforeunload = ()=>{
|
|
||||||
if(unsavedChangesRef.current)
|
|
||||||
return 'You have unsaved changes!';
|
|
||||||
};
|
|
||||||
return ()=>{
|
|
||||||
document.removeEventListener('keydown', handleControlKeys);
|
|
||||||
window.onbeforeunload = null;
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(()=>{
|
|
||||||
unsavedChangesRef.current = unsavedChanges;
|
|
||||||
}, [unsavedChanges]);
|
|
||||||
|
|
||||||
const save = ()=>{
|
|
||||||
request.post('/api')
|
|
||||||
.send(currentBrew)
|
|
||||||
.end((err, res)=>{
|
|
||||||
if(err) {
|
|
||||||
setError(err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const saved = res.body;
|
|
||||||
window.location = `/edit/${saved.editId}`;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(()=>{
|
const onSaveSuccess = (savedBrew)=>{
|
||||||
const hasChange = !_.isEqual(currentBrew, lastSavedBrew.current);
|
window.onbeforeunload = null;
|
||||||
setUnsavedChanges(hasChange);
|
window.location = `/edit/${savedBrew.editId}`;
|
||||||
|
|
||||||
if(autoSaveEnabled) trySave(false, hasChange);
|
|
||||||
}, [currentBrew]);
|
|
||||||
|
|
||||||
const handleSplitMove = ()=>{
|
|
||||||
editorRef.current.update();
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleBrewChange = (field)=>(value, subfield)=>{ //'text', 'style', 'snippets', 'metadata'
|
|
||||||
if(subfield == 'renderer' || subfield == 'theme')
|
|
||||||
fetchThemeBundle(setError, setThemeBundle, value.renderer, value.theme);
|
|
||||||
|
|
||||||
//If there are HTML errors, run the validator on every change to give quick feedback
|
|
||||||
if(HTMLErrors.length && (field == 'text' || field == 'snippets'))
|
|
||||||
setHTMLErrors(Markdown.validate(value));
|
|
||||||
|
|
||||||
if(field == 'metadata') setCurrentBrew((prev)=>({ ...prev, ...value }));
|
|
||||||
else setCurrentBrew((prev)=>({ ...prev, [field]: value }));
|
|
||||||
|
|
||||||
if(useLocalStorage) {
|
|
||||||
if(field == 'text') localStorage.setItem(BREWKEY, value);
|
|
||||||
if(field == 'style') localStorage.setItem(STYLEKEY, value);
|
|
||||||
if(field == 'snippets') localStorage.setItem(SNIPKEY, value);
|
|
||||||
if(field == 'metadata') localStorage.setItem(METAKEY, JSON.stringify({
|
|
||||||
renderer : value.renderer,
|
|
||||||
theme : value.theme,
|
|
||||||
lang : value.lang
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderSaveButton = ()=>{
|
|
||||||
// #1 - Currently saving, show SAVING
|
|
||||||
if(isSaving)
|
|
||||||
return <Nav.item className='save' icon='fas fa-spinner fa-spin'>saving...</Nav.item>;
|
|
||||||
|
|
||||||
// #2 - Unsaved changes exist, autosave is OFF and warning timer has expired, show AUTOSAVE WARNING
|
|
||||||
// if(unsavedChanges && warnUnsavedChanges) {
|
|
||||||
// resetWarnUnsavedTimer();
|
|
||||||
// const elapsedTime = Math.round((new Date() - lastSavedTime) / 1000 / 60);
|
|
||||||
// const text = elapsedTime === 0
|
|
||||||
// ? 'Autosave is OFF.'
|
|
||||||
// : `Autosave is OFF, and you haven't saved for ${elapsedTime} minutes.`;
|
|
||||||
|
|
||||||
// return <Nav.item className='save error' icon='fas fa-exclamation-circle'>
|
|
||||||
// Reminder...
|
|
||||||
// <div className='errorContainer'>{text}</div>
|
|
||||||
// </Nav.item>;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #3 - Unsaved changes exist, click to save, show SAVE NOW
|
|
||||||
if(unsavedChanges)
|
|
||||||
return <Nav.item className='save' onClick={save} color='blue' icon='fas fa-save'>save now</Nav.item>;
|
|
||||||
|
|
||||||
// #4 - No unsaved changes, autosave is ON, show AUTO-SAVED
|
|
||||||
if(autoSaveEnabled)
|
|
||||||
return <Nav.item className='save saved'>auto-saved</Nav.item>;
|
|
||||||
|
|
||||||
// #5 - No unsaved changes, and has never been saved, hide the button
|
|
||||||
if(neverSaved)
|
|
||||||
return <Nav.item className='save neverSaved'>save now</Nav.item>;
|
|
||||||
|
|
||||||
// DEFAULT - No unsaved changes, show SAVED
|
|
||||||
return <Nav.item className='save saved'>saved</Nav.item>;
|
|
||||||
};
|
|
||||||
|
|
||||||
const clearError = ()=>{
|
|
||||||
setError(null);
|
|
||||||
setIsSaving(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderNavbar = ()=>{
|
|
||||||
return <Navbar ver={props.ver}>
|
|
||||||
<Nav.section>
|
|
||||||
{error
|
|
||||||
? <ErrorNavItem error={error} clearError={clearError} />
|
|
||||||
: renderSaveButton()}
|
|
||||||
<NewBrewItem />
|
|
||||||
<PrintNavItem />
|
|
||||||
<HelpNavItem />
|
|
||||||
<VaultNavItem />
|
|
||||||
<RecentNavItem />
|
|
||||||
<AccountNavItem />
|
|
||||||
</Nav.section>
|
|
||||||
</Navbar>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='homePage sitePage'>
|
<EditorPage
|
||||||
<Meta name='google-site-verification' content='NwnAQSSJZzAT7N-p5MY6ydQ7Njm67dtbu73ZSyE5Fy4' />
|
useLocalStorage = {false}
|
||||||
{renderNavbar()}
|
sandbox = {true}
|
||||||
<div className='content'>
|
showFloatingButtons = {true}
|
||||||
<SplitPane onDragFinish={handleSplitMove}>
|
showEditorButtons = {false}
|
||||||
<Editor
|
pageName = {'homePage'}
|
||||||
ref={editorRef}
|
brew = {props.brew}
|
||||||
brew={currentBrew}
|
userThemes = {{}}
|
||||||
onBrewChange={handleBrewChange}
|
save = {save}
|
||||||
renderer={currentBrew.renderer}
|
onSaveSuccess = {onSaveSuccess}
|
||||||
showEditButtons={false}
|
></EditorPage>);
|
||||||
themeBundle={themeBundle}
|
|
||||||
onCursorPageChange={setCurrentEditorCursorPageNum}
|
|
||||||
onViewPageChange={setCurrentEditorViewPageNum}
|
|
||||||
currentEditorViewPageNum={currentEditorViewPageNum}
|
|
||||||
currentEditorCursorPageNum={currentEditorCursorPageNum}
|
|
||||||
currentBrewRendererPageNum={currentBrewRendererPageNum}
|
|
||||||
/>
|
|
||||||
<BrewRenderer
|
|
||||||
text={currentBrew.text}
|
|
||||||
style={currentBrew.style}
|
|
||||||
renderer={currentBrew.renderer}
|
|
||||||
onPageChange={setCurrentBrewRendererPageNum}
|
|
||||||
currentEditorViewPageNum={currentEditorViewPageNum}
|
|
||||||
currentEditorCursorPageNum={currentEditorCursorPageNum}
|
|
||||||
currentBrewRendererPageNum={currentBrewRendererPageNum}
|
|
||||||
themeBundle={themeBundle}
|
|
||||||
/>
|
|
||||||
</SplitPane>
|
|
||||||
</div>
|
|
||||||
<div className={`floatingSaveButton${unsavedChanges ? ' show' : ''}`} onClick={save}>
|
|
||||||
Save current <i className='fas fa-save' />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<a href='/new' className='floatingNewButton'>
|
|
||||||
Create your own <i className='fas fa-magic' />
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = HomePage;
|
export default HomePage;
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@import '@sharedStyles/core.less';
|
||||||
|
|
||||||
.homePage {
|
.homePage {
|
||||||
position : relative;
|
position : relative;
|
||||||
a.floatingNewButton {
|
a.floatingNewButton {
|
||||||
@@ -35,14 +37,14 @@
|
|||||||
|
|
||||||
.navItem.save {
|
.navItem.save {
|
||||||
background-color : @orange;
|
background-color : @orange;
|
||||||
transition:all 0.2s;
|
transition : all 0.2s;
|
||||||
&:hover { background-color : @green; }
|
&:hover { background-color : @green; }
|
||||||
|
|
||||||
&.neverSaved {
|
&.neverSaved {
|
||||||
translate:-100%;
|
cursor : auto;
|
||||||
opacity: 0;
|
background-color : #333333;
|
||||||
background-color :#333;
|
opacity : 0;
|
||||||
cursor:auto;
|
translate : -100%;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ After clicking the "Print" item in the navbar a new page will open and a print d
|
|||||||
If you want to save ink or have a monochrome printer, add the **PRINT → {{fas,fa-tint}} Ink Friendly** snippet to your brew!
|
If you want to save ink or have a monochrome printer, add the **PRINT → {{fas,fa-tint}} Ink Friendly** snippet to your brew!
|
||||||
}}
|
}}
|
||||||
|
|
||||||
 {position:absolute,bottom:20px,left:130px,width:220px}
|
 {position:absolute,bottom:20px,left:130px,width:220px}
|
||||||
|
|
||||||
{{artist,bottom:160px,left:100px
|
{{artist,bottom:160px,left:100px
|
||||||
##### Homebrew Mug
|
##### Homebrew Mug
|
||||||
@@ -77,16 +77,16 @@ If you wish to sell or in some way gain profit for what's created on this site,
|
|||||||
If you'd like to credit us in your brew, we'd be flattered! Just reference that you made it with The Homebrewery.
|
If you'd like to credit us in your brew, we'd be flattered! Just reference that you made it with The Homebrewery.
|
||||||
|
|
||||||
### More Homebrew Resources
|
### More Homebrew Resources
|
||||||
[{width:50px,float:right,padding-left:10px}](https://discord.gg/by3deKx)
|
[{width:50px,float:right,padding-left:10px}](https://discord.gg/by3deKx)
|
||||||
|
|
||||||
If you are looking for more 5e Homebrew resources check out [r/UnearthedArcana](https://www.reddit.com/r/UnearthedArcana/) and their list of useful resources [here](https://www.reddit.com/r/UnearthedArcana/wiki/resources). The [Discord Of Many Things](https://discord.gg/by3deKx) is another great resource to connect with fellow homebrewers for help and feedback.
|
If you are looking for more 5e Homebrew resources check out [r/UnearthedArcana](https://www.reddit.com/r/UnearthedArcana/) and their list of useful resources [here](https://www.reddit.com/r/UnearthedArcana/wiki/resources). The [Discord Of Many Things](https://discord.gg/by3deKx) is another great resource to connect with fellow homebrewers for help and feedback.
|
||||||
|
|
||||||
|
|
||||||
{{position:absolute;top:20px;right:20px;width:auto
|
{{position:absolute;top:20px;right:20px;width:auto
|
||||||
[{height:30px}](https://discord.gg/by3deKx)
|
[{height:30px}](https://discord.gg/by3deKx)
|
||||||
[{height:30px}](https://github.com/naturalcrit/homebrewery)
|
[{height:30px}](https://github.com/naturalcrit/homebrewery)
|
||||||
[{height:30px}](https://patreon.com/NaturalCrit)
|
[{height:30px}](https://patreon.com/NaturalCrit)
|
||||||
[{height:30px}](https://www.reddit.com/r/homebrewery/)
|
[{height:30px}](https://www.reddit.com/r/homebrewery/)
|
||||||
}}
|
}}
|
||||||
|
|
||||||
\page
|
\page
|
||||||
@@ -162,7 +162,7 @@ Images must be hosted online somewhere, like [Imgur](https://www.imgur.com). You
|
|||||||
|
|
||||||
Using *Curly Injection* you can assign an id, classes, or inline CSS properties to the Markdown image syntax.
|
Using *Curly Injection* you can assign an id, classes, or inline CSS properties to the Markdown image syntax.
|
||||||
|
|
||||||
 {width:100px,border:"2px solid",border-radius:10px}
|
 {width:100px,border:"2px solid",border-radius:10px}
|
||||||
|
|
||||||
\* *When using Imgur-hosted images, use the "direct link", which can be found when you click into your image in the Imgur interface.*
|
\* *When using Imgur-hosted images, use the "direct link", which can be found when you click into your image in the Imgur interface.*
|
||||||
|
|
||||||
|
|||||||
@@ -1,40 +1,10 @@
|
|||||||
/* eslint-disable max-lines */
|
|
||||||
import './newPage.less';
|
import './newPage.less';
|
||||||
|
|
||||||
// Common imports
|
import React from 'react';
|
||||||
import React, { useState, useEffect, useRef } from 'react';
|
import request from '../../utils/request-middleware.js';
|
||||||
import request from '../../utils/request-middleware.js';
|
import _ from 'lodash';
|
||||||
import Markdown from 'markdown.js';
|
import EditorPage from '../basePages/editPage/editorPage.jsx';
|
||||||
import _ from 'lodash';
|
import { DEFAULT_BREW } from '../../../../server/brewDefaults.js';
|
||||||
|
|
||||||
import { DEFAULT_BREW } from '../../../../server/brewDefaults.js';
|
|
||||||
import { printCurrentBrew, fetchThemeBundle, splitTextStyleAndMetadata } from '../../../../shared/helpers.js';
|
|
||||||
|
|
||||||
import SplitPane from 'client/components/splitPane/splitPane.jsx';
|
|
||||||
import Editor from '../../editor/editor.jsx';
|
|
||||||
import BrewRenderer from '../../brewRenderer/brewRenderer.jsx';
|
|
||||||
|
|
||||||
import Nav from 'client/homebrew/navbar/nav.jsx';
|
|
||||||
import Navbar from 'client/homebrew/navbar/navbar.jsx';
|
|
||||||
import NewBrewItem from 'client/homebrew/navbar/newbrew.navitem.jsx';
|
|
||||||
import AccountNavItem from 'client/homebrew/navbar/account.navitem.jsx';
|
|
||||||
import ErrorNavItem from 'client/homebrew/navbar/error-navitem.jsx';
|
|
||||||
import HelpNavItem from 'client/homebrew/navbar/help.navitem.jsx';
|
|
||||||
import VaultNavItem from 'client/homebrew/navbar/vault.navitem.jsx';
|
|
||||||
import PrintNavItem from 'client/homebrew/navbar/print.navitem.jsx';
|
|
||||||
import { both as RecentNavItem } from 'client/homebrew/navbar/recent.navitem.jsx';
|
|
||||||
|
|
||||||
// Page specific imports
|
|
||||||
import { Meta } from 'vitreum/headtags';
|
|
||||||
|
|
||||||
const BREWKEY = 'HB_newPage_content';
|
|
||||||
const STYLEKEY = 'HB_newPage_style';
|
|
||||||
const METAKEY = 'HB_newPage_metadata';
|
|
||||||
const SNIPKEY = 'HB_newPage_snippets';
|
|
||||||
const SAVEKEYPREFIX = 'HB_editor_defaultSave_';
|
|
||||||
|
|
||||||
const useLocalStorage = true;
|
|
||||||
const neverSaved = true;
|
|
||||||
|
|
||||||
const NewPage = (props)=>{
|
const NewPage = (props)=>{
|
||||||
props = {
|
props = {
|
||||||
@@ -42,238 +12,31 @@ const NewPage = (props)=>{
|
|||||||
...props
|
...props
|
||||||
};
|
};
|
||||||
|
|
||||||
const [currentBrew , setCurrentBrew ] = useState(props.brew);
|
const save = async (brew, saveToGoogle)=>{
|
||||||
const [isSaving , setIsSaving ] = useState(false);
|
|
||||||
const [saveGoogle , setSaveGoogle ] = useState(global.account?.googleId ? true : false);
|
|
||||||
const [error , setError ] = useState(null);
|
|
||||||
const [HTMLErrors , setHTMLErrors ] = useState(Markdown.validate(props.brew.text));
|
|
||||||
const [currentEditorViewPageNum , setCurrentEditorViewPageNum ] = useState(1);
|
|
||||||
const [currentEditorCursorPageNum, setCurrentEditorCursorPageNum] = useState(1);
|
|
||||||
const [currentBrewRendererPageNum, setCurrentBrewRendererPageNum] = useState(1);
|
|
||||||
const [themeBundle , setThemeBundle ] = useState({});
|
|
||||||
const [unsavedChanges , setUnsavedChanges ] = useState(false);
|
|
||||||
const [autoSaveEnabled , setAutoSaveEnabled ] = useState(false);
|
|
||||||
|
|
||||||
const editorRef = useRef(null);
|
|
||||||
const lastSavedBrew = useRef(_.cloneDeep(props.brew));
|
|
||||||
// const saveTimeout = useRef(null);
|
|
||||||
// const warnUnsavedTimeout = useRef(null);
|
|
||||||
const trySaveRef = useRef(trySave); // CTRL+S listener lives outside React and needs ref to use trySave with latest copy of brew
|
|
||||||
const unsavedChangesRef = useRef(unsavedChanges); // Similarly, onBeforeUnload lives outside React and needs ref to unsavedChanges
|
|
||||||
|
|
||||||
useEffect(()=>{
|
|
||||||
loadBrew();
|
|
||||||
fetchThemeBundle(setError, setThemeBundle, currentBrew.renderer, currentBrew.theme);
|
|
||||||
|
|
||||||
const handleControlKeys = (e)=>{
|
|
||||||
if(!(e.ctrlKey || e.metaKey)) return;
|
|
||||||
if(e.keyCode === 83) trySaveRef.current(true);
|
|
||||||
if(e.keyCode === 80) printCurrentBrew();
|
|
||||||
if([83, 80].includes(e.keyCode)) {
|
|
||||||
e.stopPropagation();
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
document.addEventListener('keydown', handleControlKeys);
|
|
||||||
|
|
||||||
return ()=>{
|
|
||||||
document.removeEventListener('keydown', handleControlKeys);
|
|
||||||
};
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const loadBrew = ()=>{
|
|
||||||
const brew = { ...currentBrew };
|
|
||||||
if(!brew.shareId && typeof window !== 'undefined') { //Load from localStorage if in client browser
|
|
||||||
const brewStorage = localStorage.getItem(BREWKEY);
|
|
||||||
const styleStorage = localStorage.getItem(STYLEKEY);
|
|
||||||
const metaStorage = JSON.parse(localStorage.getItem(METAKEY));
|
|
||||||
|
|
||||||
brew.text = brewStorage ?? brew.text;
|
|
||||||
brew.style = styleStorage ?? brew.style;
|
|
||||||
brew.renderer = metaStorage?.renderer ?? brew.renderer;
|
|
||||||
brew.theme = metaStorage?.theme ?? brew.theme;
|
|
||||||
brew.lang = metaStorage?.lang ?? brew.lang;
|
|
||||||
}
|
|
||||||
|
|
||||||
const SAVEKEY = `${SAVEKEYPREFIX}${global.account?.username}`;
|
|
||||||
const saveStorage = localStorage.getItem(SAVEKEY) || 'HOMEBREWERY';
|
|
||||||
|
|
||||||
setCurrentBrew(brew);
|
|
||||||
lastSavedBrew.current = brew;
|
|
||||||
setSaveGoogle(saveStorage == 'GOOGLE-DRIVE' && saveGoogle);
|
|
||||||
|
|
||||||
localStorage.setItem(BREWKEY, brew.text);
|
|
||||||
if(brew.style)
|
|
||||||
localStorage.setItem(STYLEKEY, brew.style);
|
|
||||||
localStorage.setItem(METAKEY, JSON.stringify({ renderer: brew.renderer, theme: brew.theme, lang: brew.lang }));
|
|
||||||
if(window.location.pathname !== '/new')
|
|
||||||
window.history.replaceState({}, window.location.title, '/new/');
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(()=>{
|
|
||||||
const hasChange = !_.isEqual(currentBrew, lastSavedBrew.current);
|
|
||||||
setUnsavedChanges(hasChange);
|
|
||||||
|
|
||||||
if(autoSaveEnabled) trySave(false, hasChange);
|
|
||||||
}, [currentBrew]);
|
|
||||||
|
|
||||||
useEffect(()=>{
|
|
||||||
trySaveRef.current = trySave;
|
|
||||||
unsavedChangesRef.current = unsavedChanges;
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleSplitMove = ()=>{
|
|
||||||
editorRef.current.update();
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleBrewChange = (field)=>(value, subfield)=>{ //'text', 'style', 'snippets', 'metadata'
|
|
||||||
if(subfield == 'renderer' || subfield == 'theme')
|
|
||||||
fetchThemeBundle(setError, setThemeBundle, value.renderer, value.theme);
|
|
||||||
|
|
||||||
//If there are HTML errors, run the validator on every change to give quick feedback
|
|
||||||
if(HTMLErrors.length && (field == 'text' || field == 'snippets'))
|
|
||||||
setHTMLErrors(Markdown.validate(value));
|
|
||||||
|
|
||||||
if(field == 'metadata') setCurrentBrew((prev)=>({ ...prev, ...value }));
|
|
||||||
else setCurrentBrew((prev)=>({ ...prev, [field]: value }));
|
|
||||||
|
|
||||||
if(useLocalStorage) {
|
|
||||||
if(field == 'text') localStorage.setItem(BREWKEY, value);
|
|
||||||
if(field == 'style') localStorage.setItem(STYLEKEY, value);
|
|
||||||
if(field == 'snippets') localStorage.setItem(SNIPKEY, value);
|
|
||||||
if(field == 'metadata') localStorage.setItem(METAKEY, JSON.stringify({
|
|
||||||
renderer : value.renderer,
|
|
||||||
theme : value.theme,
|
|
||||||
lang : value.lang
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const trySave = async ()=>{
|
|
||||||
setIsSaving(true);
|
|
||||||
|
|
||||||
const updatedBrew = { ...currentBrew };
|
|
||||||
splitTextStyleAndMetadata(updatedBrew);
|
|
||||||
|
|
||||||
const pageRegex = updatedBrew.renderer === 'legacy' ? /\\page/g : /^\\page$/gm;
|
|
||||||
updatedBrew.pageCount = (updatedBrew.text.match(pageRegex) || []).length + 1;
|
|
||||||
|
|
||||||
const res = await request
|
const res = await request
|
||||||
.post(`/api${saveGoogle ? '?saveToGoogle=true' : ''}`)
|
.post(`/api${saveToGoogle ? '?saveToGoogle=true' : ''}`)
|
||||||
.send(updatedBrew)
|
.send(brew);
|
||||||
.catch((err)=>{
|
|
||||||
setIsSaving(false);
|
|
||||||
setError(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
setIsSaving(false);
|
return res.body;
|
||||||
if(!res) return;
|
};
|
||||||
|
|
||||||
const savedBrew = res.body;
|
const onSaveSuccess = (savedBrew)=>{
|
||||||
|
window.onbeforeunload = null;
|
||||||
localStorage.removeItem(BREWKEY);
|
|
||||||
localStorage.removeItem(STYLEKEY);
|
|
||||||
localStorage.removeItem(METAKEY);
|
|
||||||
window.location = `/edit/${savedBrew.editId}`;
|
window.location = `/edit/${savedBrew.editId}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderSaveButton = ()=>{
|
|
||||||
// #1 - Currently saving, show SAVING
|
|
||||||
if(isSaving)
|
|
||||||
return <Nav.item className='save' icon='fas fa-spinner fa-spin'>saving...</Nav.item>;
|
|
||||||
|
|
||||||
// #2 - Unsaved changes exist, autosave is OFF and warning timer has expired, show AUTOSAVE WARNING
|
|
||||||
// if(unsavedChanges && warnUnsavedChanges) {
|
|
||||||
// resetWarnUnsavedTimer();
|
|
||||||
// const elapsedTime = Math.round((new Date() - lastSavedTime) / 1000 / 60);
|
|
||||||
// const text = elapsedTime === 0
|
|
||||||
// ? 'Autosave is OFF.'
|
|
||||||
// : `Autosave is OFF, and you haven't saved for ${elapsedTime} minutes.`;
|
|
||||||
|
|
||||||
// return <Nav.item className='save error' icon='fas fa-exclamation-circle'>
|
|
||||||
// Reminder...
|
|
||||||
// <div className='errorContainer'>{text}</div>
|
|
||||||
// </Nav.item>;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #3 - Unsaved changes exist, click to save, show SAVE NOW
|
|
||||||
if(unsavedChanges)
|
|
||||||
return <Nav.item className='save' onClick={trySave} color='blue' icon='fas fa-save'>save now</Nav.item>;
|
|
||||||
|
|
||||||
// #4 - No unsaved changes, autosave is ON, show AUTO-SAVED
|
|
||||||
if(autoSaveEnabled)
|
|
||||||
return <Nav.item className='save saved'>auto-saved</Nav.item>;
|
|
||||||
|
|
||||||
// #5 - No unsaved changes, and has never been saved, hide the button
|
|
||||||
if(neverSaved)
|
|
||||||
return <Nav.item className='save neverSaved'>save now</Nav.item>;
|
|
||||||
|
|
||||||
// DEFAULT - No unsaved changes, show SAVED
|
|
||||||
return <Nav.item className='save saved'>saved</Nav.item>;
|
|
||||||
};
|
|
||||||
|
|
||||||
const clearError = ()=>{
|
|
||||||
setError(null);
|
|
||||||
setIsSaving(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderNavbar = ()=>(
|
|
||||||
<Navbar>
|
|
||||||
<Nav.section>
|
|
||||||
<Nav.item className='brewTitle'>{currentBrew.title}</Nav.item>
|
|
||||||
</Nav.section>
|
|
||||||
|
|
||||||
<Nav.section>
|
|
||||||
{error
|
|
||||||
? <ErrorNavItem error={error} clearError={clearError} />
|
|
||||||
: renderSaveButton()}
|
|
||||||
<NewBrewItem />
|
|
||||||
<PrintNavItem />
|
|
||||||
<HelpNavItem />
|
|
||||||
<VaultNavItem />
|
|
||||||
<RecentNavItem />
|
|
||||||
<AccountNavItem />
|
|
||||||
</Nav.section>
|
|
||||||
</Navbar>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='newPage sitePage'>
|
<EditorPage
|
||||||
{renderNavbar()}
|
useLocalStorage = {true}
|
||||||
<div className='content'>
|
sandbox = {true}
|
||||||
<SplitPane onDragFinish={handleSplitMove}>
|
showFloatingButtons = {false}
|
||||||
<Editor
|
showEditorButtons = {true}
|
||||||
ref={editorRef}
|
pageName = {'newPage'}
|
||||||
brew={currentBrew}
|
brew = {props.brew}
|
||||||
onBrewChange={handleBrewChange}
|
userThemes = {props.userThemes}
|
||||||
renderer={currentBrew.renderer}
|
save = {save}
|
||||||
userThemes={props.userThemes}
|
onSaveSuccess = {onSaveSuccess}
|
||||||
themeBundle={themeBundle}
|
></EditorPage>);
|
||||||
onCursorPageChange={setCurrentEditorCursorPageNum}
|
|
||||||
onViewPageChange={setCurrentEditorViewPageNum}
|
|
||||||
currentEditorViewPageNum={currentEditorViewPageNum}
|
|
||||||
currentEditorCursorPageNum={currentEditorCursorPageNum}
|
|
||||||
currentBrewRendererPageNum={currentBrewRendererPageNum}
|
|
||||||
/>
|
|
||||||
<BrewRenderer
|
|
||||||
text={currentBrew.text}
|
|
||||||
style={currentBrew.style}
|
|
||||||
renderer={currentBrew.renderer}
|
|
||||||
theme={currentBrew.theme}
|
|
||||||
themeBundle={themeBundle}
|
|
||||||
errors={HTMLErrors}
|
|
||||||
lang={currentBrew.lang}
|
|
||||||
onPageChange={setCurrentBrewRendererPageNum}
|
|
||||||
currentEditorViewPageNum={currentEditorViewPageNum}
|
|
||||||
currentEditorCursorPageNum={currentEditorCursorPageNum}
|
|
||||||
currentBrewRendererPageNum={currentBrewRendererPageNum}
|
|
||||||
allowPrint={true}
|
|
||||||
/>
|
|
||||||
</SplitPane>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = NewPage;
|
export default NewPage;
|
||||||
Loaded 100 of 232 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user