Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e574598a9e
|
||
|
|
ebcd324980
|
||
|
|
0926dea8b0
|
||
|
|
a1d7e1b51b
|
||
|
|
18f26b7fd6
|
||
|
|
75548d39f3
|
||
|
|
1fe99698fb
|
||
|
|
162db8ca63
|
||
|
|
cafa5cddcd
|
||
|
|
f96dec267b
|
||
|
|
3b83125771
|
||
|
|
5e07ef6e8d
|
||
|
|
aeca3926a3
|
||
|
|
03455c5bf5 | ||
|
|
bbf838c5d6
|
||
|
|
3a77763641
|
||
|
|
adaa10a4dc
|
||
|
|
9183363ea1
|
||
|
|
448c67912f
|
||
|
|
06b7ad2c77
|
||
|
|
400411d736
|
||
|
|
84dd8e6bf4
|
||
|
|
bbfebc0095
|
||
|
|
23d9b83567
|
||
|
|
a55c403527
|
||
|
|
0bf80006df
|
||
|
|
66bb91cb3e
|
||
|
|
fb9f4b0345
|
||
|
|
6ff41ce8ec
|
||
|
|
fe278d465f
|
||
|
|
727a090bb7
|
||
|
|
d4724ac6de
|
||
|
|
7edca3fa8f
|
||
|
|
6473d7108b
|
||
|
|
0880870a9f
|
||
|
|
7b159a0355
|
||
|
|
1703b3806a
|
||
|
|
8f06133181
|
||
|
|
efac56ba76
|
||
|
|
022ae1daef
|
||
|
|
8c112f50e6
|
||
|
|
a181ed3ebd | ||
|
|
30a4bf4be0
|
||
|
|
86f9e963d2 | ||
|
|
23c94e01f6 | ||
|
|
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 | ||
|
|
73e32bea79 | ||
|
|
848962e351 | ||
|
|
becf95a644 | ||
|
|
78a34e3b58 | ||
|
|
a350fcc254 | ||
|
|
f7edc8a366 | ||
|
|
0c5266429d | ||
|
|
db2b45a095 | ||
|
|
a0e496bf1c | ||
|
|
07a21247e6 | ||
|
|
4c444346d7 | ||
|
|
55946c93e3 | ||
|
|
657c268a80 | ||
|
|
726d9abec2 | ||
|
|
9d507a5bc7 | ||
|
|
950f6a79c5 | ||
|
|
84d32a70f9 | ||
|
|
d234dd0e0b | ||
|
|
4aa9408358 | ||
|
|
d2ca8473f3 | ||
|
|
b53abb5f9f | ||
|
|
fb42675574 | ||
|
|
1d02fb9565 | ||
|
|
2af063ac88 | ||
|
|
8442fdfe0a | ||
|
|
239029e196 | ||
|
|
0fcf6dfe89 | ||
|
|
eb99af2735 | ||
|
|
8b347bafbc | ||
|
|
83406479a7 | ||
|
|
9d2ff401fd | ||
|
|
2dda9c9804 | ||
|
|
82aa5b76ea | ||
|
|
94080ba952 | ||
|
|
1f2a329553 | ||
|
|
4bce4a9489 | ||
|
|
4da270616d | ||
|
|
7abea94196 | ||
|
|
c996bee932 | ||
|
|
901f84bf34 | ||
|
|
0842e398c4 | ||
|
|
98f73dd57c | ||
|
|
ad9f4773b0 | ||
|
|
c0b3a1940f | ||
|
|
9edb0e2fc6 | ||
|
|
55d93a0e5f | ||
|
|
9a74a20884 | ||
|
|
a00a3440fc | ||
|
|
06e15a04e9 | ||
|
|
d4c1eba3f3 | ||
|
|
1328d1aaca | ||
|
|
3992d71910 | ||
|
|
96e1d6e100 | ||
|
|
3a671cf48f | ||
|
|
3b9eae2e4f | ||
|
|
b0ebeaffb9 | ||
|
|
f50c25b906 | ||
|
|
ad50be45c6 | ||
|
|
1e5cf3a4de | ||
|
|
2b327a9ac9 | ||
|
|
0e431eb498 | ||
|
|
eaeb0ec5b1 | ||
|
|
b45795fac2 | ||
|
|
52f2f532a7 | ||
|
|
456c149f7b | ||
|
|
3e6f006811 | ||
|
|
5c8a6bc4d3 | ||
|
|
47b47ff255 | ||
|
|
bba3199dba | ||
|
|
953ef8c534 | ||
|
|
02ae7176f7 | ||
|
|
c76b174fd6 | ||
|
|
4483537b93 | ||
|
|
ec159e4f14 | ||
|
|
436d21f33c | ||
|
|
4ee9dfa509 | ||
|
|
c18e8edd34 | ||
|
|
42e254c9c7 | ||
|
|
3785d5808f | ||
|
|
9f6ec87101 | ||
|
|
61b8e02bfa | ||
|
|
cb8adb6740 | ||
|
|
33edc9600a | ||
|
|
0d26ed2a0f | ||
|
|
1742f810c9 | ||
|
|
2e445e664b | ||
|
|
286b40ce80 | ||
|
|
3c7d7339f0 | ||
|
|
153fa3abb5 | ||
|
|
3b89bba93c | ||
|
|
4f4a0ef273 | ||
|
|
e7a33a1d39 | ||
|
|
7987bf1671 | ||
|
|
89eb7990aa | ||
|
|
22e09b0879 | ||
|
|
af477c56b1 | ||
|
|
4aacb36b3f | ||
|
|
dd63370d20 | ||
|
|
9d72796a67 | ||
|
|
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:
|
||||
build:
|
||||
docker:
|
||||
- image: cimg/node:20.18.0
|
||||
- image: cimg/node:26.4
|
||||
- image: mongo:4.4
|
||||
|
||||
working_directory: ~/homebrewery
|
||||
@@ -27,7 +27,7 @@ jobs:
|
||||
# fallback to using the latest cache if no exact match is found
|
||||
- v1-dependencies-
|
||||
|
||||
- run: sudo npm install -g npm@10.8.2
|
||||
- run: sudo npm install -g npm@11.17.0
|
||||
- node/install-packages:
|
||||
app-dir: ~/homebrewery
|
||||
cache-path: node_modules
|
||||
@@ -45,7 +45,7 @@ jobs:
|
||||
|
||||
test:
|
||||
docker:
|
||||
- image: cimg/node:20.17.0
|
||||
- image: cimg/node:26.4
|
||||
|
||||
working_directory: ~/homebrewery
|
||||
parallelism: 1
|
||||
@@ -82,6 +82,9 @@ jobs:
|
||||
- run:
|
||||
name: Test - HTML sanitization
|
||||
command: npm run test:safehtml
|
||||
- run:
|
||||
name: Test - Helpers
|
||||
command: npm run test:helpers
|
||||
- run:
|
||||
name: Test - Coverage
|
||||
command: npm run test:coverage
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
# Kopieren nach .env. Nur Entwicklungswerte – keine echten Secrets einchecken.
|
||||
APP_PORT=8000
|
||||
MONGODB_URI=mongodb://mongodb/homebrewery
|
||||
MONGO_TAG=8
|
||||
|
||||
# Storage-Backend (ADR 0002, docs/storage/): mongo (Standard) oder postgres.
|
||||
# Postgres: docker compose --profile postgres up --build homebrewery-pg
|
||||
HB_DB_DRIVER=mongo
|
||||
# HB_POSTGRES_URL=postgres://homebrewery:homebrewery-dev@postgres:5432/homebrewery
|
||||
# HB_POSTGRES_POOL_MAX=10
|
||||
|
||||
# Profil postgres
|
||||
POSTGRES_DB=homebrewery
|
||||
POSTGRES_USER=homebrewery
|
||||
POSTGRES_PASSWORD=homebrewery-dev
|
||||
POSTGRES_PORT=5432
|
||||
|
||||
# Profil keycloak (Discovery: http://keycloak.localhost:8080/realms/homebrewery/.well-known/openid-configuration)
|
||||
KEYCLOAK_TAG=26.4
|
||||
KEYCLOAK_PORT=8080
|
||||
KEYCLOAK_ADMIN=admin
|
||||
KEYCLOAK_ADMIN_PASSWORD=admin-dev
|
||||
|
||||
# Profil authentik (Discovery: http://authentik.localhost:9000/application/o/homebrewery/.well-known/openid-configuration)
|
||||
AUTHENTIK_TAG=2026.2
|
||||
AUTHENTIK_PORT=9000
|
||||
AUTHENTIK_SECRET_KEY=dev-only-insecure-secret-key-change-me
|
||||
AUTHENTIK_DB_PASSWORD=authentik-dev
|
||||
AUTHENTIK_BOOTSTRAP_PASSWORD=admin-dev
|
||||
|
||||
# --- Auth (ADR 0001, docs/auth/) ---------------------------------------------
|
||||
# Ohne diese Werte verhält sich die App wie Upstream (nur naturalcrit-Login).
|
||||
# Aktive Login-Methoden, kommagetrennt: oidc, naturalcrit.
|
||||
# leer + HB_OIDC_ISSUER gesetzt -> oidc,naturalcrit (Auswahlseite /auth/login)
|
||||
# leer ohne Issuer -> naturalcrit
|
||||
# oidc -> nur OIDC (nc_session und /local/login gesperrt)
|
||||
# naturalcrit -> nur Alt-Login (/auth/oidc/* gesperrt)
|
||||
HB_AUTH_PROVIDERS=oidc
|
||||
# Öffentliche URL der App, ohne Schrägstrich am Ende (Redirect-URI: <HB_PUBLIC_URL>/auth/oidc/callback)
|
||||
HB_PUBLIC_URL=http://localhost:8000
|
||||
# Mindestens 32 Byte, nur Umgebung. Erzeugen: openssl rand -base64 48
|
||||
HB_SESSION_SECRET=dev-only-session-secret-change-me-0123456789
|
||||
HB_SESSION_TTL=7d
|
||||
# Aus Compose heraus: Keycloak (docker compose --profile keycloak up -d)
|
||||
HB_OIDC_ISSUER=http://keycloak.localhost:8080/realms/homebrewery
|
||||
# ... oder authentik (docker compose --profile authentik up -d)
|
||||
# HB_OIDC_ISSUER=http://authentik.localhost:9000/application/o/homebrewery/
|
||||
HB_OIDC_CLIENT_ID=homebrewery
|
||||
HB_OIDC_CLIENT_SECRET=dev-only-client-secret
|
||||
# Optional
|
||||
# HB_OIDC_SCOPES=openid profile email
|
||||
# HB_OIDC_USERNAME_CLAIM=preferred_username
|
||||
# HB_OIDC_LINK_BY_EMAIL=false
|
||||
# HB_OIDC_END_SESSION=false
|
||||
# HB_OIDC_LABEL=Anmelden
|
||||
# PUT /api/user/rename für naturalcrit-Sitzungen: off (Standard, gesperrt) oder signed (Nachweis oldSession, docs/auth/)
|
||||
# HB_NATURALCRIT_RENAME=off
|
||||
|
||||
# --- Git-Backend (ADR 0003, docs/git/) -----------------------------------------
|
||||
# Brews in beliebigen Git-Repos speichern (HTTPS + Personal Access Token). Nur für OIDC-Konten.
|
||||
# Ohne Schlüssel ist das Feature aus. Erzeugen: openssl rand -base64 32 (Schlüssel nie einchecken, nicht verlieren:
|
||||
# ohne ihn sind gespeicherte Tokens unbrauchbar)
|
||||
# HB_GIT_TOKEN_KEY=
|
||||
# Alte Schlüssel (kommagetrennt) nur zum Entschlüsseln bei Rotation
|
||||
# HB_GIT_TOKEN_KEYS_OLD=
|
||||
# Empfohlen im Betrieb: nur diese Hosts (Wildcards wie *.example.org erlaubt)
|
||||
# HB_GIT_ALLOWED_HOSTS=git.example.org,github.com
|
||||
# Nur für Entwicklung: private Ziele (z. B. Gitea im Compose-Netz) und http:// erlauben
|
||||
# HB_GIT_ALLOW_PRIVATE=false
|
||||
# HB_GIT_ALLOW_HTTP=false
|
||||
# HB_GIT_TIMEOUT_MS=20000
|
||||
# HB_GIT_OPEN_TIMEOUT_MS=4000
|
||||
# HB_GIT_MAX_FILE_BYTES=5242880
|
||||
# HB_GIT_MAX_CONCURRENCY=2
|
||||
# HB_GIT_COMMITTER_NAME=Homebrewery
|
||||
# HB_GIT_COMMITTER_EMAIL=
|
||||
# Bild-Upload (ADR 0004): nur mit aktivem Git-Backend, Standard an
|
||||
# HB_ASSETS_ENABLED=true
|
||||
# HB_ASSET_MAX_BYTES=5242880
|
||||
# HB_ASSET_MAX_BYTES_PER_BREW=52428800
|
||||
# HB_ASSET_TYPES=png,jpeg,gif,webp
|
||||
@@ -0,0 +1,100 @@
|
||||
# Fork-CI für Pull Requests und main (Gitea #4, FLW-82).
|
||||
# Nutzt ausschließlich die Upstream-npm-Skripte; die Upstream-CI unter .github/ und
|
||||
# .circleci/ bleibt unverändert (Merges aus naturalcrit/homebrewery konfliktfrei).
|
||||
# Läuft auf jedem Gitea act_runner mit dem Label ubuntu-latest.
|
||||
name: CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: ci-${{ github.ref }}
|
||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
env:
|
||||
# package.json verlangt Node >=26.4.0 und npm >=10.8 <12; das Lockfile zieht das
|
||||
# npm-Paket "node" ^26.13.0. Lokal verifiziert mit Node 26.13.1 / npm 11.20.0.
|
||||
NODE_VERSION: 26.13.1
|
||||
|
||||
jobs:
|
||||
app:
|
||||
name: App (npm ci + Build, ESLint, Stylelint, Jest)
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
|
||||
- uses: actions/setup-node@v7
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
package-manager-cache: false
|
||||
|
||||
# npm-Cache nur mit Repo-Variable CI_CACHE=true: Ist der Cache-Server des
|
||||
# act_runner aus dem Job-Container nicht erreichbar, kostet jeder
|
||||
# Cache-Schritt mehrere Minuten Timeout.
|
||||
- uses: actions/cache@v6
|
||||
if: vars.CI_CACHE == 'true'
|
||||
with:
|
||||
path: ~/.npm
|
||||
key: npm-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
|
||||
restore-keys: npm-${{ runner.os }}-
|
||||
|
||||
# postinstall führt "npm run build" (vite build) aus, prüft also auch den Build.
|
||||
- name: Abhängigkeiten und Build (npm ci)
|
||||
run: npm ci --no-audit --no-fund
|
||||
|
||||
# Upstream hat derzeit nur Warnungen (keine Fehler); Warnungen brechen nicht ab.
|
||||
- name: ESLint (npm run lint:dry)
|
||||
run: npm run lint:dry
|
||||
|
||||
- name: Stylelint (npm run stylelint:dry)
|
||||
run: npm run stylelint:dry
|
||||
|
||||
# Kommt ohne MongoDB aus (Mongoose wird in den Specs gemockt).
|
||||
- name: Jest (npm test)
|
||||
run: npm test
|
||||
|
||||
# Storage-Contract-Suite und API-Smoke gegen beide Backends (ADR 0002 §5, Gitea #7).
|
||||
# Service-Container: act_runner startet sie im selben Docker-Netz, Hostname = Service-Name.
|
||||
storage:
|
||||
name: Storage (${{ matrix.backend }})
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
backend: [mongo, postgres]
|
||||
services:
|
||||
mongo:
|
||||
image: mongo:8
|
||||
postgres:
|
||||
image: postgres:18
|
||||
env:
|
||||
POSTGRES_PASSWORD: hb-ci-only
|
||||
options: >-
|
||||
--health-cmd "pg_isready -U postgres"
|
||||
--health-interval 5s
|
||||
--health-timeout 5s
|
||||
--health-retries 10
|
||||
env:
|
||||
HB_TEST_MONGODB_URI: ${{ matrix.backend == 'mongo' && 'mongodb://mongo:27017' || '' }}
|
||||
HB_TEST_POSTGRES_URL: ${{ matrix.backend == 'postgres' && 'postgres://postgres:hb-ci-only@postgres:5432/postgres' || '' }}
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
|
||||
- uses: actions/setup-node@v7
|
||||
with:
|
||||
node-version: ${{ env.NODE_VERSION }}
|
||||
package-manager-cache: false
|
||||
|
||||
- name: Abhängigkeiten und Build (npm ci)
|
||||
run: npm ci --no-audit --no-fund
|
||||
|
||||
- name: Contract-Suite und API-Smoke (${{ matrix.backend }})
|
||||
run: npx jest server/storage tests/fork --runInBand
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
# Docker Hub: Repo-Beschreibung (Overview + Short description) aus docs/dockerhub/README.md setzen (FLW-263).
|
||||
# Auslöser: Release-Tag vX.Y.Z (wie der Docker-Hub-Pfad in image.yml), Änderungen an der Datei auf main, manuell.
|
||||
# Secrets: DOCKER_HUB_USER, DOCKER_HUB_TOKEN (Access Token mit Read, Write, Delete).
|
||||
# Fehlen sie, wird mit Warnung übersprungen. Das Token wird nie ausgegeben.
|
||||
name: Docker Hub Description
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- docs/dockerhub/README.md
|
||||
- .gitea/workflows/dockerhub-description.yml
|
||||
tags: ["v*"]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: dockerhub-description
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
description:
|
||||
name: Beschreibung nach Docker Hub schreiben
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
steps:
|
||||
- name: Prüfen
|
||||
id: check
|
||||
env:
|
||||
REF: ${{ github.ref }}
|
||||
REF_NAME: ${{ github.ref_name }}
|
||||
HUB_USER: ${{ secrets.DOCKER_HUB_USER }}
|
||||
HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
|
||||
run: |
|
||||
run=true
|
||||
if [[ "$REF" == refs/tags/* ]] && ! [[ "$REF_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||
echo "Kein Release-Tag (${REF_NAME}), übersprungen."; run=false
|
||||
elif [ -z "$HUB_USER" ] || [ -z "$HUB_TOKEN" ]; then
|
||||
echo "::warning::DOCKER_HUB_USER/DOCKER_HUB_TOKEN fehlen, Docker-Hub-Beschreibung wird übersprungen."; run=false
|
||||
fi
|
||||
echo "run=${run}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- uses: actions/checkout@v7
|
||||
if: steps.check.outputs.run == 'true'
|
||||
|
||||
- name: Platzhalter ersetzen (nur in der ausgecheckten Kopie)
|
||||
if: steps.check.outputs.run == 'true'
|
||||
env:
|
||||
HUB_USER: ${{ secrets.DOCKER_HUB_USER }}
|
||||
run: sed -i "s#<DOCKER_HUB_USER>#${HUB_USER}#g" docs/dockerhub/README.md
|
||||
|
||||
- name: Größe prüfen (Docker-Hub-Limit 25.000 Bytes)
|
||||
if: steps.check.outputs.run == 'true'
|
||||
run: |
|
||||
size=$(wc -c < docs/dockerhub/README.md)
|
||||
echo "README: ${size} Bytes"
|
||||
[ "$size" -lt 25000 ] || { echo "::error::docs/dockerhub/README.md ist zu groß für Docker Hub."; exit 1; }
|
||||
|
||||
- uses: peter-evans/dockerhub-description@v5
|
||||
if: steps.check.outputs.run == 'true'
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_HUB_USER }}
|
||||
password: ${{ secrets.DOCKER_HUB_TOKEN }}
|
||||
repository: ${{ secrets.DOCKER_HUB_USER }}/homebrewery-oidc
|
||||
readme-filepath: docs/dockerhub/README.md
|
||||
short-description: "Homebrewery fork: OIDC login, PostgreSQL 18, Git backend, image upload."
|
||||
@@ -0,0 +1,94 @@
|
||||
# Bereits in Gitea gebautes Release-Image nach Docker Hub übertragen, OHNE neu zu bauen (FLW-230).
|
||||
# Manuell starten mit Input "version" (Format vX.Y.Z, keine Vorabversionen).
|
||||
# Kopiert git.morlana.online/f.weber/homebrewery-oidc:<version> per `crane copy`
|
||||
# (gleicher Digest) nach <DOCKER_HUB_USER>/homebrewery-oidc:<version>. :latest wird nur gesetzt,
|
||||
# wenn <version> die höchste Release-Version mit Gitea-Image ist; ältere Versionen setzen latest nie zurück.
|
||||
# Secrets: DOCKER_HUB_USER, DOCKER_HUB_TOKEN, REGISTRY_TOKEN (wie image.yml, nur Lesen nötig).
|
||||
name: Docker Hub Sync
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: "Release-Version, z. B. v1.0.0"
|
||||
required: true
|
||||
type: string
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
packages: read
|
||||
|
||||
env:
|
||||
REGISTRY: git.morlana.online
|
||||
IMAGE: git.morlana.online/f.weber/homebrewery-oidc
|
||||
|
||||
jobs:
|
||||
sync:
|
||||
name: Nach Docker Hub kopieren
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- name: Version prüfen
|
||||
env:
|
||||
VERSION: ${{ inputs.version }}
|
||||
HUB_USER: ${{ secrets.DOCKER_HUB_USER }}
|
||||
HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
|
||||
run: |
|
||||
if ! [[ "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||
echo "::error::Version muss dem Format vX.Y.Z entsprechen."; exit 1
|
||||
fi
|
||||
if [ -z "$HUB_USER" ] || [ -z "$HUB_TOKEN" ]; then
|
||||
echo "::error::Secrets DOCKER_HUB_USER/DOCKER_HUB_TOKEN fehlen."; exit 1
|
||||
fi
|
||||
|
||||
- uses: docker/setup-buildx-action@v4
|
||||
|
||||
- uses: docker/login-action@v4
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ secrets.REGISTRY_TOKEN != '' && (vars.REGISTRY_USER || github.repository_owner) || github.actor }}
|
||||
password: ${{ secrets.REGISTRY_TOKEN || secrets.GITEA_TOKEN }}
|
||||
|
||||
- uses: docker/login-action@v4
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_HUB_USER }}
|
||||
password: ${{ secrets.DOCKER_HUB_TOKEN }}
|
||||
|
||||
- name: latest bestimmen
|
||||
id: v
|
||||
env:
|
||||
VERSION: ${{ inputs.version }}
|
||||
REPO_URL: ${{ github.server_url }}/${{ github.repository }}
|
||||
run: |
|
||||
# Höchste Release-Version, für die in Gitea ein Image existiert (Upstream-Tags ohne Image zählen nicht).
|
||||
highest=""
|
||||
for t in $(git ls-remote --tags --refs "$REPO_URL" 'v*' | sed 's#.*refs/tags/##' \
|
||||
| grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -Vr); do
|
||||
if docker buildx imagetools inspect "${IMAGE}:${t}" >/dev/null 2>&1; then highest="$t"; break; fi
|
||||
done
|
||||
highest="${highest:-$VERSION}"
|
||||
latest=false
|
||||
if [ "$(printf '%s\n%s\n' "$VERSION" "$highest" | sort -V | tail -n1)" = "$VERSION" ]; then
|
||||
latest=true
|
||||
fi
|
||||
echo "latest=${latest}" >> "$GITHUB_OUTPUT"
|
||||
echo "Version ${VERSION}, höchste Release-Version mit Image ${highest}, latest setzen: ${latest}"
|
||||
|
||||
- name: crane installieren
|
||||
run: |
|
||||
curl -fsSL https://github.com/google/go-containerregistry/releases/download/v0.20.3/go-containerregistry_Linux_x86_64.tar.gz \
|
||||
| tar -xz -C /usr/local/bin crane 2>/dev/null || { mkdir -p "$HOME/bin" && curl -fsSL https://github.com/google/go-containerregistry/releases/download/v0.20.3/go-containerregistry_Linux_x86_64.tar.gz | tar -xz -C "$HOME/bin" crane && echo "$HOME/bin" >> "$GITHUB_PATH"; }
|
||||
|
||||
- name: Kopieren
|
||||
env:
|
||||
VERSION: ${{ inputs.version }}
|
||||
LATEST: ${{ steps.v.outputs.latest }}
|
||||
HUB_USER: ${{ secrets.DOCKER_HUB_USER }}
|
||||
run: |
|
||||
dest="${HUB_USER}/homebrewery-oidc"
|
||||
# crane copy überträgt Manifest unverändert -> identischer Digest.
|
||||
crane copy "${IMAGE}:${VERSION}" "${dest}:${VERSION}"
|
||||
if [ "$LATEST" = "true" ]; then crane copy "${IMAGE}:${VERSION}" "${dest}:latest"; fi
|
||||
echo "Quelle:"; docker buildx imagetools inspect "${IMAGE}:${VERSION}" | grep -E '^(Name|Digest):'
|
||||
echo "Ziel:"; docker buildx imagetools inspect "${dest}:${VERSION}" | grep -E '^(Name|Digest):'
|
||||
if [ "$LATEST" = "true" ]; then docker buildx imagetools inspect "${dest}:latest" | grep -E '^(Name|Digest):'; fi
|
||||
@@ -0,0 +1,120 @@
|
||||
# Container-Image bauen und in die Gitea-Container-Registry pushen (Gitea #4, FLW-82).
|
||||
# Baut docker/Dockerfile (wie Compose, mit docker/Dockerfile.dockerignore) nach
|
||||
# git.morlana.online/f.weber/homebrewery-oidc
|
||||
# Tags:
|
||||
# push auf main -> :main, :sha-<7 Zeichen>
|
||||
# Tag vX.Y.Z -> :vX.Y.Z, :latest, :sha-<7 Zeichen> (Vorabversionen wie v1.0.0-rc.1 ohne :latest)
|
||||
# Zusätzlich Docker Hub (FLW-230): NUR bei Release-Tags ^vX.Y.Z$ (keine Vorabversionen, nicht main/sha-*)
|
||||
# -> <DOCKER_HUB_USER>/homebrewery-oidc:vX.Y.Z und :latest, im selben Build (gleicher Digest wie Gitea).
|
||||
# Fehlen die Repo-Secrets DOCKER_HUB_USER/DOCKER_HUB_TOKEN, wird Docker Hub übersprungen.
|
||||
# Nachholen bereits gebauter Versionen: dockerhub-sync.yml.
|
||||
# Login: Repo-Secret REGISTRY_TOKEN (PAT mit write:package). Fehlt es, wird der
|
||||
# automatische GITEA_TOKEN versucht. Details in FORK.md, Abschnitt "CI and container image".
|
||||
name: Image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
tags: ["v*"]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
concurrency:
|
||||
group: image-${{ github.ref }}
|
||||
cancel-in-progress: false
|
||||
|
||||
env:
|
||||
REGISTRY: git.morlana.online
|
||||
IMAGE: git.morlana.online/f.weber/homebrewery-oidc
|
||||
|
||||
jobs:
|
||||
image:
|
||||
name: Image bauen und pushen
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 45
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
|
||||
- name: Tags und Labels bestimmen
|
||||
id: meta
|
||||
env:
|
||||
REF: ${{ github.ref }}
|
||||
REF_NAME: ${{ github.ref_name }}
|
||||
SHA: ${{ github.sha }}
|
||||
SOURCE: ${{ github.server_url }}/${{ github.repository }}
|
||||
HUB_USER: ${{ secrets.DOCKER_HUB_USER }}
|
||||
HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
|
||||
run: |
|
||||
hub=false
|
||||
hub_names=""
|
||||
names="sha-${SHA:0:7}"
|
||||
version="sha-${SHA:0:7}"
|
||||
case "$REF" in
|
||||
refs/heads/main)
|
||||
names="${names} main"
|
||||
version="main"
|
||||
;;
|
||||
refs/tags/v*)
|
||||
names="${names} ${REF_NAME}"
|
||||
version="${REF_NAME}"
|
||||
if [[ "$REF_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||
names="${names} latest"
|
||||
hub_names="${REF_NAME} latest"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
tags=""
|
||||
for n in $names; do tags="${tags:+${tags},}${IMAGE}:${n}"; done
|
||||
if [ -n "$hub_names" ]; then
|
||||
if [ -n "$HUB_USER" ] && [ -n "$HUB_TOKEN" ]; then
|
||||
hub=true
|
||||
for n in $hub_names; do tags="${tags},${HUB_USER}/homebrewery-oidc:${n}"; done
|
||||
else
|
||||
echo "::warning::DOCKER_HUB_USER/DOCKER_HUB_TOKEN fehlen, Docker Hub wird übersprungen."
|
||||
fi
|
||||
fi
|
||||
{
|
||||
echo "tags=${tags}"
|
||||
echo "hub=${hub}"
|
||||
echo "labels<<EOF"
|
||||
echo "org.opencontainers.image.title=homebrewery-oidc"
|
||||
echo "org.opencontainers.image.description=Homebrewery-Fork mit OIDC-Login"
|
||||
echo "org.opencontainers.image.source=${SOURCE}"
|
||||
echo "org.opencontainers.image.revision=${SHA}"
|
||||
echo "org.opencontainers.image.version=${version}"
|
||||
echo "org.opencontainers.image.licenses=MIT"
|
||||
echo "EOF"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
echo "Tags: ${names} (Docker Hub: ${hub})"
|
||||
|
||||
- uses: docker/setup-buildx-action@v4
|
||||
|
||||
- uses: docker/login-action@v4
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ secrets.REGISTRY_TOKEN != '' && (vars.REGISTRY_USER || github.repository_owner) || github.actor }}
|
||||
password: ${{ secrets.REGISTRY_TOKEN || secrets.GITEA_TOKEN }}
|
||||
|
||||
- name: Docker Hub Login (nur Release-Tags)
|
||||
if: steps.meta.outputs.hub == 'true'
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_HUB_USER }}
|
||||
password: ${{ secrets.DOCKER_HUB_TOKEN }}
|
||||
|
||||
- name: Image bauen und pushen
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .
|
||||
file: docker/Dockerfile
|
||||
# Repo-Variable IMAGE_PLATFORMS; Ziel ist linux/amd64.
|
||||
platforms: ${{ vars.IMAGE_PLATFORMS || 'linux/amd64' }}
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
provenance: false
|
||||
cache-from: type=registry,ref=${{ env.IMAGE }}:buildcache
|
||||
cache-to: type=registry,ref=${{ env.IMAGE }}:buildcache,mode=max,image-manifest=true,oci-mediatypes=true,ignore-error=true
|
||||
@@ -6,6 +6,9 @@ updates:
|
||||
interval: daily
|
||||
open-pull-requests-limit: 99
|
||||
groups:
|
||||
eslint-bundle:
|
||||
patterns: ["*eslint*"]
|
||||
update-types: ["patch", "minor", "major"]
|
||||
dev-dependencies:
|
||||
dependency-type: "development"
|
||||
patterns: ["*"]
|
||||
@@ -66,10 +69,6 @@ updates:
|
||||
- dependency-name: "@babel/preset-react"
|
||||
versions:
|
||||
- 7.13.13
|
||||
- dependency-name: codemirror
|
||||
versions:
|
||||
- 5.59.3
|
||||
- 5.60.0
|
||||
- dependency-name: classnames
|
||||
versions:
|
||||
- 2.3.0
|
||||
|
||||
+3
-1
@@ -1,5 +1,5 @@
|
||||
node_modules
|
||||
storage
|
||||
/storage
|
||||
.idea
|
||||
*.swp
|
||||
|
||||
@@ -7,6 +7,7 @@ storage
|
||||
build/*
|
||||
config/local.*
|
||||
config/docker.*
|
||||
config/dev.*
|
||||
|
||||
todo.md
|
||||
startDB.bat
|
||||
@@ -14,3 +15,4 @@ startMViewer.bat
|
||||
.vscode
|
||||
|
||||
coverage
|
||||
.env
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
FROM node:22-alpine
|
||||
FROM node:26.4.0-alpine
|
||||
RUN apk --no-cache add git
|
||||
|
||||
ENV NODE_ENV=docker
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
# Homebrewery OIDC fork
|
||||
|
||||
This fork extends [naturalcrit/homebrewery](https://github.com/naturalcrit/homebrewery)
|
||||
for self-hosting while preserving its complete upstream history and MIT license.
|
||||
Keep fork changes small and isolated in modules or configuration so upstream
|
||||
updates remain practical to merge.
|
||||
|
||||
## Remotes and branches
|
||||
|
||||
- `origin`: `https://git.morlana.online/f.weber/homebrewery-oidc.git`
|
||||
- `upstream`: `https://github.com/naturalcrit/homebrewery.git`
|
||||
- `main`: reviewed integration branch for this fork.
|
||||
- `upstream`: pristine upstream `master`; never add fork commits here.
|
||||
|
||||
The initial import (2026-11-24) is upstream commit
|
||||
`6d219487de77f42868e38beeee0e4e7e9fb38679` (10,360 reachable commits, after tag `v3.21.0`).
|
||||
Both `main` and `upstream` initially point to that exact commit. The one-time
|
||||
import into the empty repository is the only direct-to-`main` exception.
|
||||
|
||||
## Reproducible upstream sync
|
||||
|
||||
Start from a clean working tree. Configure the upstream remote once after cloning:
|
||||
|
||||
```sh
|
||||
git clone https://git.morlana.online/f.weber/homebrewery-oidc.git
|
||||
cd homebrewery-oidc
|
||||
git remote add upstream https://github.com/naturalcrit/homebrewery.git
|
||||
```
|
||||
|
||||
For each update (choose a unique branch name):
|
||||
|
||||
```sh
|
||||
git fetch origin
|
||||
git switch main
|
||||
git merge --ff-only origin/main
|
||||
git switch -c sync/upstream-YYYY-MM-DD
|
||||
git fetch upstream
|
||||
UPSTREAM_SHA=$(git rev-parse upstream/master)
|
||||
git merge "$UPSTREAM_SHA"
|
||||
# Resolve conflicts, preserving the fork's isolated features; commit if needed.
|
||||
npm ci # lockfile-exact; needs Node 26 (on the VM use the container below)
|
||||
npm run build
|
||||
npm test
|
||||
npm run lint:dry
|
||||
git push -u origin sync/upstream-YYYY-MM-DD
|
||||
```
|
||||
|
||||
Open a PR against `main`, name the merged upstream commit (`$UPSTREAM_SHA`) and
|
||||
the imported range `origin/upstream..$UPSTREAM_SHA`, include validation results, and request Archimedes' review (Claudia reviews Archimedes' own PRs).
|
||||
Do not merge your own PR. Do not rebase or squash imported upstream history.
|
||||
After the reviewed sync merges, advance the pristine tracking branch to exactly
|
||||
the upstream commit that was merged into `main` (never to a newer, unreviewed
|
||||
`upstream/master`):
|
||||
|
||||
```sh
|
||||
git fetch origin
|
||||
UPSTREAM_SHA=<upstream commit named in the sync PR>
|
||||
git merge-base --is-ancestor "$UPSTREAM_SHA" origin/main &&
|
||||
git merge-base --is-ancestor origin/upstream "$UPSTREAM_SHA" &&
|
||||
git push origin "$UPSTREAM_SHA:refs/heads/upstream"
|
||||
```
|
||||
|
||||
The first check ensures the commit really is merged into `main`; the second
|
||||
prevents `upstream` from moving backwards or onto rewritten history. The push is
|
||||
not a force push. Afterwards `git log origin/upstream..origin/main` shows exactly
|
||||
the fork delta. If upstream rewrites history,
|
||||
stop for review instead of force-pushing. Never merge `main` into `upstream`.
|
||||
Use a feature branch from current `main` and a reviewed PR for fork changes.
|
||||
Keep credentials in the environment; never put tokens in remote URLs or files.
|
||||
|
||||
## CI and container image
|
||||
|
||||
Fork-owned Gitea Actions workflows live in `.gitea/workflows/`. The upstream CI in
|
||||
`.github/` and `.circleci/` stays untouched (it does not run on Gitea) so upstream
|
||||
merges remain conflict-free.
|
||||
|
||||
| Workflow | Trigger | What it does |
|
||||
| --- | --- | --- |
|
||||
| `ci.yml` | pull requests, push to `main` | `npm ci` (includes the Vite build via `postinstall`), `npm run lint:dry`, `npm run stylelint:dry`, `npm test`. Upstream currently has ESLint warnings but no errors; warnings do not fail the job. The tests need no MongoDB. |
|
||||
| `image.yml` | push to `main`, tags `v*`, manual | builds `docker/Dockerfile` (same as Compose) and pushes `git.morlana.online/f.weber/homebrewery-oidc`; release tags `vX.Y.Z` additionally go to Docker Hub (`<DOCKER_HUB_USER>/homebrewery-oidc`) |
|
||||
| `dockerhub-sync.yml` | manual (input `version`) | copies an already built `vX.Y.Z` image from Gitea to Docker Hub without rebuilding (same digest); sets `latest` only if the version is the highest release |
|
||||
| `dockerhub-description.yml` | release tag `vX.Y.Z`, push to `main` touching `docs/dockerhub/README.md`, manual | sets the Docker Hub overview from `docs/dockerhub/README.md` (English, < 25,000 bytes, absolute links only) plus a short description (≤ 100 characters), using `peter-evans/dockerhub-description`; skipped with a warning if `DOCKER_HUB_USER`/`DOCKER_HUB_TOKEN` are missing (the token needs Read, Write and Delete); `<DOCKER_HUB_USER>` in the file is replaced by the secret at publish time. A maintenance tag on an older commit overwrites the description with that older text; the first run needs the Hub repository to exist (created by `image.yml`) |
|
||||
|
||||
The authoritative image definition is `docker/Dockerfile` with
|
||||
`docker/Dockerfile.dockerignore` (BuildKit picks it up automatically for `context: .`).
|
||||
Compose (`docker-compose.override.yml`) builds the same file, so the published registry
|
||||
image matches the one built locally. The upstream `Dockerfile` stays unchanged and is not
|
||||
used by the fork. No configuration or secret is baked into the image: configure the
|
||||
container at runtime through environment variables (for example `MONGODB_URI`;
|
||||
`NODE_ENV=docker` is preset) or by mounting `config/docker.json`; `server/config.js`
|
||||
reads argv, then env, then that file, then `config/default.json`. The container exits if
|
||||
MongoDB is unreachable.
|
||||
|
||||
Image tags:
|
||||
|
||||
| Event | Tags |
|
||||
| --- | --- |
|
||||
| push to `main` | `main`, `sha-<7 chars>` |
|
||||
| tag `vX.Y.Z` | `vX.Y.Z`, `latest`, `sha-<7 chars>` (pre-release tags such as `v1.0.0-rc.1` get no `latest`) |
|
||||
|
||||
Docker Hub receives only release tags `vX.Y.Z` (as `vX.Y.Z` and `latest`, same build and
|
||||
digest as in Gitea). `main`, `sha-*` and pre-releases are never pushed there. If the secrets
|
||||
`DOCKER_HUB_USER` and `DOCKER_HUB_TOKEN` (access token with Read & Write) are missing, the
|
||||
Docker Hub part is skipped with a warning and the Gitea push is unaffected. To backfill a
|
||||
version, run `dockerhub-sync.yml` with e.g. `v1.0.0`.
|
||||
|
||||
`buildcache` is the BuildKit layer cache, not a runnable image.
|
||||
|
||||
Running the published image (Compose template with PostgreSQL 18, OIDC, Git backend and image upload, German): [docs/deploy/README.md](docs/deploy/README.md).
|
||||
|
||||
Runner and repository settings (repository → Settings → Actions):
|
||||
|
||||
- **Runner:** jobs use `runs-on: ubuntu-latest` (public runner, as in the DnD Character Manager).
|
||||
- **Secret `REGISTRY_TOKEN`:** access token of an account with write access to the
|
||||
`f.weber` packages, scope `write:package`. Without it the workflow falls back to the
|
||||
automatic `GITEA_TOKEN`, which may not be allowed to push packages.
|
||||
- **Variable `REGISTRY_USER`** (optional): owner of `REGISTRY_TOKEN`; defaults to the repository owner.
|
||||
- **Variable `CI_CACHE`** (optional): `true` enables the npm cache. Leave it unset until the
|
||||
act_runner cache server is reachable from job containers; otherwise every cache step
|
||||
waits for a connection timeout.
|
||||
- **Variable `IMAGE_PLATFORMS`** (optional): defaults to `linux/amd64`.
|
||||
|
||||
## Fork roadmap
|
||||
|
||||
These are planned features, not functionality delivered by the initial import:
|
||||
|
||||
| Milestone | Scope |
|
||||
| --- | --- |
|
||||
| [M0](https://git.morlana.online/f.weber/homebrewery-oidc/milestone/4) | Upstream import, CI, development setup |
|
||||
| [M1](https://git.morlana.online/f.weber/homebrewery-oidc/milestone/5) | OIDC login |
|
||||
| [M2](https://git.morlana.online/f.weber/homebrewery-oidc/milestone/6) | PostgreSQL backend (PostgreSQL 18+) |
|
||||
| [M3](https://git.morlana.online/f.weber/homebrewery-oidc/milestone/7) | Git backend including sharing |
|
||||
| [M4](https://git.morlana.online/f.weber/homebrewery-oidc/milestone/8) | Image uploads to the Git repository |
|
||||
|
||||
Track implementation and review status on the
|
||||
[roadmap board](https://git.morlana.online/f.weber/homebrewery-oidc/projects/2).
|
||||
|
||||
## Local startup
|
||||
|
||||
Consult `package.json` for the actual engine requirements: this imported revision
|
||||
requires Node >=26.4.0 and npm >=10.8 <12. The older Node guidance in the upstream
|
||||
README (v16+) does not match this revision. MongoDB must be >= 4.4, the minimum
|
||||
supported by the bundled MongoDB driver (7.7).
|
||||
|
||||
```sh
|
||||
export NODE_ENV=local
|
||||
export MONGODB_URI=mongodb://127.0.0.1:27017/homebrewery
|
||||
npm install # also runs the production asset build via postinstall
|
||||
npm start # http://localhost:8000
|
||||
```
|
||||
|
||||
### Development VM
|
||||
|
||||
The VM runs Node 24, and its CPU lacks AVX, so MongoDB >= 5.0 exits immediately
|
||||
(code 132). Do not install Node system-wide; use disposable containers instead:
|
||||
|
||||
```sh
|
||||
docker network create hb-dev
|
||||
docker run -d --name hb-mongo --network hb-dev --memory 400m \
|
||||
mongo:4.4 --wiredTigerCacheSizeGB 0.25
|
||||
docker run --rm --name hb-app --network hb-dev --memory 1200m \
|
||||
--user "$(id -u):$(id -g)" -e HOME=/tmp -e NODE_ENV=local \
|
||||
-e MONGODB_URI=mongodb://hb-mongo:27017/homebrewery \
|
||||
-p 127.0.0.1:8000:8000 -v "$PWD":/app -w /app \
|
||||
node:26 sh -c 'npm install && npm start'
|
||||
# when finished
|
||||
docker rm -f hb-app hb-mongo && docker network rm hb-dev
|
||||
```
|
||||
|
||||
MongoDB 4.4 is end-of-life: use it only with disposable test data. Verified on
|
||||
2026-11-24 with `node:26` (Node 26.13.1, npm 11.20.0) and `mongo:4.4`.
|
||||
@@ -90,6 +90,35 @@ If you still have problems, post in [Our Subreddit](https://www.reddit.com/r/hom
|
||||
|
||||
Please see the docs here: [README.DOCKER.md](./README.DOCKER.md)
|
||||
|
||||
### Lokal starten / Selbst hosten (Fork homebrewery-oidc)
|
||||
|
||||
```bash
|
||||
cp .env.example .env # optional, alle Werte haben Entwicklungs-Defaults
|
||||
docker compose up --build # App + MongoDB -> http://localhost:8000
|
||||
```
|
||||
|
||||
`docker-compose.override.yml` (wird automatisch geladen) und `docker/` enthalten die Fork-Erweiterungen; `docker-compose.yml` bleibt Upstream-identisch.
|
||||
|
||||
| Profil | Start | Ergebnis |
|
||||
|---|---|---|
|
||||
| `postgres` | `docker compose --profile postgres up -d postgres` | PostgreSQL 18 auf `127.0.0.1:5432` (ab M2) |
|
||||
| `keycloak` | `docker compose --profile keycloak up -d` | Keycloak :8080, Realm `homebrewery`, Client `homebrewery`/`dev-only-client-secret`, Nutzer `testuser`/`testuser-dev`, Admin `admin`/`admin-dev`. Discovery: `http://keycloak.localhost:8080/realms/homebrewery/.well-known/openid-configuration` (Start dauert 1–2 Min.) |
|
||||
| `authentik` | `docker compose --profile authentik up -d` | authentik :9000, Provider/App `homebrewery` per Blueprint, gleicher Client und Nutzer, Admin `akadmin`/`admin-dev`. Discovery: `http://authentik.localhost:9000/application/o/homebrewery/.well-known/openid-configuration` |
|
||||
|
||||
Hinweise: Die IdPs laufen unter `keycloak.localhost:8080` bzw. `authentik.localhost:9000` (Issuer für Browser und App-Container identisch, Bindung nur an 127.0.0.1; `*.localhost` löst moderne Browser/OS automatisch auf, sonst `127.0.0.1 keycloak.localhost authentik.localhost` in `/etc/hosts`). Ports nur ändern, wenn Redirect-/Issuer-Einstellungen mitgezogen werden. Alle Zugangsdaten sind reine Dev-Werte, für den Betrieb in `.env` ersetzen. MongoDB 5+ benötigt eine CPU mit AVX; auf älteren CPUs/VMs `MONGO_TAG=4.4` setzen. Der authentik-Blueprint wird beim Erststart automatisch angewendet (dauert einige Minuten, bis die Discovery-URL 200 liefert).
|
||||
|
||||
#### Login über OIDC (Keycloak, authentik, …)
|
||||
|
||||
Der Fork bringt einen generischen OIDC-Login (Authorization Code + PKCE) mit. Konfiguration nur über Umgebungsvariablen (`HB_OIDC_ISSUER`, `HB_OIDC_CLIENT_ID`, `HB_OIDC_CLIENT_SECRET`, `HB_PUBLIC_URL`, `HB_SESSION_SECRET`, …, Vorlage in `.env.example`). Die bisherigen Logins (`naturalcrit`: Benutzername/Passwort, Google) bleiben Standard und lassen sich über `HB_AUTH_PROVIDERS` abschalten, abgeschaltete Methoden verschwinden aus der UI und ihre Endpunkte sind gesperrt. Einrichtung, Variablen und Kontozuordnung: [docs/auth/README.md](./docs/auth/README.md), [Keycloak](./docs/auth/keycloak.md), [authentik](./docs/auth/authentik.md). Entscheidung: [ADR 0001](./docs/adr/0001-auth-oidc.md).
|
||||
|
||||
#### Brews in Git speichern
|
||||
|
||||
Angemeldete OIDC-Nutzer können Brews in einem beliebigen Git-Repository speichern (HTTPS + Personal Access Token, providerneutral: Gitea, Forgejo, GitHub, GitLab, …). Speichern erzeugt einen Commit, beim Öffnen wird der Remote-Stand übernommen, Konflikte werden erkannt und angezeigt. Das Feature ist aus, solange `HB_GIT_TOKEN_KEY` fehlt. Einrichtung, Variablen, Sicherheit und Anbieter-Hinweise: [docs/git/README.md](./docs/git/README.md). Entscheidung: [ADR 0003](./docs/adr/0003-git-backend-und-teilen.md). Fehlersuche und nachträgliches Aktivieren: [docs/git/README.md](./docs/git/README.md#fehlersuche--nachträglich-aktivieren).
|
||||
|
||||
#### Betrieb mit dem veröffentlichten Image
|
||||
|
||||
Compose-Vorlage (App + PostgreSQL 18, OIDC, Git, Bild-Upload) ohne Repo-Checkout: [docs/deploy/README.md](./docs/deploy/README.md). Wichtig: Jede `HB_*`-Variable muss im Container ankommen (`environment:`/`env_file:`), und nach Änderungen gilt `docker compose up -d`, nicht `restart`.
|
||||
|
||||
### Running the application on FreeBSD or FreeNAS
|
||||
|
||||
Please see the docs here: [README.FreeBSD.md](./README.FREEBSD.md)
|
||||
|
||||
+142
-5
@@ -90,21 +90,157 @@ pre {
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## changelog
|
||||
For a full record of development, visit our [Github Page](https://github.com/naturalcrit/homebrewery).
|
||||
|
||||
### 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**}} to be inserted mid-line
|
||||
* [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] Replace all example artwork with
|
||||
* [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
|
||||
@@ -119,6 +255,7 @@ Fixes issues [#543](https://github.com/naturalcrit/homebrewery/issues/543), [#24
|
||||
* [x] Multiple other backend fixes and refactors
|
||||
}}
|
||||
|
||||
|
||||
### Friday 1/11/2026 - v3.20.1
|
||||
|
||||
{{taskList
|
||||
@@ -155,7 +292,7 @@ Fixes issue [#4559](https://github.com/naturalcrit/homebrewery/issues/4559)
|
||||
##### G-Ambatte
|
||||
* [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
|
||||
|
||||
Fixes issue [#807](https://github.com/naturalcrit/homebrewery/issues/807)
|
||||
@@ -314,7 +451,7 @@ Fixes issue [#1729](https://github.com/naturalcrit/homebrewery/issues/1729)
|
||||
Fixes issue [#4079](https://github.com/naturalcrit/homebrewery/issues/4079)
|
||||
|
||||
##### 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
|
||||
|
||||
Fixes issue [#4059](https://github.com/naturalcrit/homebrewery/issues/4059)
|
||||
@@ -2384,4 +2521,4 @@ Massive changelog incoming:
|
||||
|
||||
* Added `phb.standalone.css` plus a build system for creating it
|
||||
* Added page numbers and footer text
|
||||
* Page accent now flips each page
|
||||
* Page accent now flips each page
|
||||
@@ -107,9 +107,13 @@ body {
|
||||
}
|
||||
|
||||
th, td {
|
||||
max-width : 50ch;
|
||||
padding : 5px 10px;
|
||||
overflow : hidden;
|
||||
text-overflow : ellipsis;
|
||||
vertical-align : middle;
|
||||
text-align : center;
|
||||
white-space : nowrap;
|
||||
border-right : 1px solid;
|
||||
|
||||
&:last-child { border-right : none; }
|
||||
|
||||
@@ -1,71 +1,176 @@
|
||||
import React from 'react';
|
||||
import createReactClass from 'create-react-class';
|
||||
import React, { useState } from 'react';
|
||||
import request from 'superagent';
|
||||
import Moment from 'moment';
|
||||
|
||||
const BrewCleanup = createReactClass({
|
||||
displayName : 'BrewCleanup',
|
||||
getDefaultProps(){
|
||||
return {};
|
||||
},
|
||||
getInitialState() {
|
||||
return {
|
||||
count : 0,
|
||||
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);
|
||||
|
||||
pending : false,
|
||||
primed : false,
|
||||
err : null
|
||||
};
|
||||
},
|
||||
prime(){
|
||||
this.setState({ pending: true });
|
||||
const find = async (type)=>{
|
||||
|
||||
request.get('/admin/cleanup')
|
||||
.then((res)=>this.setState({ count: res.body.count, primed: true }))
|
||||
.catch((err)=>this.setState({ error: err }))
|
||||
.finally(()=>this.setState({ pending: false }));
|
||||
},
|
||||
cleanup(){
|
||||
this.setState({ pending: true });
|
||||
|
||||
request.post('/admin/cleanup')
|
||||
.then((res)=>this.setState({ count: res.body.count }))
|
||||
.catch((err)=>this.setState({ error: err }))
|
||||
.finally(()=>this.setState({ pending: false, primed: false }));
|
||||
},
|
||||
renderPrimed(){
|
||||
if(!this.state.primed) return;
|
||||
if(type === 'junk') try {
|
||||
setPendingJunk(true);
|
||||
const res = await request.get('/admin/cleanupJunk');
|
||||
|
||||
if(!this.state.count){
|
||||
return <div className='result noBrews'>No Matching Brews found.</div>;
|
||||
setJunkBrewCollection(res.body.brewCollection);
|
||||
} catch (err) {
|
||||
setError(err);
|
||||
} finally {
|
||||
setPendingJunk(false);
|
||||
}
|
||||
|
||||
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'>
|
||||
<button onClick={this.cleanup} className='remove'>
|
||||
{this.state.pending
|
||||
{deleteButton && <button onClick={()=>cleanup(type)} className='remove'>
|
||||
{pendingLost && type === 'lost' || pendingJunk && type === 'junk'
|
||||
? <i className='fas fa-spin fa-spinner' />
|
||||
: <span><i className='fas fa-times' /> Remove</span>
|
||||
}
|
||||
</button>
|
||||
<span>Found {this.state.count} Brews that could be removed. </span>
|
||||
}
|
||||
{renderBrewList(type)}
|
||||
</div>;
|
||||
},
|
||||
render(){
|
||||
return <div className='brewUtil brewCleanup'>
|
||||
<h2> Brew Cleanup </h2>
|
||||
<p>Removes very short brews to tidy up the database</p>
|
||||
};
|
||||
const renderJunkBrewCleanup = ()=>{
|
||||
return <div className='junk'>
|
||||
<h3> Junk brews</h3>
|
||||
<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'>
|
||||
{this.state.pending
|
||||
<button onClick={()=>find('junk')} className='query'>
|
||||
{pendingJunk
|
||||
? <i className='fas fa-spin fa-spinner' />
|
||||
: 'Query Brews'
|
||||
}
|
||||
</button>
|
||||
{this.renderPrimed()}
|
||||
{renderFound('junk')}
|
||||
|
||||
{this.state.error
|
||||
&& <div className='error noBrews'>{this.state.error.toString()}</div>
|
||||
}
|
||||
{error && <div className='error noBrews'>{error.toString()}</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>
|
||||
|
||||
<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;
|
||||
@@ -16,7 +16,7 @@
|
||||
margin-left : 10px;
|
||||
}
|
||||
&.checkbox {
|
||||
line-height: 1.5em;
|
||||
line-height : 1.5em;
|
||||
input {
|
||||
width : 1.5em;
|
||||
height : 1.5em;
|
||||
@@ -26,9 +26,9 @@
|
||||
}
|
||||
|
||||
.lockSuggestions {
|
||||
columns : 2;
|
||||
line-height : 1.2em;
|
||||
break-inside : avoid;
|
||||
columns : 2;
|
||||
h2 { column-span : all; }
|
||||
h3 { margin-top : 0px; }
|
||||
b { font-weight : 600; }
|
||||
|
||||
@@ -1,6 +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();
|
||||
@@ -71,10 +71,14 @@ const Anchored = ({ children })=>{
|
||||
// forward ref for AnchoredTrigger
|
||||
const AnchoredTrigger = forwardRef(({ toggleVisibility, visible, children, className, ...props }, ref)=>(
|
||||
<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}`}
|
||||
onClick={toggleVisibility}
|
||||
style={{ anchorName: `--${props.id}` }} // setting anchor properties here allows greater recyclability.
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
@@ -84,9 +88,12 @@ const AnchoredTrigger = forwardRef(({ toggleVisibility, visible, children, class
|
||||
// forward ref for AnchoredBox
|
||||
const AnchoredBox = forwardRef(({ visible, children, className, anchorId, ...props }, ref)=>(
|
||||
<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}`}
|
||||
style={{ positionAnchor: `--${anchorId}` }} // setting anchor properties here allows greater recyclability.
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
|
||||
|
||||
.anchored-box {
|
||||
position : absolute;
|
||||
visibility : hidden;
|
||||
justify-self : anchor-center;
|
||||
@supports (inset-block-start: anchor(bottom)) {
|
||||
inset-block-start : anchor(bottom);
|
||||
}
|
||||
position : absolute;
|
||||
inset-block-start : anchor(bottom);
|
||||
visibility : hidden;
|
||||
justify-self : anchor-center;
|
||||
&.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);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export default {
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
export default {
|
||||
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,494 +1,442 @@
|
||||
/* eslint-disable max-lines */
|
||||
/* eslint max-lines: ["error", { "max": 455 }] */
|
||||
import './codeEditor.less';
|
||||
import React from 'react';
|
||||
import createReactClass from 'create-react-class';
|
||||
import _ from 'lodash';
|
||||
import closeTag from './close-tag';
|
||||
import autoCompleteEmoji from './autocompleteEmoji';
|
||||
let CodeMirror;
|
||||
import React, { useEffect, useRef, forwardRef, useImperativeHandle } from 'react';
|
||||
|
||||
const CodeEditor = createReactClass({
|
||||
displayName : 'CodeEditor',
|
||||
getDefaultProps : function() {
|
||||
return {
|
||||
language : '',
|
||||
tab : 'brewText',
|
||||
value : '',
|
||||
wrap : true,
|
||||
onChange : ()=>{},
|
||||
onReady : ()=>{},
|
||||
enableFolding : true,
|
||||
editorTheme : 'default'
|
||||
};
|
||||
import {
|
||||
EditorView,
|
||||
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';
|
||||
|
||||
const autoCloseBrackets = closeBrackets({ brackets: ['()', '[]', '{{}}'] });
|
||||
|
||||
import defaultCM5Theme from '@themes/codeMirror/default.js';
|
||||
import darkbrewery from '@themes/codeMirror/darkbrewery.js';
|
||||
import cm5Themes from 'codemirror-5-themes';
|
||||
|
||||
const themes = { default: defaultCM5Theme, ...cm5Themes, darkbrewery };
|
||||
const themeCompartment = new Compartment();
|
||||
const highlightCompartment = new Compartment();
|
||||
const settingsCompartment = new Compartment();
|
||||
|
||||
import { generalKeymap, markdownKeymap, cssKeymap, formatCSS } from './extensions/customKeyMaps.js';
|
||||
import foldOnPages from './extensions/customFolding.js';
|
||||
import { customHighlightStyle, customHighlightPlugin } from './extensions/customHighlight.js';
|
||||
import { legacyCustomHighlightStyle } from './extensions/legacyCustomHighlight.js';
|
||||
|
||||
const PAGEBREAK_REGEX_V3 = /^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m;
|
||||
|
||||
const setProgrammaticCursorLine = StateEffect.define();
|
||||
|
||||
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 {
|
||||
docs : {}
|
||||
};
|
||||
},
|
||||
|
||||
editor : React.createRef(null),
|
||||
|
||||
async componentDidMount() {
|
||||
CodeMirror = (await import('codemirror')).default;
|
||||
this.CodeMirror = CodeMirror;
|
||||
|
||||
await import('codemirror/mode/gfm/gfm.js');
|
||||
await import('codemirror/mode/css/css.js');
|
||||
await import('codemirror/mode/javascript/javascript.js');
|
||||
|
||||
// addons
|
||||
await import('codemirror/addon/fold/foldcode.js');
|
||||
await import('codemirror/addon/fold/foldgutter.js');
|
||||
await import('codemirror/addon/fold/xml-fold.js');
|
||||
await import('codemirror/addon/search/search.js');
|
||||
await import('codemirror/addon/search/searchcursor.js');
|
||||
await import('codemirror/addon/search/jump-to-line.js');
|
||||
await import('codemirror/addon/search/match-highlighter.js');
|
||||
await import('codemirror/addon/search/matchesonscrollbar.js');
|
||||
await import('codemirror/addon/dialog/dialog.js');
|
||||
await import('codemirror/addon/scroll/scrollpastend.js');
|
||||
await import('codemirror/addon/edit/closetag.js');
|
||||
await import('codemirror/addon/hint/show-hint.js');
|
||||
// import 'codemirror/addon/selection/active-line.js';
|
||||
// import 'codemirror/addon/edit/trailingspace.js';
|
||||
|
||||
|
||||
// register helpers dynamically as well
|
||||
const foldPagesCode = (await import('./fold-pages')).default;
|
||||
const foldCSSCode = (await import('./fold-css')).default;
|
||||
foldPagesCode.registerHomebreweryHelper(CodeMirror);
|
||||
foldCSSCode.registerHomebreweryHelper(CodeMirror);
|
||||
|
||||
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];
|
||||
return Decoration.set([
|
||||
Decoration.line({
|
||||
class : 'sourceMoveFlash'
|
||||
}).range(line.from)
|
||||
]);
|
||||
}
|
||||
|
||||
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;
|
||||
},
|
||||
|
||||
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;
|
||||
// }
|
||||
});
|
||||
this.props.onReady?.(this.codeMirror);
|
||||
// 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();
|
||||
},
|
||||
|
||||
// Use for GFM tabs that use common hot-keys
|
||||
isGFM : function() {
|
||||
console.log(this.props.tab);
|
||||
if( this.props.tab === 'brewText' || this.props.tab === 'brewSnippets') return true;
|
||||
return false;
|
||||
},
|
||||
|
||||
isBrewText : function() {
|
||||
if(this.isGFM()) return true;
|
||||
return false;
|
||||
},
|
||||
|
||||
isBrewSnippets : function() {
|
||||
if(this.props.tab === 'brewSnippets') return true;
|
||||
return false;
|
||||
},
|
||||
|
||||
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) {
|
||||
if(!this.isGFM()) return;
|
||||
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() {
|
||||
console.log('hello');
|
||||
if(!this.isGFM()) return;
|
||||
console.log(this.isGFM());
|
||||
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() {
|
||||
if(!this.isGFM()) return;
|
||||
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() {
|
||||
if(!this.isGFM()) return;
|
||||
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() {
|
||||
if(!this.isGFM()) return;
|
||||
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() {
|
||||
if(!this.isGFM()) return;
|
||||
this.codeMirror?.replaceSelection(' ', 'end');
|
||||
},
|
||||
|
||||
makeSpace : function() {
|
||||
if(!this.isGFM()) return;
|
||||
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() {
|
||||
if(!this.isGFM()) return;
|
||||
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() {
|
||||
if(!this.isGFM()) return;
|
||||
this.codeMirror?.replaceSelection('\n\\column\n\n', 'end');
|
||||
},
|
||||
|
||||
newPage : function() {
|
||||
if(!this.isGFM()) return;
|
||||
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() {
|
||||
if(!this.isGFM()) return;
|
||||
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() {
|
||||
if(!this.isGFM()) return;
|
||||
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() {
|
||||
if(!this.isGFM()) return;
|
||||
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.isGFM()){
|
||||
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() {
|
||||
if(!this.isGFM()) return;
|
||||
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) {
|
||||
if(!this.isGFM()) return;
|
||||
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}/>
|
||||
</>;
|
||||
}
|
||||
provide : (decorationSet)=>EditorView.decorations.from(decorationSet)
|
||||
});
|
||||
|
||||
export default 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';
|
||||
@import (less) 'codemirror/addon/fold/foldgutter.css';
|
||||
@import (less) 'codemirror/addon/search/matchesonscrollbar.css';
|
||||
@import (less) 'codemirror/addon/dialog/dialog.css';
|
||||
@import (less) 'codemirror/addon/hint/show-hint.css';
|
||||
|
||||
//Icon fonts included so they can appear in emoji autosuggest dropdown
|
||||
// Icon fonts for emoji/autocomplete
|
||||
@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 {
|
||||
50% { color : white;background-color : red;}
|
||||
100% { color : unset;background-color : unset;}
|
||||
50% {
|
||||
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) {
|
||||
font-size : 16px;
|
||||
}
|
||||
.CodeMirror-foldmarker {
|
||||
|
||||
.cm-gutterElement span {
|
||||
font-family : inherit;
|
||||
font-weight : 600;
|
||||
color : grey;
|
||||
text-shadow : none;
|
||||
}
|
||||
|
||||
.CodeMirror-foldgutter {
|
||||
.cm-foldGutter {
|
||||
cursor : pointer;
|
||||
border-left : 1px solid #EEEEEE;
|
||||
transition : background 0.1s;
|
||||
&:hover { background : #DDDDDD; }
|
||||
}
|
||||
|
||||
.sourceMoveFlash .CodeMirror-line {
|
||||
/* Flash animation for source moves */
|
||||
.cm-line.sourceMoveFlash {
|
||||
animation-name : sourceMoveAnimation;
|
||||
animation-duration : 0.4s;
|
||||
}
|
||||
|
||||
.CodeMirror-search-field {
|
||||
width:25em !important;
|
||||
outline:1px inset #00000055 !important;
|
||||
/* Search input */
|
||||
.cm-searchField {
|
||||
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 {
|
||||
// background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAMCAQAAACOs/baAAAARUlEQVR4nGJgIAG8JkXxUAcCtDWemcGR1lY4MvgzCEKY7jSBjgxBDAG09UEQzAe0AMwMHrSOAwEGRtpaMIwAAAAA//8DAG4ID9EKs6YqAAAAAElFTkSuQmCC) no-repeat right;
|
||||
// background: url(...) no-repeat right;
|
||||
//}
|
||||
|
||||
//.cm-trailingspace {
|
||||
// .cm-space {
|
||||
// background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAQAgMAAABW5NbuAAAACVBMVEVHcEwAAAAAAAAWawmTAAAAA3RSTlMAPBJ6PMxpAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAFUlEQVQI12NgwACcCQysASAEZGAAACMuAX06aCQUAAAAAElFTkSuQmCC) no-repeat right;
|
||||
// }
|
||||
/* Trailing space visualization (optional) */
|
||||
//.cm-trailingSpace .cm-space {
|
||||
// background: url(...) no-repeat right;
|
||||
//}
|
||||
}
|
||||
|
||||
/* Emoji preview styling */
|
||||
.emojiPreview {
|
||||
font-size : 1.5em;
|
||||
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 @@
|
||||
export default {
|
||||
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 @@
|
||||
export default {
|
||||
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;
|
||||
});
|
||||
}
|
||||
};
|
||||
+94
-102
@@ -1,141 +1,133 @@
|
||||
import React from 'react';
|
||||
import createReactClass from 'create-react-class';
|
||||
import React, { useState, useEffect, useRef, useCallback } from 'react';
|
||||
import _ from 'lodash';
|
||||
import './combobox.less';
|
||||
|
||||
const Combobox = createReactClass({
|
||||
displayName : 'Combobox',
|
||||
getDefaultProps : function() {
|
||||
return {
|
||||
className : '',
|
||||
trigger : 'hover',
|
||||
default : '',
|
||||
placeholder : '',
|
||||
tooltip : '',
|
||||
autoSuggest : {
|
||||
clearAutoSuggestOnClick : true,
|
||||
suggestMethod : 'includes',
|
||||
filterOn : [] // should allow as array to filter on multiple attributes, or even custom filter
|
||||
},
|
||||
valuePatterns : /.+/
|
||||
};
|
||||
const Combobox = ({
|
||||
id = '',
|
||||
className = '',
|
||||
trigger = 'hover',
|
||||
defaultValue = '',
|
||||
placeholder = '',
|
||||
tooltip = '',
|
||||
autoSuggest = {
|
||||
clearAutoSuggestOnClick : true,
|
||||
suggestMethod : 'includes',
|
||||
filterOn : [] // should allow as array to filter on multiple attributes, or even custom filter
|
||||
},
|
||||
getInitialState : function() {
|
||||
this.dropdownRef = React.createRef();
|
||||
return {
|
||||
showDropdown : false,
|
||||
value : '',
|
||||
options : [...this.props.options],
|
||||
inputFocused : false
|
||||
};
|
||||
},
|
||||
componentDidMount : function() {
|
||||
if(this.props.trigger == 'click')
|
||||
document.addEventListener('click', this.handleClickOutside);
|
||||
this.setState({
|
||||
value : this.props.default
|
||||
});
|
||||
},
|
||||
componentWillUnmount : function() {
|
||||
if(this.props.trigger == 'click')
|
||||
document.removeEventListener('click', this.handleClickOutside);
|
||||
},
|
||||
handleClickOutside : function(e){
|
||||
// Close dropdown when clicked outside
|
||||
if(this.dropdownRef.current && !this.dropdownRef.current.contains(e.target)) {
|
||||
this.handleDropdown(false);
|
||||
valuePatterns = '.+',
|
||||
options = [],
|
||||
keepValueOnClose = false,
|
||||
...props
|
||||
})=>{
|
||||
const dropdownRef = useRef(null);
|
||||
const [showDropdown, setShowDropdown] = useState(false);
|
||||
const [inputFocused, setInputFocused] = useState(false);
|
||||
const [value, setValue] = useState(defaultValue);
|
||||
|
||||
useEffect(()=>{
|
||||
if(trigger === 'click') {
|
||||
document.addEventListener('click', handleClickOutside);
|
||||
return ()=>document.removeEventListener('click', handleClickOutside);
|
||||
}
|
||||
},
|
||||
handleDropdown : function(show){
|
||||
this.setState({
|
||||
value : show ? '' : this.props.default,
|
||||
showDropdown : show,
|
||||
inputFocused : this.props.autoSuggest.clearAutoSuggestOnClick ? show : false
|
||||
});
|
||||
},
|
||||
handleInput : function(e){
|
||||
e.persist();
|
||||
this.setState({
|
||||
value : e.target.value,
|
||||
inputFocused : false
|
||||
}, ()=>{
|
||||
this.props.onEntry(e);
|
||||
});
|
||||
},
|
||||
handleSelect : function(value, data=value){
|
||||
this.setState({
|
||||
value : value
|
||||
}, ()=>{this.props.onSelect(data);});
|
||||
;
|
||||
},
|
||||
renderTextInput : function(){
|
||||
}, []);
|
||||
|
||||
const handleClickOutside = useCallback((e)=>{
|
||||
// Close dropdown when clicked outside
|
||||
if(!dropdownRef.current?.contains(e.target)) {
|
||||
handleDropdown(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleDropdown = (show)=>{
|
||||
if(show) {
|
||||
if(autoSuggest.clearAutoSuggestOnClick) {
|
||||
setValue('');
|
||||
}
|
||||
} else if(!keepValueOnClose) {
|
||||
setValue(defaultValue);
|
||||
}
|
||||
setShowDropdown(show);
|
||||
setInputFocused(autoSuggest.clearAutoSuggestOnClick && show);
|
||||
};
|
||||
|
||||
const handleInput = (e)=>{
|
||||
setValue(e.target.value);
|
||||
setInputFocused(false);
|
||||
props.onEntry(e);
|
||||
};
|
||||
|
||||
const handleSelect = (value, data=value)=>{
|
||||
setValue(value);
|
||||
props.onSelect(data);
|
||||
};
|
||||
|
||||
const renderTextInput = ()=>{
|
||||
return (
|
||||
<div className='dropdown-input item'
|
||||
onMouseEnter={this.props.trigger == 'hover' ? ()=>{this.handleDropdown(true);} : undefined}
|
||||
onClick= {this.props.trigger == 'click' ? ()=>{this.handleDropdown(true);} : undefined}
|
||||
{...(this.props.tooltip ? { 'data-tooltip-right': this.props.tooltip } : {})}>
|
||||
onMouseEnter={trigger == 'hover' ? ()=>{handleDropdown(true);} : undefined}
|
||||
onClick= {trigger == 'click' ? ()=>{handleDropdown(true);} : undefined}
|
||||
{...(tooltip ? { 'data-tooltip-right': tooltip } : {})}>
|
||||
<input
|
||||
id={id}
|
||||
type='text'
|
||||
onChange={(e)=>this.handleInput(e)}
|
||||
value={this.state.value || ''}
|
||||
onChange={(e)=>handleInput(e)}
|
||||
value={value || ''}
|
||||
title=''
|
||||
pattern={this.props.valuePatterns}
|
||||
placeholder={this.props.placeholder}
|
||||
pattern={valuePatterns}
|
||||
placeholder={placeholder}
|
||||
onBlur={(e)=>{
|
||||
if(!e.target.checkValidity()){
|
||||
this.setState({
|
||||
value : this.props.default
|
||||
});
|
||||
setValue(defaultValue);
|
||||
}
|
||||
}}
|
||||
onKeyDown={(e)=>{
|
||||
if(e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
this.props.onEntry(e);
|
||||
props.onEntry(e);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<i className='fas fa-caret-down'/>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
renderDropdown : function(dropdownChildren){
|
||||
if(!this.state.showDropdown) return null;
|
||||
if(this.props.autoSuggest && !this.state.inputFocused){
|
||||
const suggestMethod = this.props.autoSuggest.suggestMethod;
|
||||
const filterOn = _.isString(this.props.autoSuggest.filterOn) ? [this.props.autoSuggest.filterOn] : this.props.autoSuggest.filterOn;
|
||||
};
|
||||
|
||||
const renderDropdown = ()=>{
|
||||
if(!showDropdown) return null;
|
||||
let dropdownChildren = options.map((child, i)=>{
|
||||
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 children = dropdownChildren.filter((item)=>{
|
||||
if(suggestMethod === 'includes')
|
||||
return item.props[attr]?.toLowerCase().includes(this.state.value.toLowerCase());
|
||||
return item.props[attr]?.toLowerCase().includes(value.toLowerCase());
|
||||
if(suggestMethod === 'startsWith')
|
||||
return item.props[attr]?.toLowerCase().startsWith(this.state.value.toLowerCase());
|
||||
return item.props[attr]?.toLowerCase().startsWith(value.toLowerCase());
|
||||
});
|
||||
return children;
|
||||
});
|
||||
dropdownChildren = _.uniq(filteredArrays.flat(1));
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='dropdown-options'>
|
||||
{dropdownChildren}
|
||||
</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={this.dropdownRef}
|
||||
onMouseLeave={this.props.trigger == 'hover' ? ()=>{this.handleDropdown(false);} : undefined}>
|
||||
{this.renderTextInput()}
|
||||
{this.renderDropdown(dropdownChildren)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={`dropdown-container ${className}`}
|
||||
ref={dropdownRef}
|
||||
onMouseLeave={trigger == 'hover' ? ()=>{handleDropdown(false);} : undefined}>
|
||||
{renderTextInput()}
|
||||
{renderDropdown()}
|
||||
</div>
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
export default Combobox;
|
||||
@@ -4,7 +4,7 @@
|
||||
.item i {
|
||||
position : absolute;
|
||||
right : 10px;
|
||||
color : black;
|
||||
color : inherit;
|
||||
}
|
||||
.dropdown-options {
|
||||
position : absolute;
|
||||
@@ -31,15 +31,12 @@
|
||||
font-family : 'Open Sans';
|
||||
font-size : 11px;
|
||||
cursor : default;
|
||||
&:hover {
|
||||
background-color : rgb(163, 163, 163);
|
||||
filter : brightness(120%);
|
||||
}
|
||||
&:hover { background-color : #DDDDDD; }
|
||||
.detail {
|
||||
width : 100%;
|
||||
font-size : 9px;
|
||||
font-style : italic;
|
||||
color : rgb(124, 124, 124);
|
||||
color : #7C7C7C;
|
||||
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
|
||||
}
|
||||
@@ -18,8 +18,7 @@ const SplitPane = (props)=>{
|
||||
const [liveScroll, setLiveScroll] = useState(false);
|
||||
|
||||
useEffect(()=>{
|
||||
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);
|
||||
handleResize();
|
||||
setLiveScroll(window.localStorage.getItem(LIVE_SCROLL_KEY) === 'true');
|
||||
|
||||
window.addEventListener('resize', handleResize);
|
||||
@@ -29,7 +28,10 @@ const SplitPane = (props)=>{
|
||||
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
|
||||
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)=>{
|
||||
e.preventDefault();
|
||||
@@ -56,20 +58,32 @@ const SplitPane = (props)=>{
|
||||
setLiveScroll(!liveScroll);
|
||||
};
|
||||
|
||||
const DividerButton = ({ className, children, ...props })=>{
|
||||
return <div
|
||||
className={className}
|
||||
onPointerDown={(e)=>{e.stopPropagation();}}
|
||||
{...props} >
|
||||
|
||||
{children}
|
||||
|
||||
</div>;
|
||||
};
|
||||
|
||||
const renderMoveArrows = (showMoveArrows &&
|
||||
<>
|
||||
<div className='arrow left'
|
||||
<DividerButton className='arrow left'
|
||||
onClick={()=>setMoveSource(!moveSource)} >
|
||||
<i className='fas fa-arrow-left' />
|
||||
</div>
|
||||
<div className='arrow right'
|
||||
</DividerButton>
|
||||
<DividerButton
|
||||
className='arrow right'
|
||||
onClick={()=>setMoveBrew(!moveBrew)} >
|
||||
<i className='fas fa-arrow-right' />
|
||||
</div>
|
||||
<div id='scrollToggleDiv' className={liveScroll ? 'arrow lock' : 'arrow unlock'}
|
||||
</DividerButton>
|
||||
<DividerButton id='scrollToggleDiv' className={liveScroll ? 'arrow lock' : 'arrow unlock'}
|
||||
onClick={liveScrollToggle} >
|
||||
<i id='scrollToggle' className={liveScroll ? 'fas fa-lock' : 'fas fa-unlock'} />
|
||||
</div>
|
||||
</DividerButton>
|
||||
</>
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import './assets.less';
|
||||
import React, { useRef } from 'react';
|
||||
import cx from 'classnames';
|
||||
import { imageFiles, formatBytes } from './assetClient.js';
|
||||
|
||||
// Button in der Snippet-Bar (ADR 0004 §5): Dateiauswahl, Fortschritt und Fehlertexte direkt am Button.
|
||||
// Sichtbar nur bei Git-verknüpften Brews (assetUpload.available).
|
||||
const AssetUploadButton = ({ assetUpload })=>{
|
||||
const input = useRef(null);
|
||||
if(!assetUpload?.available) return null;
|
||||
const { cfg, busy, percent, name, errors, done, upload, dismiss } = assetUpload;
|
||||
const accept = cfg.types.map((t)=>`image/${t}`).join(',');
|
||||
|
||||
return (
|
||||
<div className='assetUpload'>
|
||||
<button className={cx('editorTool', 'assetUploadButton', { active: !busy })}
|
||||
disabled={busy}
|
||||
title={`Bild ins Git-Repository hochladen (${cfg.types.join(', ').toUpperCase()}, max. ${formatBytes(cfg.maxBytes)}). Auch per Drag-and-drop oder Einfügen. Hinweis: Metadaten (z. B. GPS) bleiben erhalten, Bilder sind über den Teilen-Link öffentlich.`}
|
||||
onClick={()=>input.current?.click()}>
|
||||
<i className={busy ? 'fas fa-spinner fa-spin' : 'fas fa-image'} />
|
||||
</button>
|
||||
<input ref={input} type='file' hidden multiple accept={accept}
|
||||
onChange={(e)=>{ const files = imageFiles(e.target.files); e.target.value = ''; upload(files); }} />
|
||||
{(busy || errors.length > 0 || done > 0) && (
|
||||
<div className={cx('assetUploadStatus', { error: errors.length > 0 })} role='status'>
|
||||
{busy && <span>„{name}“ wird hochgeladen{percent != null ? ` (${percent} %)` : ''} …</span>}
|
||||
{!busy && done > 0 && errors.length === 0 && <span>{done === 1 ? 'Bild eingefügt.' : `${done} Bilder eingefügt.`} Hinweis: Fotos können Metadaten (z. B. GPS) enthalten und sind über den Teilen-Link öffentlich.</span>}
|
||||
{!busy && errors.map((msg, i)=><span key={i}>{msg}</span>)}
|
||||
{!busy && <button className='dismiss' onClick={dismiss} title='Schließen'><i className='fas fa-times' /></button>}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default AssetUploadButton;
|
||||
@@ -0,0 +1,76 @@
|
||||
import request from '../../homebrew/utils/request-middleware.js';
|
||||
|
||||
// Client-Seite des Bild-Uploads (ADR 0004 §5). Reine Funktionen und dünne API-Hülle, ohne React.
|
||||
|
||||
export const MIME_TYPE = { 'image/png': 'png', 'image/jpeg': 'jpeg', 'image/gif': 'gif', 'image/webp': 'webp' };
|
||||
|
||||
const MIB = 1024 * 1024;
|
||||
export const formatBytes = (n)=>{
|
||||
if(n >= MIB) return `${+(n / MIB).toFixed(1)} MiB`;
|
||||
if(n >= 1024) return `${Math.round(n / 1024)} KiB`;
|
||||
return `${n} Byte`;
|
||||
};
|
||||
|
||||
// Vorabprüfung mit den Limits des Servers, spart den Upload. Der Server prüft ohnehin erneut.
|
||||
export const validateFile = (file, cfg)=>{
|
||||
const type = MIME_TYPE[file.type];
|
||||
if(!type || !cfg.types.includes(type))
|
||||
return `„${file.name}“: Dieser Dateityp ist nicht erlaubt. Erlaubt sind: ${cfg.types.join(', ').toUpperCase()}.`;
|
||||
if(file.size > cfg.maxBytes)
|
||||
return `„${file.name}“ ist zu groß (${formatBytes(file.size)}). Erlaubt sind höchstens ${formatBytes(cfg.maxBytes)}.`;
|
||||
if(file.size === 0) return `„${file.name}“ ist leer.`;
|
||||
return null;
|
||||
};
|
||||
|
||||
export const imageFiles = (fileList)=>Array.from(fileList ?? []).filter((f)=>f.type?.startsWith('image/'));
|
||||
|
||||
// Verständliche Meldung zu einem Fehler der API (A01–A07, G02–G05, G08, 412, 401)
|
||||
export const describeError = (err)=>{
|
||||
const code = err?.HBErrorCode;
|
||||
const msg = err?.message;
|
||||
if(err?.status === 412) return msg || 'Die Seite ist veraltet. Bitte neu laden.';
|
||||
if(err?.status === 401) return 'Bitte melde dich an und prüfe, ob du Autor dieses Brews bist.';
|
||||
if(code === 'G02') return 'Anmeldung am Git-Server fehlgeschlagen. Prüfe den Token der Verbindung (Schreibrecht nötig).';
|
||||
if(code === 'G03') return 'Repository oder Branch nicht gefunden.';
|
||||
if(code === 'G04') return 'Der Git-Server ist nicht erreichbar. Bitte später erneut versuchen.';
|
||||
if(code === 'G05') return 'Speichern im Repository gerade nicht möglich. Bitte erneut versuchen.';
|
||||
return msg || 'Das Bild konnte nicht hochgeladen werden.';
|
||||
};
|
||||
|
||||
const unwrap = (promise)=>promise.then((res)=>res.body).catch((err)=>{
|
||||
const body = err.response?.body ?? {};
|
||||
const e = new Error(body.message || err.message);
|
||||
e.status = err.response?.status;
|
||||
e.HBErrorCode = body.HBErrorCode;
|
||||
e.body = body;
|
||||
throw e;
|
||||
});
|
||||
|
||||
export const assetApi = {
|
||||
config : ()=>unwrap(request.get('/api/git/assets/config')),
|
||||
upload : (editId, file, { onProgress } = {})=>{
|
||||
const req = request.post(`/api/git/brews/${editId}/assets`)
|
||||
.set('Content-Type', file.type)
|
||||
.set('X-HB-Filename', encodeURIComponent(file.name || 'image'))
|
||||
.send(file);
|
||||
if(onProgress) req.on('progress', (e)=>{ if(e.direction === 'upload' && e.percent != null) onProgress(Math.round(e.percent)); });
|
||||
return unwrap(req);
|
||||
}
|
||||
};
|
||||
|
||||
// Dateien nacheinander hochladen. Liefert Markdown für alle erfolgreichen und die Fehlermeldungen.
|
||||
export const uploadFiles = async (editId, files, cfg, { api = assetApi, onProgress } = {})=>{
|
||||
const markdown = [];
|
||||
const errors = [];
|
||||
for (const [i, file] of files.entries()) {
|
||||
const invalid = validateFile(file, cfg);
|
||||
if(invalid) { errors.push(invalid); continue; }
|
||||
try {
|
||||
const res = await api.upload(editId, file, { onProgress: (p)=>onProgress?.({ index: i, total: files.length, percent: p, name: file.name }) });
|
||||
markdown.push(res.markdown ?? `![${file.name.replace(/\.[^.]+$/, '')}](${res.url})`);
|
||||
} catch (err) {
|
||||
errors.push(`„${file.name}“: ${describeError(err)}`);
|
||||
}
|
||||
}
|
||||
return { markdown, errors };
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
@import '@sharedStyles/core.less';
|
||||
|
||||
.assetUpload {
|
||||
position : relative;
|
||||
display : inline-block;
|
||||
.assetUploadStatus {
|
||||
position : absolute;
|
||||
z-index : 20;
|
||||
top : 100%;
|
||||
right : 0;
|
||||
display : grid;
|
||||
gap : 4px;
|
||||
width : 280px;
|
||||
padding : 8px 24px 8px 8px;
|
||||
font-size : 12px;
|
||||
color : white;
|
||||
background-color : #333333;
|
||||
&.error span { color : #ff9a9a; font-weight : 800; }
|
||||
.dismiss {
|
||||
position : absolute;
|
||||
top : 4px;
|
||||
right : 4px;
|
||||
color : white;
|
||||
cursor : pointer;
|
||||
background : none;
|
||||
border : none;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { gitApi } from '../git/gitApi.js';
|
||||
import { assetApi, imageFiles, uploadFiles } from './assetClient.js';
|
||||
|
||||
export const LINK_EVENT = 'hb:git-link-changed';
|
||||
|
||||
// Bild-Upload im Editor (ADR 0004 §5): Zustand für Button, Drag-and-drop und Einfügen aus der Zwischenablage.
|
||||
// `containerRef`: Wurzelelement des Editors, `inject(text)`: Text an der Cursorposition einfügen.
|
||||
export const useAssetUpload = ({ editId, containerRef, inject, active = true })=>{
|
||||
const [cfg, setCfg] = useState(null); // null: unbekannt/aus
|
||||
const [linked, setLinked] = useState(false);
|
||||
const [state, setState] = useState({ busy: false, percent: null, name: '', errors: [], done: 0 });
|
||||
const busyRef = useRef(false);
|
||||
const injectRef = useRef(inject);
|
||||
injectRef.current = inject;
|
||||
|
||||
useEffect(()=>{
|
||||
let live = true;
|
||||
assetApi.config().then((c)=>live && setCfg(c.enabled ? c : null)).catch(()=>live && setCfg(null));
|
||||
return ()=>{ live = false; };
|
||||
}, []);
|
||||
|
||||
useEffect(()=>{
|
||||
if(!editId || !cfg) { setLinked(false); return; }
|
||||
let live = true;
|
||||
const refresh = ()=>gitApi.status(editId).then((s)=>live && setLinked(!!s.linked)).catch(()=>live && setLinked(false));
|
||||
refresh();
|
||||
window.addEventListener(LINK_EVENT, refresh);
|
||||
return ()=>{ live = false; window.removeEventListener(LINK_EVENT, refresh); };
|
||||
}, [editId, cfg]);
|
||||
|
||||
const available = !!(cfg && linked && editId);
|
||||
|
||||
const upload = useCallback(async (files)=>{
|
||||
if(!available || busyRef.current || !files.length) return;
|
||||
busyRef.current = true;
|
||||
setState({ busy: true, percent: 0, name: files[0].name, errors: [], done: 0 });
|
||||
const { markdown, errors } = await uploadFiles(editId, files, cfg, {
|
||||
onProgress : ({ percent, name })=>setState((s)=>({ ...s, percent, name }))
|
||||
});
|
||||
if(markdown.length) injectRef.current(`${markdown.join('\n')}\n`);
|
||||
busyRef.current = false;
|
||||
setState({ busy: false, percent: null, name: '', errors, done: markdown.length });
|
||||
}, [available, editId, cfg]);
|
||||
|
||||
// Drag-and-drop und Einfügen im Text-Editor (Capture-Phase, vor CodeMirror). Nur Bilddateien, Text bleibt unberührt.
|
||||
useEffect(()=>{
|
||||
const root = containerRef?.current;
|
||||
if(!root || !available || !active) return;
|
||||
const inText = (e)=>!!e.target.closest?.('.codeEditor.brewText');
|
||||
const hasFiles = (dt)=>!!dt && (Array.from(dt.types ?? []).includes('Files') || dt.files?.length > 0);
|
||||
const onDragOver = (e)=>{
|
||||
if(inText(e) && hasFiles(e.dataTransfer)) { e.preventDefault(); e.dataTransfer.dropEffect = 'copy'; }
|
||||
};
|
||||
const onDrop = (e)=>{
|
||||
if(!inText(e)) return;
|
||||
const files = imageFiles(e.dataTransfer?.files);
|
||||
if(!files.length) return;
|
||||
e.preventDefault(); e.stopPropagation();
|
||||
upload(files);
|
||||
};
|
||||
const onPaste = (e)=>{
|
||||
if(!inText(e)) return;
|
||||
const files = imageFiles(e.clipboardData?.files);
|
||||
if(!files.length) return;
|
||||
e.preventDefault(); e.stopPropagation();
|
||||
upload(files);
|
||||
};
|
||||
root.addEventListener('dragover', onDragOver, true);
|
||||
root.addEventListener('drop', onDrop, true);
|
||||
root.addEventListener('paste', onPaste, true);
|
||||
return ()=>{
|
||||
root.removeEventListener('dragover', onDragOver, true);
|
||||
root.removeEventListener('drop', onDrop, true);
|
||||
root.removeEventListener('paste', onPaste, true);
|
||||
};
|
||||
}, [containerRef, available, active, upload]);
|
||||
|
||||
const dismiss = useCallback(()=>setState((s)=>({ ...s, errors: [], done: 0 })), []);
|
||||
|
||||
return { available, cfg, upload, dismiss, ...state };
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
// Login-/Logout-Helfer für den Client (ADR 0001 §6). Konfiguration kommt aus configuration.auth (Server).
|
||||
const NATURALCRIT_LOGIN = 'https://www.naturalcrit.com/login';
|
||||
|
||||
const authConfig = ()=>(typeof global !== 'undefined' && global.config?.auth) || null;
|
||||
|
||||
export const oidcEnabled = ()=>!!authConfig()?.providers?.includes('oidc');
|
||||
export const naturalcritEnabled = ()=>{
|
||||
const providers = authConfig()?.providers;
|
||||
return !providers || providers.includes('naturalcrit');
|
||||
};
|
||||
|
||||
export const getOidcLabel = ()=>authConfig()?.oidcLabel || 'Anmelden';
|
||||
|
||||
// redirect: Pfad (mit Query) oder absolute URL; bei OIDC wird nur der Pfad verwendet
|
||||
export const getLoginUrl = (redirect = '/')=>{
|
||||
const cfg = authConfig();
|
||||
if(cfg?.loginUrl) {
|
||||
let path = redirect;
|
||||
try {
|
||||
const u = new URL(redirect, typeof window !== 'undefined' ? window.location.href : 'http://localhost');
|
||||
path = `${u.pathname}${u.search}${u.hash}`;
|
||||
} catch { path = '/'; }
|
||||
return `${cfg.loginUrl}?redirect=${encodeURIComponent(path)}`;
|
||||
}
|
||||
if(!redirect || redirect === '/') return NATURALCRIT_LOGIN;
|
||||
const base = redirect.startsWith('/') ? (global.config?.baseUrl || global.config?.publicUrl || '') : '';
|
||||
return `${NATURALCRIT_LOGIN}?redirect=${base}${redirect}`;
|
||||
};
|
||||
|
||||
export const getLogoutUrl = ()=>authConfig()?.logoutUrl || '/auth/logout';
|
||||
|
||||
// true, wenn der Client den Logout dem Server überlassen muss (httpOnly-Cookie)
|
||||
export const logoutViaServer = (account = typeof global !== 'undefined' ? global.account : undefined)=>account?.provider === 'oidc';
|
||||
@@ -0,0 +1,102 @@
|
||||
import './git.less';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { gitApi } from './gitApi.js';
|
||||
import { classifyListError } from './panelState.js';
|
||||
|
||||
// Verbindungen verwalten (ADR 0003 §7): anlegen, testen, löschen, Brews aus dem Repo importieren.
|
||||
// Das Token-Feld ist reines Eingabefeld und wird nie vorbefüllt; der Server gibt den Token nie zurück.
|
||||
const EMPTY = { label: '', repoUrl: '', authUsername: 'git', token: '' };
|
||||
|
||||
const GitConnectionsPanel = ()=>{
|
||||
const [state, setState] = useState('loading'); // loading | hidden | notice | ready
|
||||
const [notice, setNotice] = useState('');
|
||||
const [conns, setConns] = useState([]);
|
||||
const [form, setForm] = useState(EMPTY);
|
||||
const [msg, setMsg] = useState({}); // pro Verbindung: { ok, text }
|
||||
const [formError, setFormError] = useState('');
|
||||
const [files, setFiles] = useState({}); // pro Verbindung: { branch, files }
|
||||
|
||||
const reload = ()=>gitApi.listConnections().then((list)=>{ setConns(list); setState('ready'); })
|
||||
.catch((err)=>{
|
||||
const { state: next, notice: text } = classifyListError(err);
|
||||
if(next === 'error') { setFormError(err.message); setState('ready'); } else { setNotice(text ?? ''); setState(next); }
|
||||
});
|
||||
useEffect(()=>{ reload(); }, []);
|
||||
|
||||
if(state === 'notice') return (
|
||||
<div className='dataGroup gitConnections'>
|
||||
<h3>Git-Verbindungen <i className='fab fa-git-alt'></i></h3>
|
||||
<p className='notice'>{notice}</p>
|
||||
</div>
|
||||
);
|
||||
if(state !== 'ready') return null; // lädt oder nicht angemeldet
|
||||
|
||||
const set = (id, ok, text)=>setMsg((m)=>({ ...m, [id]: { ok, text } }));
|
||||
|
||||
const create = async (e)=>{
|
||||
e.preventDefault();
|
||||
setFormError('');
|
||||
try {
|
||||
await gitApi.createConnection(form);
|
||||
setForm(EMPTY);
|
||||
await reload();
|
||||
} catch (err) { setFormError(err.message); }
|
||||
};
|
||||
|
||||
const test = (c)=>gitApi.testConnection(c.id)
|
||||
.then((r)=>{ set(c.id, true, `Verbindung ok (Standard-Branch ${r.defaultBranch ?? '?'}, ${r.branchCount} Branches)`); reload(); })
|
||||
.catch((err)=>set(c.id, false, `${err.HBErrorCode ?? ''} ${err.message}`));
|
||||
|
||||
const remove = async (c)=>{
|
||||
if(!window.confirm(`Verbindung „${c.label}“ löschen? Verknüpfte Brews bleiben als normale Brews erhalten.`)) return;
|
||||
await gitApi.deleteConnection(c.id).catch((err)=>set(c.id, false, err.message));
|
||||
reload();
|
||||
};
|
||||
|
||||
const showFiles = (c)=>gitApi.listFiles(c.id, c.defaultBranch, c.brewDir)
|
||||
.then((r)=>setFiles((f)=>({ ...f, [c.id]: { branch: r.branch, files: r.files } })))
|
||||
.catch((err)=>set(c.id, false, `${err.HBErrorCode ?? ''} ${err.message}`));
|
||||
|
||||
const importFile = (c, branch, path)=>gitApi.importBrew({ connectionId: c.id, branch, path })
|
||||
.then((brew)=>{ window.location.href = `/edit/${brew.editId}`; })
|
||||
.catch((err)=>set(c.id, false, `${err.HBErrorCode ?? ''} ${err.message}`));
|
||||
|
||||
return (
|
||||
<div className='dataGroup gitConnections'>
|
||||
<h3>Git-Verbindungen <i className='fab fa-git-alt'></i></h3>
|
||||
<p>Brews in einem beliebigen Git-Repository speichern (HTTPS + Personal Access Token). Der Token wird verschlüsselt gespeichert und nie angezeigt.</p>
|
||||
{conns.map((c)=>(
|
||||
<div className='gitConn' key={c.id}>
|
||||
<div className='label'>{c.label}</div>
|
||||
<div className='url'>{c.repoUrl}</div>
|
||||
<div className='meta'>Standard-Branch {c.defaultBranch}, Ordner {c.brewDir || '/'}{c.lastVerifiedAt ? '' : ' · noch nicht getestet'}</div>
|
||||
<div className='actions'>
|
||||
<button onClick={()=>test(c)}>Testen</button>
|
||||
<button onClick={()=>showFiles(c)}>Brews aus Repo importieren</button>
|
||||
<button onClick={()=>remove(c)}>Löschen</button>
|
||||
</div>
|
||||
{msg[c.id] && <div className={msg[c.id].ok ? 'ok' : 'error'}>{msg[c.id].text}</div>}
|
||||
{files[c.id] && (
|
||||
<ul className='files'>
|
||||
{files[c.id].files.length === 0 && <li>Keine .md-Dateien in {c.brewDir || '/'} auf {files[c.id].branch}.</li>}
|
||||
{files[c.id].files.map((f)=>(
|
||||
<li key={f}>{f} <button onClick={()=>importFile(c, files[c.id].branch, f)}>Importieren</button></li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
<form onSubmit={create}>
|
||||
<strong>Neue Verbindung</strong>
|
||||
<input placeholder='Bezeichnung' value={form.label} required maxLength={80} onChange={(e)=>setForm({ ...form, label: e.target.value })} />
|
||||
<input placeholder='https://git.example.org/nutzer/repo.git' value={form.repoUrl} required onChange={(e)=>setForm({ ...form, repoUrl: e.target.value })} />
|
||||
<input placeholder='Benutzername (Standard: git)' value={form.authUsername} onChange={(e)=>setForm({ ...form, authUsername: e.target.value })} />
|
||||
<input type='password' autoComplete='off' placeholder='Personal Access Token' value={form.token} required onChange={(e)=>setForm({ ...form, token: e.target.value })} />
|
||||
<button type='submit'>Verbindung anlegen</button>
|
||||
{formError && <div className='error'>{formError}</div>}
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default GitConnectionsPanel;
|
||||
@@ -0,0 +1,81 @@
|
||||
import React, { useState } from 'react';
|
||||
import Nav from '@navbar/nav.jsx';
|
||||
import { gitApi, setGitOverwrite, SAVE_EVENT } from './gitApi.js';
|
||||
|
||||
// Fehlertexte und Konfliktdialog für G01–G10 (ADR 0003 §5, §7).
|
||||
const TEXTS = {
|
||||
G02 : 'Anmeldung am Git-Server fehlgeschlagen. Prüfe den Token der Verbindung (Account-Seite).',
|
||||
G03 : 'Repository, Branch oder Datei wurden nicht gefunden.',
|
||||
G04 : 'Der Git-Server ist nicht erreichbar oder zu langsam. Deine Änderungen sind noch nicht gespeichert, bitte später erneut speichern.',
|
||||
G05 : 'Speichern im Repository ist gerade nicht möglich (viele gleichzeitige Änderungen). Bitte gleich erneut speichern.',
|
||||
G06 : 'Die Datei existiert im Repository bereits.',
|
||||
G07 : 'Das Git-Backend steht nur Konten mit OIDC-Anmeldung zur Verfügung.',
|
||||
G08 : 'Ungültige Eingabe für Git.',
|
||||
G09 : 'Die Datei ist für das Git-Backend zu groß.',
|
||||
G10 : 'Das Git-Backend ist auf diesem Server nicht aktiviert.'
|
||||
};
|
||||
|
||||
const downloadOwnVersion = (brew)=>{
|
||||
const blob = new Blob([brew?.text ?? ''], { type: 'text/markdown' });
|
||||
const a = document.createElement('a');
|
||||
a.href = URL.createObjectURL(blob);
|
||||
a.download = `${(brew?.title || 'brew').replace(/[^\w-]+/g, '_')}-meine-version.md`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(a.href);
|
||||
};
|
||||
|
||||
const GitErrorNavItem = ({ error, clearError, brew })=>{
|
||||
const body = error.response?.body ?? {};
|
||||
const code = body.HBErrorCode;
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
if(code === 'G01' && body.operation === 'delete') {
|
||||
return <Nav.item className='save error' icon='fas fa-exclamation-triangle'>
|
||||
Konflikt
|
||||
<div className='errorContainer' onClick={clearError}>
|
||||
Die Datei wurde im Git-Repository geändert. Der Brew wurde nicht gelöscht. Prüfe die Änderung im Repository und lösche erneut.
|
||||
</div>
|
||||
</Nav.item>;
|
||||
}
|
||||
|
||||
if(code === 'G01') {
|
||||
const keepMine = ()=>{
|
||||
setGitOverwrite(body.remoteBlobSha ?? 'none');
|
||||
clearError();
|
||||
document.dispatchEvent(new CustomEvent(SAVE_EVENT));
|
||||
};
|
||||
const loadRemote = async ()=>{
|
||||
setBusy(true);
|
||||
try { await gitApi.pull(brew.editId); window.location.reload(); } catch { setBusy(false); }
|
||||
};
|
||||
return <Nav.item className='save error' icon='fas fa-exclamation-triangle'>
|
||||
Konflikt
|
||||
<div className='errorContainer'>
|
||||
Die Datei wurde im Git-Repository geändert{body.remoteCommitSha ? ` (${body.remoteCommitSha.slice(0, 7)})` : ''}.<br />
|
||||
<div className='confirm' onClick={busy ? undefined : keepMine}>Meine Version behalten</div>
|
||||
<div className='deny' onClick={busy ? undefined : ()=>downloadOwnVersion(brew)}>Meine Version sichern</div>
|
||||
<div className='deny' onClick={busy ? undefined : loadRemote}>Remote-Version laden</div>
|
||||
<div className='deny' onClick={clearError}>Abbrechen</div>
|
||||
</div>
|
||||
</Nav.item>;
|
||||
}
|
||||
|
||||
if(body.operation === 'delete') {
|
||||
const text = (code === 'G04' || code === 'G05')
|
||||
? 'Löschen im Repository ist gerade nicht möglich. Es wurde nichts gelöscht, bitte später erneut versuchen.'
|
||||
: `Löschen fehlgeschlagen, es wurde nichts gelöscht. ${TEXTS[code] ?? body.message ?? ''}`.trim();
|
||||
return <Nav.item className='save error' icon='fas fa-exclamation-triangle'>
|
||||
Oops!
|
||||
<div className='errorContainer' onClick={clearError}>{text}</div>
|
||||
</Nav.item>;
|
||||
}
|
||||
|
||||
return <Nav.item className='save error' icon='fas fa-exclamation-triangle'>
|
||||
Oops!
|
||||
<div className='errorContainer' onClick={clearError}>
|
||||
{TEXTS[code] ?? body.message ?? 'Git-Fehler.'}
|
||||
</div>
|
||||
</Nav.item>;
|
||||
};
|
||||
|
||||
export default GitErrorNavItem;
|
||||
@@ -0,0 +1,84 @@
|
||||
import './git.less';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import Moment from 'moment';
|
||||
import Nav from '@navbar/nav.jsx';
|
||||
import { gitApi } from './gitApi.js';
|
||||
|
||||
// Git-Status im Editor-Navbar (ADR 0003 §7): Branch, Pfad, kurzer SHA, Fehler; Pull; Verknüpfen/Lösen.
|
||||
const short = (sha)=>sha ? sha.slice(0, 7) : '';
|
||||
|
||||
const GitNavItem = ({ brew, lastSavedTime, onLinkedChange })=>{
|
||||
const editId = brew?.editId;
|
||||
const [status, setStatus] = useState(null); // null: unbekannt/aus
|
||||
const [conns, setConns] = useState(null);
|
||||
const [form, setForm] = useState({ connectionId: '', branch: '', path: '' });
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
const refresh = ()=>gitApi.status(editId).then(setStatus).catch(()=>setStatus(null));
|
||||
useEffect(()=>{ if(editId) refresh(); }, [editId, lastSavedTime]);
|
||||
|
||||
// Verbindungen nur laden, wenn verknüpft werden soll (403/503: Git nicht verfügbar → Item bleibt unsichtbar)
|
||||
useEffect(()=>{
|
||||
if(status && !status.linked && conns === null) {
|
||||
gitApi.listConnections().then((list)=>{ setConns(list); setForm((f)=>({ ...f, connectionId: list[0]?.id ?? '' })); }).catch(()=>setConns(false));
|
||||
}
|
||||
}, [status]);
|
||||
|
||||
useEffect(()=>{ onLinkedChange?.(!!status?.linked); window.dispatchEvent(new Event('hb:git-link-changed')); }, [status?.linked]); // zweiter Teil: ADR 0004 (Upload-Button)
|
||||
|
||||
if(!editId || !status) return null;
|
||||
|
||||
const run = async (fn)=>{
|
||||
setBusy(true); setError('');
|
||||
try { await fn(); await refresh(); } catch (err) { setError(`${err.HBErrorCode ?? ''} ${err.message}`.trim()); }
|
||||
setBusy(false);
|
||||
};
|
||||
|
||||
if(status.linked) {
|
||||
return (
|
||||
<Nav.dropdown className='gitNav'>
|
||||
<Nav.item icon={status.lastError ? 'fas fa-exclamation-triangle' : 'fab fa-git-alt'} className={status.lastError ? 'error' : ''}>
|
||||
{status.branch}
|
||||
</Nav.item>
|
||||
<div className='gitDropdown'>
|
||||
<div className='meta'>{status.connectionLabel}: {status.repoUrl}</div>
|
||||
<div className='meta'>{status.branch} · {status.path}{status.lastCommitSha ? ` · ${short(status.lastCommitSha)}` : ''}</div>
|
||||
{status.snapshotAt && <div className='meta' title='Stand, den Teilen-Links ausliefern'>Teilen-Stand: {Moment(status.snapshotAt).format('LLL')}</div>}
|
||||
{status.lastError === 'G04' && <div className='error'>Git nicht erreichbar, angezeigt wird der zuletzt gespeicherte Stand.</div>}
|
||||
{status.lastError && status.lastError !== 'G04' && <div className='error'>Letzter Fehler: {status.lastError}</div>}
|
||||
{error && <div className='error'>{error}</div>}
|
||||
<button disabled={busy} onClick={()=>run(async ()=>{
|
||||
if(!window.confirm('Remote-Stand laden? Ungespeicherte Änderungen im Editor gehen verloren.')) return;
|
||||
await gitApi.pull(editId);
|
||||
window.location.reload();
|
||||
})}>Pull</button>
|
||||
{status.isConnectionOwner && <button disabled={busy} onClick={()=>run(async ()=>{
|
||||
if(window.confirm('Verknüpfung lösen? Der Brew bleibt erhalten, die Datei im Repository auch.')) await gitApi.unlinkBrew(editId);
|
||||
})}>Verknüpfung lösen</button>}
|
||||
</div>
|
||||
</Nav.dropdown>
|
||||
);
|
||||
}
|
||||
|
||||
if(!conns || conns.length === 0) return null; // nichts zu verknüpfen (kein OIDC-Konto oder keine Verbindung)
|
||||
|
||||
return (
|
||||
<Nav.dropdown className='gitNav'>
|
||||
<Nav.item icon='fab fa-git-alt'>Git</Nav.item>
|
||||
<div className='gitDropdown'>
|
||||
<select value={form.connectionId} onChange={(e)=>setForm({ ...form, connectionId: e.target.value })}>
|
||||
{conns.map((c)=><option key={c.id} value={c.id}>{c.label}</option>)}
|
||||
</select>
|
||||
<input placeholder='Branch (Standard der Verbindung)' value={form.branch} onChange={(e)=>setForm({ ...form, branch: e.target.value })} />
|
||||
<input placeholder='Pfad, z. B. brews/mein-brew.md' value={form.path} onChange={(e)=>setForm({ ...form, path: e.target.value })} />
|
||||
{error && <div className='error'>{error}</div>}
|
||||
<button disabled={busy || !form.connectionId} onClick={()=>run(()=>gitApi.linkBrew(editId, { connectionId: form.connectionId, branch: form.branch || undefined, path: form.path || undefined }))}>
|
||||
In Git speichern
|
||||
</button>
|
||||
</div>
|
||||
</Nav.dropdown>
|
||||
);
|
||||
};
|
||||
|
||||
export default GitNavItem;
|
||||
@@ -0,0 +1,36 @@
|
||||
@import '@sharedStyles/core.less';
|
||||
|
||||
.gitConnections {
|
||||
.gitConn {
|
||||
padding : 8px 0;
|
||||
border-bottom : 1px solid #cccccc;
|
||||
.label { font-weight : 800; }
|
||||
.url, .meta { font-size : 0.9em; color : #555555; word-break : break-all; }
|
||||
.actions button { margin : 4px 6px 0 0; }
|
||||
}
|
||||
form {
|
||||
display : grid;
|
||||
gap : 6px;
|
||||
margin-top : 10px;
|
||||
input { padding : 4px; }
|
||||
}
|
||||
.error { color : @red; font-weight : 800; }
|
||||
.ok { color : @teal; font-weight : 800; }
|
||||
.notice { color : #555555; font-style : italic; }
|
||||
ul.files { list-style : none; padding : 0; li { margin : 2px 0; } }
|
||||
}
|
||||
|
||||
.gitNav {
|
||||
.gitDropdown {
|
||||
display : grid;
|
||||
gap : 6px;
|
||||
min-width : 260px;
|
||||
padding : 8px;
|
||||
font-size : 12px;
|
||||
color : white;
|
||||
background-color : #333333;
|
||||
input, select { padding : 3px; }
|
||||
.error { color : #ff9a9a; font-weight : 800; }
|
||||
.meta { opacity : 0.8; word-break : break-all; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import superagent from 'superagent';
|
||||
import request from '../../homebrew/utils/request-middleware.js';
|
||||
|
||||
const patch = (path)=>superagent.patch(path).set('Homebrewery-Version', global.version);
|
||||
|
||||
// Dünne Hülle um /api/git/* (ADR 0003 §7). Fehler tragen `HBErrorCode` und `message` des Servers.
|
||||
const unwrap = (promise)=>promise.then((res)=>res.body).catch((err)=>{
|
||||
const body = err.response?.body ?? {};
|
||||
const e = new Error(body.message || err.message);
|
||||
e.status = err.response?.status;
|
||||
e.HBErrorCode = body.HBErrorCode;
|
||||
e.body = body;
|
||||
throw e;
|
||||
});
|
||||
|
||||
export const gitApi = {
|
||||
listConnections : ()=>unwrap(request.get('/api/git/connections')),
|
||||
createConnection : (data)=>unwrap(request.post('/api/git/connections').send(data)),
|
||||
updateConnection : (id, data)=>unwrap(patch(`/api/git/connections/${id}`).send(data)),
|
||||
deleteConnection : (id)=>unwrap(request.delete(`/api/git/connections/${id}`)),
|
||||
testConnection : (id)=>unwrap(request.post(`/api/git/connections/${id}/test`)),
|
||||
listBranches : (id)=>unwrap(request.get(`/api/git/connections/${id}/branches`)),
|
||||
listFiles : (id, branch, dir)=>unwrap(request.get(`/api/git/connections/${id}/files`).query({ branch, dir })),
|
||||
importBrew : (data)=>unwrap(request.post('/api/git/brews/import').send(data)),
|
||||
linkBrew : (editId, data)=>unwrap(request.post(`/api/git/brews/${editId}/link`).send(data)),
|
||||
unlinkBrew : (editId)=>unwrap(request.delete(`/api/git/brews/${editId}/link`)),
|
||||
status : (editId)=>unwrap(request.get(`/api/git/brews/${editId}`)),
|
||||
pull : (editId)=>unwrap(request.post(`/api/git/brews/${editId}/pull`))
|
||||
};
|
||||
|
||||
// "Meine Version behalten" (Konfliktdialog G01): der nächste Save hängt ?gitOverwrite=<blob> an.
|
||||
let overwriteBlob = null;
|
||||
export const setGitOverwrite = (blob)=>{ overwriteBlob = blob; };
|
||||
export const consumeGitOverwrite = ()=>{ const b = overwriteBlob; overwriteBlob = null; return b; };
|
||||
export const SAVE_EVENT = 'hb:git-save';
|
||||
@@ -0,0 +1,18 @@
|
||||
// Zustand des Git-Panels auf der Account-Seite (FLW-258): aus dem Fehler von GET /api/git/connections
|
||||
// wird entschieden, ob das Panel einen Hinweis zeigt, normal arbeitet oder unsichtbar bleibt.
|
||||
export const NOTICES = {
|
||||
disabled : 'Git-Backend auf diesem Server nicht aktiviert – siehe docs/git (Abschnitt „Fehlersuche / nachträglich aktivieren“).',
|
||||
noOidc : 'Nur mit OIDC-Anmeldung verfügbar.'
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {{ status?: number, HBErrorCode?: string }} err Fehler aus gitApi.listConnections()
|
||||
* @returns {{ state: 'notice'|'hidden'|'error', notice?: string }}
|
||||
* notice = Hinweis anzeigen, hidden = nichts anzeigen (nicht angemeldet), error = Panel mit Fehlermeldung
|
||||
*/
|
||||
export const classifyListError = (err)=>{
|
||||
if(err?.status === 503 && (!err.HBErrorCode || err.HBErrorCode === 'G10')) return { state: 'notice', notice: NOTICES.disabled };
|
||||
if(err?.status === 403 && (!err.HBErrorCode || err.HBErrorCode === 'G07')) return { state: 'notice', notice: NOTICES.noOidc };
|
||||
if(err?.status === 401) return { state: 'hidden' };
|
||||
return { state: 'error' };
|
||||
};
|
||||
@@ -6,12 +6,12 @@ import React, { useState, useRef, useMemo, useEffect } from 'react';
|
||||
import _ from 'lodash';
|
||||
|
||||
import MarkdownLegacy from '@shared/markdownLegacy.js';
|
||||
import Markdown from '@shared/markdown.js';
|
||||
import { hbfm } from 'marked-hbfm';
|
||||
import ErrorBar from './errorBar/errorBar.jsx';
|
||||
import ToolBar from './toolBar/toolBar.jsx';
|
||||
|
||||
//TODO: move to the brew renderer
|
||||
import RenderWarnings from '../../components/renderWarnings/renderWarnings.jsx';
|
||||
import RenderWarnings from '@components/renderWarnings/renderWarnings.jsx';
|
||||
import NotificationPopup from './notificationPopup/notificationPopup.jsx';
|
||||
import Frame from 'react-frame-component';
|
||||
import dedent from 'dedent';
|
||||
@@ -23,13 +23,12 @@ import safeHTML from './safeHTML.js';
|
||||
const PAGEBREAK_REGEX_V3 = /^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m;
|
||||
const PAGEBREAK_REGEX_LEGACY = /\\page(?:break)?/m;
|
||||
const COLUMNBREAK_REGEX_LEGACY = /\\column(:?break)?/m;
|
||||
const PAGE_HEIGHT = 1056;
|
||||
|
||||
const TOOLBAR_STATE_KEY = 'HB_renderer_toolbarState';
|
||||
|
||||
const INITIAL_CONTENT = dedent`
|
||||
<!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="${brewRendererStylesUrl}" rel="stylesheet" />
|
||||
<link href="${headerNavStylesUrl}" rel="stylesheet" />
|
||||
@@ -46,31 +45,25 @@ const BrewPage = (props)=>{
|
||||
};
|
||||
const pageRef = useRef(null);
|
||||
const cleanText = safeHTML(props.contents);
|
||||
const pageNum = props.index + 1;
|
||||
|
||||
useEffect(()=>{
|
||||
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(
|
||||
(entries)=>{
|
||||
entries.forEach((entry)=>{
|
||||
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);
|
||||
});
|
||||
},
|
||||
(entries)=>entries.forEach((entry)=>{
|
||||
props.onVisibilityChange(pageNum, entry.isIntersecting, false); // add/remove page from array of visible pages.
|
||||
}),
|
||||
{ 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.
|
||||
const centerObserver = new IntersectionObserver(
|
||||
(entries)=>{
|
||||
entries.forEach((entry)=>{
|
||||
if(entry.isIntersecting)
|
||||
props.onVisibilityChange(props.index + 1, true, true); // Set this page as the center page
|
||||
});
|
||||
},
|
||||
(entries)=>entries.forEach((entry)=>{
|
||||
if(entry.isIntersecting)
|
||||
props.onVisibilityChange(pageNum, true, true); // Set this page as the center page
|
||||
}),
|
||||
{ threshold: 0, rootMargin: '-50% 0px -50% 0px' } // Detect when the page is at the center
|
||||
);
|
||||
|
||||
@@ -91,6 +84,7 @@ const BrewPage = (props)=>{
|
||||
|
||||
//v=====--------------------< Brew Renderer Component >-------------------=====v//
|
||||
let renderedPages = [];
|
||||
const pageTemplates = [];
|
||||
let rawPages = [];
|
||||
|
||||
const BrewRenderer = (props)=>{
|
||||
@@ -98,22 +92,23 @@ const BrewRenderer = (props)=>{
|
||||
text : '',
|
||||
style : '',
|
||||
renderer : 'legacy',
|
||||
theme : '5ePHB',
|
||||
lang : '',
|
||||
errors : [],
|
||||
currentEditorCursorPageNum : 1,
|
||||
currentEditorViewPageNum : 1,
|
||||
currentBrewRendererPageNum : 1,
|
||||
themeBundle : {},
|
||||
onPageChange : ()=>{},
|
||||
...props
|
||||
};
|
||||
|
||||
const pagesRef = useRef(null);
|
||||
|
||||
const [visiblePages, setVisiblePages] = useState([]);
|
||||
const [centerPage, setCenterPage] = useState(1);
|
||||
const [headerState, setHeaderState] = useState(false);
|
||||
|
||||
const [state, setState] = useState({
|
||||
isMounted : false,
|
||||
visibility : 'hidden',
|
||||
visiblePages : [],
|
||||
centerPage : 1
|
||||
isMounted : false,
|
||||
visibility : 'hidden'
|
||||
});
|
||||
|
||||
const [displayOptions, setDisplayOptions] = useState({
|
||||
@@ -131,11 +126,6 @@ const BrewRenderer = (props)=>{
|
||||
toolbarState && setDisplayOptions(toolbarState);
|
||||
}, []);
|
||||
|
||||
const [headerState, setHeaderState] = useState(false);
|
||||
|
||||
const mainRef = useRef(null);
|
||||
const pagesRef = useRef(null);
|
||||
|
||||
if(props.renderer == 'legacy') {
|
||||
rawPages = props.text.split(PAGEBREAK_REGEX_LEGACY);
|
||||
} else {
|
||||
@@ -143,20 +133,16 @@ const BrewRenderer = (props)=>{
|
||||
}
|
||||
|
||||
const handlePageVisibilityChange = (pageNum, isVisible, isCenter)=>{
|
||||
setState((prevState)=>{
|
||||
const updatedVisiblePages = new Set(prevState.visiblePages);
|
||||
if(!isCenter)
|
||||
isVisible ? updatedVisiblePages.add(pageNum) : updatedVisiblePages.delete(pageNum);
|
||||
|
||||
return {
|
||||
...prevState,
|
||||
visiblePages : [...updatedVisiblePages].sort((a, b)=>a - b),
|
||||
centerPage : isCenter ? pageNum : prevState.centerPage
|
||||
};
|
||||
setVisiblePages((prev)=>{
|
||||
const updatedVisiblePages = new Set(prev);
|
||||
isVisible ? updatedVisiblePages.add(pageNum) : updatedVisiblePages.delete(pageNum);
|
||||
return [...updatedVisiblePages].sort((a, b)=>a - b);
|
||||
});
|
||||
|
||||
if(isCenter)
|
||||
if(isCenter) {
|
||||
setCenterPage(pageNum);
|
||||
props.onPageChange(pageNum);
|
||||
}
|
||||
};
|
||||
|
||||
const isInView = (index)=>{
|
||||
@@ -166,17 +152,15 @@ const BrewRenderer = (props)=>{
|
||||
if(index == props.currentEditorCursorPageNum - 1) //Already rendered before this step
|
||||
return false;
|
||||
|
||||
if(Math.abs(index - props.currentBrewRendererPageNum - 1) <= 3)
|
||||
if(Math.abs(index - centerPage - 1) <= 3)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
const renderDummyPage = (index)=>{
|
||||
return <div className='phb page' id={`p${index + 1}`} key={index}>
|
||||
<i className='fas fa-spinner fa-spin' />
|
||||
</div>;
|
||||
};
|
||||
const renderDummyPage = (index)=><div className='phb page' id={`p${index + 1}`} key={index}>
|
||||
<i className='fas fa-spinner fa-spin' />
|
||||
</div>;
|
||||
|
||||
const renderStyle = ()=>{
|
||||
const themeStyles = props.themeBundle?.joinedStyles ?? '<style>@import url("/themes/V3/Blank/style.css");</style>';
|
||||
@@ -200,13 +184,27 @@ const BrewRenderer = (props)=>{
|
||||
return <BrewPage className='page phb' index={index} key={index} contents={html} style={styles} onVisibilityChange={handlePageVisibilityChange} />;
|
||||
} else {
|
||||
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;
|
||||
if(injectedTags) {
|
||||
styles = { ...styles, ...injectedTags.styles };
|
||||
styles = _.mapKeys(styles, (v, k)=>k.startsWith('--') ? k : _.camelCase(k)); // Convert CSS to camelCase for React
|
||||
classes = [classes, injectedTags.classes].join(' ').trim();
|
||||
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
|
||||
}
|
||||
@@ -214,18 +212,20 @@ const BrewRenderer = (props)=>{
|
||||
// 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)
|
||||
|
||||
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} />;
|
||||
}
|
||||
};
|
||||
|
||||
const renderPages = ()=>{
|
||||
if(props.errors && props.errors.length)
|
||||
if(props.errors?.length)
|
||||
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;
|
||||
pageTemplates.length = 0;
|
||||
}
|
||||
|
||||
// Render currently-edited page first so cross-page effects (variables, links) can propagate out first
|
||||
if(rawPages.length > props.currentEditorCursorPageNum -1)
|
||||
@@ -272,14 +272,9 @@ const BrewRenderer = (props)=>{
|
||||
const frameDidMount = ()=>{ //This triggers when iFrame finishes internal "componentDidMount"
|
||||
scrollToHash(window.location.hash);
|
||||
|
||||
navigation.addEventListener('navigate', (e)=>{
|
||||
if(e.hashChange && e.destination.sameDocument){
|
||||
const dest = e.destination.url.slice(e.destination.url.indexOf('#'));
|
||||
scrollToHash(dest);
|
||||
}
|
||||
});
|
||||
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
|
||||
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
|
||||
setState((prevState)=>({
|
||||
...prevState,
|
||||
@@ -306,7 +301,7 @@ const BrewRenderer = (props)=>{
|
||||
};
|
||||
|
||||
const renderedStyle = useMemo(()=>renderStyle(), [props.style, props.themeBundle]);
|
||||
renderedPages = useMemo(()=>renderPages(), [props.text, displayOptions]);
|
||||
renderedPages = useMemo(()=>renderPages(), [props.text, centerPage, displayOptions]);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -320,18 +315,19 @@ const BrewRenderer = (props)=>{
|
||||
: null}
|
||||
|
||||
<ErrorBar errors={props.errors} />
|
||||
<div className='popups' ref={mainRef}>
|
||||
<div className='popups'>
|
||||
<RenderWarnings />
|
||||
<NotificationPopup />
|
||||
</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.*/}
|
||||
<Frame id='BrewRenderer' initialContent={INITIAL_CONTENT}
|
||||
<Frame id='BrewRenderer' title='Rendered Brew Content' initialContent={INITIAL_CONTENT}
|
||||
style={{ width: '100%', height: '100%', visibility: state.visibility }}
|
||||
contentDidMount={frameDidMount}
|
||||
onClick={()=>{emitClick();}}
|
||||
onClick={emitClick}
|
||||
sandbox='allow-same-origin allow-modals allow-top-navigation'
|
||||
>
|
||||
<div className='brewRenderer'
|
||||
onKeyDown={handleControlKeys}
|
||||
|
||||
@@ -61,9 +61,7 @@
|
||||
}
|
||||
|
||||
@supports (break-after:always) {
|
||||
.columnSplit {
|
||||
margin-bottom: 100vh;
|
||||
}
|
||||
.columnSplit { margin-bottom : 100vh; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,13 +74,11 @@
|
||||
height : 100%;
|
||||
padding : unset;
|
||||
overflow-y : unset;
|
||||
&:has(.facing, .flow) {
|
||||
padding : unset;
|
||||
}
|
||||
&:has(.facing, .flow) { padding : unset; }
|
||||
.pages {
|
||||
display : block;
|
||||
margin : 0px;
|
||||
zoom : 100% !important;
|
||||
display : block;
|
||||
& > .page { box-shadow : unset; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import './errorBar.less';
|
||||
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' />;
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import './notificationPopup.less';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import request from '../../utils/request-middleware.js';
|
||||
import Markdown from '@shared/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' />;
|
||||
|
||||
@@ -44,7 +44,7 @@ const NotificationPopup = ()=>{
|
||||
return notifications.map((notification)=>(
|
||||
<li key={notification.dismissKey} >
|
||||
<em>{notification.title}</em><br />
|
||||
<p dangerouslySetInnerHTML={{ __html: Markdown.render(notification.text) }}></p>
|
||||
<p dangerouslySetInnerHTML={{ __html: hbfm.render(notification.text) }}></p>
|
||||
</li>
|
||||
));
|
||||
};
|
||||
|
||||
@@ -32,12 +32,12 @@ function safeHTML(htmlString) {
|
||||
return;
|
||||
}
|
||||
// Check remaining elements for blacklisted attributes
|
||||
for (const attribute of element.attributes){
|
||||
[...element.attributes].forEach((attribute)=>{
|
||||
if(blacklistAttrs.some((test)=>{return test(attribute);})) {
|
||||
element.removeAttribute(attribute.localName);
|
||||
break;
|
||||
element.removeAttribute(attribute.name);
|
||||
return;
|
||||
};
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
return div.innerHTML;
|
||||
|
||||
@@ -3,7 +3,7 @@ import './toolBar.less';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import _ from 'lodash';
|
||||
|
||||
import { Anchored, AnchoredBox, AnchoredTrigger } from '../../../components/Anchored.jsx';
|
||||
import { Anchored, AnchoredBox, AnchoredTrigger } from '@components/Anchored.jsx';
|
||||
|
||||
const MAX_ZOOM = 300;
|
||||
const MIN_ZOOM = 10;
|
||||
@@ -99,11 +99,16 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
||||
return (
|
||||
<div id='preview-toolbar' className={`toolBar ${toolsVisible ? 'visible' : 'hidden'}`} role='toolbar'>
|
||||
<div className='toggleButton'>
|
||||
<button data-tooltip-right={`${toolsVisible ? 'Hide' : 'Show'} Preview Toolbar`} onClick={()=>{
|
||||
setToolsVisible(!toolsVisible);
|
||||
localStorage.setItem(TOOLBAR_VISIBILITY, !toolsVisible);
|
||||
}}><i className='fas fa-glasses' /></button>
|
||||
<button data-tooltip-right={`${headerState ? 'Hide' : 'Show'} Header Navigation`} onClick={()=>{setHeaderState(!headerState);}}><i className='fas fa-rectangle-list' /></button>
|
||||
<button data-tooltip-right={`${toolsVisible ? 'Hide' : 'Show'} Preview Toolbar`}
|
||||
aria-label={`${toolsVisible ? 'Hide' : 'Show'} Preview Toolbar`}
|
||||
onClick={()=>{ setToolsVisible(!toolsVisible); localStorage.setItem(TOOLBAR_VISIBILITY, !toolsVisible); }}>
|
||||
<i aria-hidden='true' className='fas fa-glasses' />
|
||||
</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>
|
||||
{/*v=====----------------------< Zoom Controls >---------------------=====v*/}
|
||||
<div className='group' role='group' aria-label='Zoom' aria-hidden={!toolsVisible}>
|
||||
@@ -111,17 +116,19 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
||||
id='fill-width'
|
||||
className='tool'
|
||||
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'))}
|
||||
>
|
||||
<i className='fac fit-width' />
|
||||
<i aria-hidden='true' className='fac fit-width' />
|
||||
</button>
|
||||
<button
|
||||
id='zoom-to-fit'
|
||||
className='tool'
|
||||
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'))}
|
||||
>
|
||||
<i className='fac zoom-to-fit' />
|
||||
<i aria-hidden='true' className='fac zoom-to-fit' />
|
||||
</button>
|
||||
<button
|
||||
id='zoom-out'
|
||||
@@ -129,8 +136,9 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
||||
onClick={()=>handleZoomButton(displayOptions.zoomLevel - 20)}
|
||||
disabled={displayOptions.zoomLevel <= MIN_ZOOM}
|
||||
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>
|
||||
<input
|
||||
id='zoom-slider'
|
||||
@@ -138,6 +146,7 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
||||
type='range'
|
||||
name='zoom'
|
||||
list='zoomLevels'
|
||||
aria-label='Zoom Amount'
|
||||
min={MIN_ZOOM}
|
||||
max={MAX_ZOOM}
|
||||
step='1'
|
||||
@@ -154,8 +163,9 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
||||
onClick={()=>handleZoomButton(displayOptions.zoomLevel + 20)}
|
||||
disabled={displayOptions.zoomLevel >= MAX_ZOOM}
|
||||
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>
|
||||
</div>
|
||||
|
||||
@@ -166,27 +176,32 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
||||
id='single-spread'
|
||||
className='tool'
|
||||
data-tooltip-bottom='Single Page'
|
||||
aria-label='Single Page Spread'
|
||||
onClick={()=>{handleOptionChange('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'
|
||||
id='facing-spread'
|
||||
className='tool'
|
||||
data-tooltip-bottom='Facing Pages'
|
||||
aria-label='Facing Pages Spread'
|
||||
onClick={()=>{handleOptionChange('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'
|
||||
id='flow-spread'
|
||||
className='tool'
|
||||
data-tooltip-bottom='Flow Pages'
|
||||
aria-label='Flow Pages Spread'
|
||||
onClick={()=>{handleOptionChange('spread', 'flow');}}
|
||||
aria-checked={displayOptions.spread === 'flow'}
|
||||
><i className='fac flow-spread' /></button>
|
||||
><i aria-hidden='true' className='fac flow-spread' /></button>
|
||||
|
||||
</div>
|
||||
<Anchored>
|
||||
<AnchoredTrigger id='spread-settings' className='tool' data-tooltip-bottom='Spread options'><i className='fas fa-gear' /></AnchoredTrigger>
|
||||
<AnchoredTrigger id='spread-settings' className='tool' aria-label='Spread options' data-tooltip-bottom='Spread options'>
|
||||
<i aria-hidden='true' className='fas fa-gear' />
|
||||
</AnchoredTrigger>
|
||||
<AnchoredBox>
|
||||
<h1>Options</h1>
|
||||
<label data-tooltip-left='Modify the horizontal space between pages.'>
|
||||
@@ -217,10 +232,11 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
||||
className='previousPage tool'
|
||||
type='button'
|
||||
data-tooltip-bottom='Previous Page(s)'
|
||||
aria-label='Previous Page'
|
||||
onClick={()=>scrollToPage(_.min(visiblePages) - visiblePages.length)}
|
||||
disabled={visiblePages.includes(1)}
|
||||
>
|
||||
<i className='fas fa-arrow-left'></i>
|
||||
<i aria-hidden='true' className='fas fa-arrow-left'></i>
|
||||
</button>
|
||||
|
||||
<div className='tool'>
|
||||
@@ -230,6 +246,7 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
||||
type='text'
|
||||
name='page'
|
||||
data-tooltip-bottom='Current page(s) in view'
|
||||
aria-label='Current page in view'
|
||||
inputMode='numeric'
|
||||
pattern='[0-9]'
|
||||
value={pageNum}
|
||||
@@ -239,7 +256,7 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
||||
onKeyDown={(e)=>e.key == 'Enter' && scrollToPage(pageNum)}
|
||||
style={{ width: `${pageNum.length}ch` }}
|
||||
/>
|
||||
<span id='page-count' data-tooltip-bottom='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>
|
||||
|
||||
<button
|
||||
@@ -247,10 +264,11 @@ const ToolBar = ({ displayOptions, onDisplayOptionsChange, visiblePages, totalPa
|
||||
className='tool'
|
||||
type='button'
|
||||
data-tooltip-bottom='Next Page(s)'
|
||||
aria-label='Next Page'
|
||||
onClick={()=>scrollToPage(_.max(visiblePages) + 1)}
|
||||
disabled={visiblePages.includes(totalPages)}
|
||||
>
|
||||
<i className='fas fa-arrow-right'></i>
|
||||
<i aria-hidden='true' className='fas fa-arrow-right'></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@import (less) './client/icons/customIcons.less';
|
||||
@import (less) '../../../icons/customIcons.less';
|
||||
|
||||
.toolBar {
|
||||
position : absolute;
|
||||
@@ -176,9 +176,7 @@
|
||||
transition : all 0.2s ease;
|
||||
}
|
||||
|
||||
.toggleButton button i {
|
||||
filter: drop-shadow(0 0 2px black) drop-shadow(0 0 1px black);
|
||||
}
|
||||
.toggleButton button i { filter : drop-shadow(0 0 2px black) drop-shadow(0 0 1px black); }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+335
-505
@@ -1,19 +1,44 @@
|
||||
/*eslint max-lines: ["warn", {"max": 500, "skipBlankLines": true, "skipComments": true}]*/
|
||||
import './editor.less';
|
||||
import React from 'react';
|
||||
import createReactClass from 'create-react-class';
|
||||
import _ from 'lodash';
|
||||
import React, { useState, useRef, useEffect, forwardRef, useImperativeHandle } from 'react';
|
||||
import dedent from 'dedent';
|
||||
import Markdown from '@shared/markdown.js';
|
||||
import { EditorView } from '@codemirror/view';
|
||||
|
||||
import CodeEditor from '../../components/codeEditor/codeEditor.jsx';
|
||||
import CodeEditor from '@components/codeEditor/codeEditor.jsx';
|
||||
import SnippetBar from './snippetbar/snippetbar.jsx';
|
||||
import MetadataEditor from './metadataEditor/metadataEditor.jsx';
|
||||
import SettingsEditor from './settingsEditor/settingsEditor.jsx';
|
||||
import { useAssetUpload } from '../../fork/assets/useAssetUpload.js'; // [fork] ADR-0004
|
||||
|
||||
const EDITOR_THEME_KEY = 'HB_editor_theme';
|
||||
const EDITOR_SETTINGS_KEY = 'HB_edit_settings';
|
||||
|
||||
const PAGEBREAK_REGEX_V3 = /^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m;
|
||||
const SNIPPETBREAK_REGEX_V3 = /^\\snippet\ .*$/;
|
||||
import defaultCM5Theme from '@themes/codeMirror/default.js';
|
||||
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`
|
||||
/*=======--- Example CSS styling ---=======*/
|
||||
/* Any CSS here will apply to your document! */
|
||||
@@ -30,544 +55,349 @@ 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.
|
||||
`;
|
||||
let isJumping = false;
|
||||
let jumpSource = null;
|
||||
|
||||
const Editor = createReactClass({
|
||||
displayName : 'Editor',
|
||||
getDefaultProps : function() {
|
||||
return {
|
||||
brew : {
|
||||
text : '',
|
||||
style : ''
|
||||
},
|
||||
const Editor = forwardRef(
|
||||
(
|
||||
{
|
||||
brew = {},
|
||||
|
||||
onBrewChange : ()=>{},
|
||||
reportError : ()=>{},
|
||||
onBrewChange = ()=>{},
|
||||
reportError = ()=>{},
|
||||
|
||||
onCursorPageChange : ()=>{},
|
||||
onViewPageChange : ()=>{},
|
||||
onCursorPageChange = ()=>{},
|
||||
onViewPageChange = ()=>{},
|
||||
|
||||
editorTheme : 'default',
|
||||
renderer : 'legacy',
|
||||
renderer = 'legacy',
|
||||
|
||||
currentEditorCursorPageNum : 1,
|
||||
currentEditorViewPageNum : 1,
|
||||
currentBrewRendererPageNum : 1,
|
||||
};
|
||||
},
|
||||
getInitialState : function() {
|
||||
return {
|
||||
editorTheme : this.props.editorTheme,
|
||||
view : 'text', //'text', 'style', 'meta', 'snippet'
|
||||
snippetBarHeight : 26,
|
||||
};
|
||||
},
|
||||
moveBrew,
|
||||
moveSource,
|
||||
liveScroll,
|
||||
|
||||
editor : React.createRef(null),
|
||||
codeEditor : React.createRef(null),
|
||||
setMoveArrows,
|
||||
updateBrew,
|
||||
showEditButtons,
|
||||
themeBundle,
|
||||
userThemes,
|
||||
|
||||
isText : function() {return this.state.view == 'text';},
|
||||
isStyle : function() {return this.state.view == 'style';},
|
||||
isMeta : function() {return this.state.view == 'meta';},
|
||||
isSnip : function() {return this.state.view == 'snippet';},
|
||||
|
||||
componentDidMount : function() {
|
||||
|
||||
this.highlightCustomMarkdown();
|
||||
document.getElementById('BrewRenderer').addEventListener('keydown', this.handleControlKeys);
|
||||
document.addEventListener('keydown', this.handleControlKeys);
|
||||
|
||||
const editorTheme = window.localStorage.getItem(EDITOR_THEME_KEY);
|
||||
if(editorTheme) {
|
||||
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 });
|
||||
currentEditorCursorPageNum = 1,
|
||||
currentEditorViewPageNum = 1,
|
||||
currentBrewRendererPageNum = 1,
|
||||
},
|
||||
ref,
|
||||
)=>{
|
||||
const [view, setView] = useState('text'); // 'text', 'style', 'meta', 'snippet'
|
||||
const [snippetBarHeight, setSnippetBarHeight] = useState(26);
|
||||
const [isDark, setIsDark] = useState(false);
|
||||
const [editorSettings, setEditorSettings] = useState({
|
||||
autoCloseBrackets : true,
|
||||
showImagePreviews : true,
|
||||
activeLineShading : true,
|
||||
lineNumbers : true,
|
||||
fontSize : 1,
|
||||
editorTheme : 'default',
|
||||
});
|
||||
|
||||
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();
|
||||
if(prevProps.moveBrew !== this.props.moveBrew)
|
||||
this.brewJump();
|
||||
const isView = (name)=>view === name;
|
||||
|
||||
if(prevProps.moveSource !== this.props.moveSource)
|
||||
this.sourceJump();
|
||||
useEffect(()=>{
|
||||
const brewRenderer = document.getElementById('BrewRenderer');
|
||||
brewRenderer.onload = ()=>brewRenderer.contentDocument?.addEventListener('keydown', handleControlKeys);
|
||||
document.addEventListener('keydown', handleControlKeys);
|
||||
|
||||
if(this.props.liveScroll) {
|
||||
if(prevProps.currentBrewRendererPageNum !== this.props.currentBrewRendererPageNum) {
|
||||
this.sourceJump(this.props.currentBrewRendererPageNum, false);
|
||||
} else if(prevProps.currentEditorViewPageNum !== this.props.currentEditorViewPageNum) {
|
||||
this.brewJump(this.props.currentEditorViewPageNum, false);
|
||||
} else if(prevProps.currentEditorCursorPageNum !== this.props.currentEditorCursorPageNum) {
|
||||
this.brewJump(this.props.currentEditorCursorPageNum, false);
|
||||
}
|
||||
}
|
||||
},
|
||||
const localEditorTheme = window.localStorage.getItem(EDITOR_THEME_KEY);
|
||||
if(localEditorTheme && EditorThemes.includes(localEditorTheme)) {
|
||||
setEditorSettings({ ...editorSettings, editorTheme: localEditorTheme });
|
||||
} else setEditorSettings({ ...editorSettings, editorTheme: 'default' });
|
||||
const localEditorSettings = window.localStorage.getItem(EDITOR_SETTINGS_KEY);
|
||||
if(localEditorSettings) setEditorSettings(JSON.parse(localEditorSettings));
|
||||
const snippetBar = document.querySelector('.editor > .snippetBar');
|
||||
if(!snippetBar) return;
|
||||
|
||||
componentWillUnmount() {
|
||||
if(this.resizeObserver) this.resizeObserver.disconnect();
|
||||
},
|
||||
|
||||
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?.codeMirror) 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
const resizeObserver = new ResizeObserver((entries)=>{
|
||||
const height = document.querySelector('.editor > .snippetBar').offsetHeight;
|
||||
setSnippetBarHeight(height);
|
||||
});
|
||||
}
|
||||
},
|
||||
resizeObserver.observe(snippetBar);
|
||||
|
||||
brewJump : function(targetPage=this.props.currentEditorCursorPageNum, smooth=true){
|
||||
if(!window || !this.isText() || isJumping)
|
||||
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 });
|
||||
return ()=>{
|
||||
if(resizeObserver) resizeObserver.disconnect();
|
||||
};
|
||||
this.throttleBrewMove(currentPos, bouncePos, targetPos);
|
||||
} else {
|
||||
brewRenderer.scrollTo({ top: currentPos + targetPos, behavior: 'instant', block: 'start' });
|
||||
}
|
||||
},
|
||||
}, []);
|
||||
|
||||
sourceJump : function(targetPage=this.props.currentBrewRendererPageNum, smooth=true){
|
||||
if(!this.isText() || isJumping)
|
||||
return;
|
||||
useEffect(()=>{ if(moveBrew) brewJump(); }, [moveBrew]);
|
||||
useEffect(()=>{ if(moveSource) sourceJump(); }, [moveSource]);
|
||||
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 textString = this.props.brew.text.split(textSplit).slice(0, targetPage-1).join(textSplit);
|
||||
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
|
||||
const handleFormatCode = ()=>{
|
||||
codeEditor.current?.formatCode();
|
||||
};
|
||||
|
||||
isJumping = true;
|
||||
checkIfScrollComplete();
|
||||
if(this.codeEditor.current?.codeMirror) {
|
||||
this.codeEditor.current.codeMirror?.on('scroll', checkIfScrollComplete);
|
||||
}
|
||||
const handleControlKeys = (e)=>{
|
||||
if(!(e.ctrlKey && e.metaKey && e.shiftKey)) return;
|
||||
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) {
|
||||
//Scroll 1/10 of the way every 10ms until 1px off.
|
||||
const incrementalScroll = setInterval(()=>{
|
||||
currentY += (targetY - currentY) / 10;
|
||||
this.codeEditor.current.codeMirror?.scrollTo(null, currentY);
|
||||
const updateCurrentCursorPage = (pageNumber)=>{
|
||||
onCursorPageChange(pageNumber);
|
||||
};
|
||||
|
||||
// Update target: target height is not accurate until within +-10 lines of the visible window
|
||||
if(Math.abs(targetY - currentY > 100))
|
||||
targetY = this.codeEditor.current.codeMirror?.heightAtLine(targetLine, 'local', true);
|
||||
const updateCurrentViewPage = (pageNumber)=>{
|
||||
onViewPageChange(pageNumber);
|
||||
};
|
||||
|
||||
// End when close enough
|
||||
if(Math.abs(targetY - currentY) < 1) {
|
||||
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');
|
||||
clearInterval(incrementalScroll);
|
||||
const handleInject = (injectText)=>{
|
||||
codeEditor.current?.injectText(injectText);
|
||||
};
|
||||
const assetUpload = useAssetUpload({ editId: brew.editId, containerRef: editor, inject: handleInject, active: view === 'text' }); // [fork] ADR-0004
|
||||
|
||||
const handleViewChange = (newView)=>{
|
||||
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 {
|
||||
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
|
||||
update : function(){},
|
||||
|
||||
updateEditorTheme : function(newTheme){
|
||||
window.localStorage.setItem(EDITOR_THEME_KEY, newTheme);
|
||||
this.setState({
|
||||
editorTheme : newTheme
|
||||
});
|
||||
},
|
||||
|
||||
//Called by CodeEditor after document switch, so Snippetbar can refresh UndoHistory
|
||||
rerenderParent : function (){
|
||||
this.forceUpdate();
|
||||
},
|
||||
|
||||
//temporary fix until cm6 comes next update
|
||||
attachCodeMirrorListeners : function(cm) {
|
||||
if(!cm) return;
|
||||
// detach previous (important on remount / view switch)
|
||||
if(this._cm) {
|
||||
this._cm.off('cursorActivity', this._onCursor);
|
||||
this._cm.off('scroll', this._onScroll);
|
||||
}
|
||||
|
||||
this._cm = cm;
|
||||
|
||||
this._onCursor = ()=>{
|
||||
this.updateCurrentCursorPage(cm.getCursor());
|
||||
} else {
|
||||
brewRenderer.scrollTo({ top : currentPos + targetPos, behavior : 'instant', block : 'start',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this._onScroll = _.throttle(()=>{
|
||||
const topLine = cm.lineAtHeight(cm.getScrollInfo().top, 'local');
|
||||
this.updateCurrentViewPage(topLine);
|
||||
}, 200);
|
||||
const sourceJump = (targetPage = currentBrewRendererPageNum, smooth = true)=>{
|
||||
if(!isText() || isJumping || jumpSource === 'brew') return;
|
||||
|
||||
cm.on('cursorActivity', this._onCursor);
|
||||
cm.on('scroll', this._onScroll);
|
||||
},
|
||||
renderEditor : function(){
|
||||
if(this.isText()){
|
||||
return <>
|
||||
<CodeEditor key='codeEditor'
|
||||
ref={this.codeEditor}
|
||||
language='gfm'
|
||||
tab='brewText'
|
||||
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)` }}
|
||||
onReady={this.attachCodeMirrorListeners}/>
|
||||
</>;
|
||||
}
|
||||
if(this.isStyle()){
|
||||
return <>
|
||||
<CodeEditor key='codeEditor'
|
||||
ref={this.codeEditor}
|
||||
language='css'
|
||||
tab='brewStyles'
|
||||
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)` }}
|
||||
onReady={this.attachCodeMirrorListeners}/>
|
||||
</>;
|
||||
}
|
||||
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'
|
||||
tab='brewSnippets'
|
||||
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)` }}
|
||||
onReady={this.attachCodeMirrorListeners}/>
|
||||
</>;
|
||||
}
|
||||
},
|
||||
if(!codeEditor.current) return;
|
||||
jumpSource = 'source';
|
||||
|
||||
redo : function(){
|
||||
return this.codeEditor.current?.redo();
|
||||
},
|
||||
codeEditor.current.scrollToPage(targetPage);
|
||||
setTimeout(()=>{
|
||||
jumpSource = null;
|
||||
}, 200);
|
||||
};
|
||||
|
||||
historySize : function(){
|
||||
return this.codeEditor.current?.historySize();
|
||||
},
|
||||
const updateEditorTheme = (newTheme)=>{
|
||||
window.localStorage.setItem(EDITOR_THEME_KEY, newTheme);
|
||||
setEditorSettings({ ...editorSettings, editorTheme: newTheme });
|
||||
};
|
||||
|
||||
undo : function(){
|
||||
return this.codeEditor.current?.undo();
|
||||
},
|
||||
const updateEditorSettings = (newEditorSettings)=>{
|
||||
window.localStorage.setItem(EDITOR_SETTINGS_KEY, JSON.stringify(newEditorSettings));
|
||||
setEditorSettings(newEditorSettings);
|
||||
};
|
||||
|
||||
foldCode : function(){
|
||||
return this.codeEditor.current?.foldAllCode();
|
||||
},
|
||||
const renderEditor = ()=>{
|
||||
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}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
unfoldCode : function(){
|
||||
return this.codeEditor.current?.unfoldAllCode();
|
||||
},
|
||||
const redo = ()=>codeEditor.current?.redo();
|
||||
const historySize = ()=>codeEditor.current?.historySize();
|
||||
const undo = ()=>codeEditor.current?.undo();
|
||||
const foldCode = ()=>codeEditor.current?.foldAll();
|
||||
const unfoldCode = ()=>codeEditor.current?.unfoldAll();
|
||||
|
||||
render : function(){
|
||||
//Called when there are changes to the editor's dimensions
|
||||
const update = ()=>{};
|
||||
|
||||
useImperativeHandle(ref, ()=>({
|
||||
update,
|
||||
undo,
|
||||
redo,
|
||||
foldCode,
|
||||
unfoldCode,
|
||||
historySize,
|
||||
}));
|
||||
return (
|
||||
<div className='editor' ref={this.editor}>
|
||||
<div className={`editor${isDark ? ' darkMode' : ''}`} ref={editor}>
|
||||
<SnippetBar
|
||||
brew={this.props.brew}
|
||||
view={this.state.view}
|
||||
onViewChange={this.handleViewChange}
|
||||
onInject={this.handleInject}
|
||||
showEditButtons={this.props.showEditButtons}
|
||||
renderer={this.props.renderer}
|
||||
theme={this.props.brew.theme}
|
||||
undo={this.undo}
|
||||
redo={this.redo}
|
||||
foldCode={this.foldCode}
|
||||
unfoldCode={this.unfoldCode}
|
||||
historySize={this.historySize()}
|
||||
currentEditorTheme={this.state.editorTheme}
|
||||
updateEditorTheme={this.updateEditorTheme}
|
||||
themeBundle={this.props.themeBundle}
|
||||
cursorPos={this.codeEditor.current?.getCursorPosition() || {}}
|
||||
updateBrew={this.props.updateBrew}
|
||||
brew={brew}
|
||||
view={view}
|
||||
onViewChange={handleViewChange}
|
||||
onInject={handleInject}
|
||||
showEditButtons={showEditButtons}
|
||||
renderer={renderer}
|
||||
theme={brew.theme}
|
||||
undo={undo}
|
||||
redo={redo}
|
||||
foldCode={foldCode}
|
||||
unfoldCode={unfoldCode}
|
||||
formatCode={isStyle() ? handleFormatCode : null}
|
||||
historySize={historySize()}
|
||||
currentEditorTheme={editorSettings.editorTheme}
|
||||
updateEditorTheme={updateEditorTheme}
|
||||
themeBundle={themeBundle}
|
||||
cursorPos={codeEditor.current?.getCursorPosition() || {}}
|
||||
updateBrew={updateBrew}
|
||||
assetUpload={assetUpload}
|
||||
/>
|
||||
|
||||
{this.renderEditor()}
|
||||
{renderEditor()}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
export default Editor;
|
||||
@@ -1,90 +1,11 @@
|
||||
@import '@sharedStyles/core.less';
|
||||
@import '@themes/codeMirror/customEditorStyles.less';
|
||||
|
||||
.editor {
|
||||
position : relative;
|
||||
width : 100%;
|
||||
height : 100%;
|
||||
container : editor / inline-size;
|
||||
background:white;
|
||||
.codeEditor {
|
||||
height : calc(100% - 25px);
|
||||
.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); }
|
||||
}
|
||||
}
|
||||
:where(.editor) {
|
||||
position : relative;
|
||||
width : 100%;
|
||||
height : 100%;
|
||||
container : editor / inline-size;
|
||||
background : white;
|
||||
|
||||
.brewJump {
|
||||
position : absolute;
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
/* eslint-disable max-lines */
|
||||
import './metadataEditor.less';
|
||||
import React from 'react';
|
||||
import createReactClass from 'create-react-class';
|
||||
import '../uiEditor.less';
|
||||
import React, { useState } from 'react';
|
||||
import _ from 'lodash';
|
||||
|
||||
import request from '../../utils/request-middleware.js';
|
||||
import Combobox from '../../../components/combobox.jsx';
|
||||
import TagInput from '../tagInput/tagInput.jsx';
|
||||
|
||||
|
||||
import Themes from '@themes/themes.json';
|
||||
import validations from './validations.js';
|
||||
|
||||
import Combobox from '@components/combobox.jsx';
|
||||
import TagInput from '../tagInput/tagInput.jsx';
|
||||
|
||||
import homebreweryThumbnail from '../../thumbnail.png';
|
||||
|
||||
const callIfExists = (val, fn, ...args)=>{
|
||||
@@ -19,47 +18,28 @@ const callIfExists = (val, fn, ...args)=>{
|
||||
}
|
||||
};
|
||||
|
||||
const MetadataEditor = createReactClass({
|
||||
displayName : 'MetadataEditor',
|
||||
getDefaultProps : function() {
|
||||
return {
|
||||
metadata : {
|
||||
editId : null,
|
||||
shareId : null,
|
||||
title : '',
|
||||
description : '',
|
||||
thumbnail : '',
|
||||
tags : [],
|
||||
published : false,
|
||||
authors : [],
|
||||
renderer : 'legacy',
|
||||
theme : '5ePHB',
|
||||
lang : 'en'
|
||||
},
|
||||
|
||||
onChange : ()=>{},
|
||||
reportError : ()=>{}
|
||||
};
|
||||
const MetadataEditor = ({
|
||||
metadata = {
|
||||
shareId : null,
|
||||
editId : null,
|
||||
title : '',
|
||||
description : '',
|
||||
tags : [],
|
||||
lang : 'en',
|
||||
renderer : 'legacy',
|
||||
authors : [],
|
||||
published : false,
|
||||
thumbnail : '',
|
||||
theme : '5ePHB',
|
||||
},
|
||||
onChange = ()=>{},
|
||||
reportError = ()=>{},
|
||||
userThemes = {},
|
||||
themeBundle = {}
|
||||
})=>{
|
||||
const [showThumbnail, setShowThumbnail] = useState(true);
|
||||
|
||||
getInitialState : function(){
|
||||
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){
|
||||
const handleFieldChange = (name, e)=>{
|
||||
// load validation rules, and check input value against them
|
||||
const inputRules = validations[name] ?? [];
|
||||
const validationErr = inputRules.map((rule)=>rule(e.target.value)).filter(Boolean);
|
||||
@@ -72,8 +52,8 @@ const MetadataEditor = createReactClass({
|
||||
// if no validation rules, save to props
|
||||
if(validationErr.length === 0){
|
||||
callIfExists(e.target, 'setCustomValidity', '');
|
||||
this.props.onChange({
|
||||
...this.props.metadata,
|
||||
onChange({
|
||||
...metadata,
|
||||
[name] : e.target.value
|
||||
});
|
||||
return true;
|
||||
@@ -83,49 +63,40 @@ const MetadataEditor = createReactClass({
|
||||
return `- ${err}`;
|
||||
}).join('\n');
|
||||
|
||||
|
||||
debouncedReportValidity(e.target, errMessage);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
handleRenderer : function(renderer, e){
|
||||
};
|
||||
const handleRenderer = (renderer, e)=>{
|
||||
if(e.target.checked){
|
||||
this.props.metadata.renderer = renderer;
|
||||
metadata.renderer = renderer;
|
||||
if(renderer == 'legacy')
|
||||
this.props.metadata.theme = '5ePHB';
|
||||
metadata.theme = '5ePHB';
|
||||
}
|
||||
this.props.onChange(this.props.metadata, 'renderer');
|
||||
},
|
||||
|
||||
handlePublish : function(val){
|
||||
this.props.onChange({
|
||||
...this.props.metadata,
|
||||
onChange(metadata, 'renderer');
|
||||
};
|
||||
const handlePublish = (val)=>{
|
||||
onChange({
|
||||
...metadata,
|
||||
published : val
|
||||
});
|
||||
},
|
||||
|
||||
handleTheme : function(theme){
|
||||
this.props.metadata.renderer = theme.renderer;
|
||||
this.props.metadata.theme = theme.path;
|
||||
|
||||
this.props.onChange(this.props.metadata, 'theme');
|
||||
},
|
||||
|
||||
handleThemeWritein : function(e) {
|
||||
};
|
||||
const handleTheme = (theme)=>{
|
||||
metadata.renderer = theme.renderer;
|
||||
metadata.theme = theme.path;
|
||||
onChange(metadata, 'theme');
|
||||
};
|
||||
const handleThemeWritein = (e)=>{
|
||||
const shareId = e.target.value.split('/').pop(); //Extract just the ID if a URL was pasted in
|
||||
this.props.metadata.theme = shareId;
|
||||
|
||||
this.props.onChange(this.props.metadata, 'theme');
|
||||
},
|
||||
|
||||
handleLanguage : function(languageCode){
|
||||
this.props.metadata.lang = languageCode;
|
||||
this.props.onChange(this.props.metadata);
|
||||
},
|
||||
|
||||
handleDelete : function(){
|
||||
if(this.props.metadata.authors && this.props.metadata.authors.length <= 1){
|
||||
metadata.theme = shareId;
|
||||
onChange(metadata, 'theme');
|
||||
};
|
||||
const handleLanguage = (languageCode)=>{
|
||||
metadata.lang = languageCode;
|
||||
onChange(metadata);
|
||||
};
|
||||
const handleDelete = ()=>{
|
||||
if(metadata.authors && 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 REALLY sure? You will not be able to recover the document.')) return;
|
||||
} else {
|
||||
@@ -133,61 +104,91 @@ const MetadataEditor = createReactClass({
|
||||
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()
|
||||
.end((err, res)=>{
|
||||
if(err) {
|
||||
this.props.reportError(err);
|
||||
reportError(err);
|
||||
} else {
|
||||
window.location.href = '/';
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
renderPublish : function(){
|
||||
if(this.props.metadata.published){
|
||||
return <button className='unpublish' onClick={()=>this.handlePublish(false)}>
|
||||
<i className='fas fa-ban' /> unpublish
|
||||
};
|
||||
const handleDeleteAuthor = (author)=>{
|
||||
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;
|
||||
if(!metadata.authors.includes(author)) return;
|
||||
onChange({
|
||||
...metadata,
|
||||
authors : metadata.authors.filter((a)=>a !== author)
|
||||
});
|
||||
};
|
||||
const renderPublish = ()=>{
|
||||
if(metadata.published){
|
||||
return <button id='publish-button' className='unpublish' onClick={()=>handlePublish(false)}>
|
||||
<i className='fas fa-ban' aria-hidden='true' /> unpublish
|
||||
</button>;
|
||||
} else {
|
||||
return <button className='publish' onClick={()=>this.handlePublish(true)}>
|
||||
<i className='fas fa-globe' /> publish
|
||||
return <button id='publish-button' className='publish' onClick={()=>handlePublish(true)}>
|
||||
<i className='fas fa-globe' aria-hidden='true' /> publish
|
||||
</button>;
|
||||
}
|
||||
},
|
||||
|
||||
renderDelete : function(){
|
||||
if(!this.props.metadata.editId) return;
|
||||
|
||||
return <div className='field delete'>
|
||||
<label>delete</label>
|
||||
<div className='value'>
|
||||
<button className='publish' onClick={this.handleDelete}>
|
||||
<i className='fas fa-trash-alt' /> delete brew
|
||||
</button>
|
||||
};
|
||||
const renderAuthors = ()=>{
|
||||
const authors = metadata.authors;
|
||||
const isOwner = global.account?.username && global.account?.username === authors[0];
|
||||
if(!isOwner || authors.length < 2) return (
|
||||
<div className='field authors'>
|
||||
<label>authors</label>
|
||||
<div className='value'>
|
||||
{authors.length > 0 && (
|
||||
<a href={`/user/${authors[0]}`} className='author-link' target='_blank' title={`Owner - Click to open ${authors[0]}'s profile in a new tab`}>
|
||||
{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>;
|
||||
},
|
||||
);
|
||||
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(){
|
||||
let text = 'None.';
|
||||
if(this.props.metadata.authors && this.props.metadata.authors.length){
|
||||
text = this.props.metadata.authors.join(', ');
|
||||
}
|
||||
return <div className='field authors'>
|
||||
<label>authors</label>
|
||||
<div className='value'>
|
||||
{text}
|
||||
{authors.length > 1 && authors.slice(1).map((author, i)=>(
|
||||
<li className='tag author' key={i + 1} title='Author'>
|
||||
<a href={`/user/${author}`} className='author-link' title={`Author - Click to open ${authors[0]}'s profile in a new tab`}>
|
||||
{author}
|
||||
</a>
|
||||
<button
|
||||
onClick={()=>handleDeleteAuthor(author)}
|
||||
className='delete'
|
||||
title={`Remove ${author} as an author`}
|
||||
>
|
||||
<i className='fa fa-times fa-fw' />
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>;
|
||||
},
|
||||
|
||||
renderThemeDropdown : function(){
|
||||
const mergedThemes = _.merge(Themes, this.props.userThemes);
|
||||
);
|
||||
};
|
||||
const renderThemeDropdown = ()=>{
|
||||
const mergedThemes = _.merge(Themes, userThemes);
|
||||
|
||||
const listThemes = (renderer)=>{
|
||||
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 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={''}>
|
||||
@@ -203,8 +204,8 @@ const MetadataEditor = createReactClass({
|
||||
}).filter(Boolean);
|
||||
};
|
||||
|
||||
const currentRenderer = this.props.metadata.renderer;
|
||||
const currentThemeDisplay = this.props.themeBundle?.name ? `${this.props.themeBundle.author ?? currentRenderer} : ${this.props.themeBundle.name}` : 'No Theme Selected';
|
||||
const currentRenderer = metadata.renderer;
|
||||
const currentThemeDisplay = themeBundle?.name ? `${themeBundle.author ?? currentRenderer} : ${themeBundle.name}` : 'No Theme Selected';
|
||||
let dropdown;
|
||||
|
||||
if(currentRenderer == 'legacy') {
|
||||
@@ -216,14 +217,15 @@ const MetadataEditor = createReactClass({
|
||||
dropdown =
|
||||
<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'
|
||||
id='combobox-themes'
|
||||
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'
|
||||
onSelect={(value)=>this.handleTheme(value)}
|
||||
onSelect={(value)=>handleTheme(value)}
|
||||
onEntry={(e)=>{
|
||||
e.target.setCustomValidity(''); //Clear the validation popup while typing
|
||||
if(this.handleFieldChange('theme', e))
|
||||
this.handleThemeWritein(e);
|
||||
if(handleFieldChange('theme', e))
|
||||
handleThemeWritein(e);
|
||||
}}
|
||||
options={listThemes(currentRenderer)}
|
||||
autoSuggest={{
|
||||
@@ -236,12 +238,11 @@ const MetadataEditor = createReactClass({
|
||||
}
|
||||
|
||||
return <div className='field themes'>
|
||||
<label>theme</label>
|
||||
<label htmlFor='combobox-themes'>theme</label>
|
||||
{dropdown}
|
||||
</div>;
|
||||
},
|
||||
|
||||
renderLanguageDropdown : function(){
|
||||
};
|
||||
const renderLanguageDropdown = ()=>{
|
||||
const langCodes = ['en', 'de', 'de-ch', 'fr', 'ja', 'es', 'it', 'sv', 'ru', 'zh-Hans', 'zh-Hant'];
|
||||
const listLanguages = ()=>{
|
||||
return _.map(langCodes.sort(), (code, index)=>{
|
||||
@@ -255,16 +256,19 @@ const MetadataEditor = createReactClass({
|
||||
};
|
||||
|
||||
return <div className='field language'>
|
||||
<label>language</label>
|
||||
<label htmlFor='combobox-language'>language</label>
|
||||
<div className='value' data-tooltip-right='Sets the HTML Lang property for your brew. May affect hyphenation or spellcheck.'>
|
||||
<Combobox trigger='click'
|
||||
id='combobox-language'
|
||||
className='language-dropdown'
|
||||
default={this.props.metadata.lang || ''}
|
||||
defaultValue={metadata.lang || ''}
|
||||
keepValueOnClose={true}
|
||||
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)=>{
|
||||
e.target.setCustomValidity(''); //Clear the validation popup while typing
|
||||
this.handleFieldChange('lang', e);
|
||||
handleFieldChange('lang', e);
|
||||
}}
|
||||
options={listLanguages()}
|
||||
autoSuggest={{
|
||||
@@ -274,11 +278,9 @@ const MetadataEditor = createReactClass({
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
</div>;
|
||||
},
|
||||
|
||||
renderRenderOptions : function(){
|
||||
};
|
||||
const renderRenderOptions = ()=>{
|
||||
return <div className='field renderers'>
|
||||
<label>Renderer</label>
|
||||
<div className='value'>
|
||||
@@ -287,8 +289,8 @@ const MetadataEditor = createReactClass({
|
||||
type='radio'
|
||||
value = 'legacy'
|
||||
name = 'renderer'
|
||||
checked={this.props.metadata.renderer === 'legacy'}
|
||||
onChange={(e)=>this.handleRenderer('legacy', e)} />
|
||||
checked={metadata.renderer === 'legacy'}
|
||||
onChange={(e)=>handleRenderer('legacy', e)} />
|
||||
Legacy
|
||||
</label>
|
||||
|
||||
@@ -297,103 +299,121 @@ const MetadataEditor = createReactClass({
|
||||
type='radio'
|
||||
value = 'V3'
|
||||
name = 'renderer'
|
||||
checked={this.props.metadata.renderer === 'V3'}
|
||||
onChange={(e)=>this.handleRenderer('V3', e)} />
|
||||
checked={metadata.renderer === 'V3'}
|
||||
onChange={(e)=>handleRenderer('V3', e)} />
|
||||
V3
|
||||
</label>
|
||||
<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>;
|
||||
},
|
||||
};
|
||||
|
||||
render : function(){
|
||||
return <div className='metadataEditor'>
|
||||
return (
|
||||
<div className='metadataEditor uiEditor'>
|
||||
<h1>Properties Editor</h1>
|
||||
|
||||
<div className='field title'>
|
||||
<label>title</label>
|
||||
<input type='text' className='value'
|
||||
defaultValue={this.props.metadata.title}
|
||||
onChange={(e)=>this.handleFieldChange('title', e)} />
|
||||
<label htmlFor='title_field'>title</label>
|
||||
<input
|
||||
type='text'
|
||||
id='title_field'
|
||||
className='value'
|
||||
defaultValue={metadata.title}
|
||||
onChange={(e)=>handleFieldChange('title', e)}
|
||||
/>
|
||||
</div>
|
||||
<div className='field-group'>
|
||||
<fieldset className='field-group'>
|
||||
<div className='field-column'>
|
||||
<div className='field description'>
|
||||
<label>description</label>
|
||||
<textarea defaultValue={this.props.metadata.description} className='value'
|
||||
onChange={(e)=>this.handleFieldChange('description', e)} />
|
||||
<label htmlFor='description_field'>description</label>
|
||||
<textarea
|
||||
id='description_field'
|
||||
defaultValue={metadata.description}
|
||||
className='value'
|
||||
onChange={(e)=>handleFieldChange('description', e)}
|
||||
/>
|
||||
</div>
|
||||
<div className='field thumbnail'>
|
||||
<label>thumbnail</label>
|
||||
<input type='text'
|
||||
defaultValue={this.props.metadata.thumbnail}
|
||||
<label htmlFor='thumbnail_field'>thumbnail</label>
|
||||
<input
|
||||
type='text'
|
||||
id='thumbnail_field'
|
||||
defaultValue={metadata.thumbnail}
|
||||
placeholder='https://my.thumbnail.url'
|
||||
className='value'
|
||||
onChange={(e)=>this.handleFieldChange('thumbnail', e)} />
|
||||
<button className='display' onClick={this.toggleThumbnailDisplay}>
|
||||
<i className={`fas fa-caret-${this.state.showThumbnail ? 'right' : 'left'}`} />
|
||||
onChange={(e)=>handleFieldChange('thumbnail', e)}
|
||||
/>
|
||||
<button
|
||||
className='display'
|
||||
onClick={()=>setShowThumbnail(!showThumbnail)}
|
||||
aria-label={`${showThumbnail ? 'hide thumbnail' : 'show thumbnail'}`}>
|
||||
<i className={`fas fa-caret-${showThumbnail ? 'right' : 'left'}`} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{this.renderThumbnail()}
|
||||
</div>
|
||||
|
||||
{showThumbnail && <img className='thumbnail-preview' src={metadata.thumbnail || homebreweryThumbnail}></img>}
|
||||
</fieldset>
|
||||
<div className='field tags'>
|
||||
<label>Tags</label>
|
||||
<div className='value' >
|
||||
<label htmlFor='combobox-tags'>Tags</label>
|
||||
<div className='value'>
|
||||
<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={this.props.metadata.tags}
|
||||
onChange={(e)=>this.handleFieldChange('tags', e)}
|
||||
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>
|
||||
|
||||
|
||||
{this.renderLanguageDropdown()}
|
||||
|
||||
{this.renderThemeDropdown()}
|
||||
|
||||
{this.renderRenderOptions()}
|
||||
{renderLanguageDropdown()}
|
||||
{renderThemeDropdown()}
|
||||
{renderRenderOptions()}
|
||||
|
||||
<h2>Authors</h2>
|
||||
|
||||
{this.renderAuthors()}
|
||||
|
||||
{renderAuthors()}
|
||||
<div className='field invitedAuthors'>
|
||||
<label>Invited authors</label>
|
||||
<label htmlFor='combobox-invited-authors'>Invited authors</label>
|
||||
<div className='value'>
|
||||
<TagInput
|
||||
id='combobox-invited-authors'
|
||||
label='invited authors'
|
||||
valuePatterns={/.+/}
|
||||
validators={[(v)=>!this.props.metadata.authors?.includes(v)]}
|
||||
placeholder='invite author' unique={true}
|
||||
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={this.props.metadata.invitedAuthors}
|
||||
onChange={(e)=>this.handleFieldChange('invitedAuthors', e)}
|
||||
values={metadata.invitedAuthors}
|
||||
onChange={(e)=>handleFieldChange('invitedAuthors', e)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<h2>Privacy</h2>
|
||||
|
||||
<div className='field publish'>
|
||||
<label>publish</label>
|
||||
<label htmlFor='publish-button'>publish</label>
|
||||
<div className='value'>
|
||||
{this.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>
|
||||
{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>
|
||||
|
||||
{this.renderDelete()}
|
||||
|
||||
</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>
|
||||
);
|
||||
};
|
||||
|
||||
export default MetadataEditor;
|
||||
@@ -1,326 +0,0 @@
|
||||
@import '@sharedStyles/core.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;
|
||||
&[data-tooltip-right] { max-width : 380px; }
|
||||
&: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; }
|
||||
}
|
||||
|
||||
&.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 : white;
|
||||
background-color : black;
|
||||
border : 1px solid #999999;
|
||||
&:hover { background-color : #777777; }
|
||||
}
|
||||
}
|
||||
|
||||
&.tags .tagInput-dropdown {
|
||||
z-index : 400;
|
||||
max-width : 200px;
|
||||
}
|
||||
&.language .value {
|
||||
z-index : 300;
|
||||
max-width : 150px;
|
||||
}
|
||||
|
||||
&.themes {
|
||||
.value {
|
||||
overflow : visible;
|
||||
text-overflow : auto;
|
||||
}
|
||||
button {
|
||||
padding-right : 5px;
|
||||
padding-left : 5px;
|
||||
}
|
||||
}
|
||||
|
||||
&.invitedAuthors .value {
|
||||
z-index : 100;
|
||||
|
||||
.tagInput-dropdown { max-width : 200px; }
|
||||
}
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.renderers.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 : 200;
|
||||
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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,14 +1,16 @@
|
||||
/*eslint max-lines: ["warn", {"max": 350, "skipBlankLines": true, "skipComments": true}]*/
|
||||
import './snippetbar.less';
|
||||
import React from 'react';
|
||||
import createReactClass from 'create-react-class';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Dropdown } from '@components/dropdown/dropdown.jsx';
|
||||
|
||||
import _ from 'lodash';
|
||||
import cx from 'classnames';
|
||||
|
||||
import { loadHistory } from '../../utils/versionHistory.js';
|
||||
import { brewSnippetsToJSON } from '@shared/helpers.js';
|
||||
import AssetUploadButton from '../../../fork/assets/AssetUploadButton.jsx'; // [fork] ADR-0004
|
||||
|
||||
/*eslint-disable camelcase*/
|
||||
import Legacy5ePHB from '@themes/Legacy/5ePHB/snippets.js';
|
||||
import V3_5ePHB from '@themes/V3/5ePHB/snippets.js';
|
||||
import V3_5eDMG from '@themes/V3/5eDMG/snippets.js';
|
||||
@@ -22,316 +24,275 @@ const ThemeSnippets = {
|
||||
V3_Journal : V3_Journal,
|
||||
V3_Blank : V3_Blank,
|
||||
};
|
||||
|
||||
import EditorThemes from '../../../../build/homebrew/codeMirror/editorThemes.json';
|
||||
/*eslint-enable camelcase */
|
||||
|
||||
const execute = function(val, props){
|
||||
if(_.isFunction(val)) return val(props);
|
||||
return val;
|
||||
};
|
||||
|
||||
const Snippetbar = createReactClass({
|
||||
displayName : 'SnippetBar',
|
||||
getDefaultProps : function() {
|
||||
return {
|
||||
brew : {},
|
||||
view : 'text',
|
||||
onViewChange : ()=>{},
|
||||
onInject : ()=>{},
|
||||
onToggle : ()=>{},
|
||||
showEditButtons : true,
|
||||
renderer : 'legacy',
|
||||
undo : ()=>{},
|
||||
redo : ()=>{},
|
||||
historySize : ()=>{},
|
||||
foldCode : ()=>{},
|
||||
unfoldCode : ()=>{},
|
||||
updateEditorTheme : ()=>{},
|
||||
cursorPos : {},
|
||||
themeBundle : [],
|
||||
updateBrew : ()=>{}
|
||||
};
|
||||
},
|
||||
const SnippetBar = ({
|
||||
brew = {},
|
||||
view = 'text',
|
||||
onViewChange = ()=>{},
|
||||
onInject = ()=>{},
|
||||
onToggle = ()=>{},
|
||||
showEditButtons = true,
|
||||
renderer = 'legacy',
|
||||
undo = ()=>{},
|
||||
redo = ()=>{},
|
||||
historySize = ()=>{},
|
||||
foldCode = ()=>{},
|
||||
unfoldCode = ()=>{},
|
||||
formatCode = ()=>{},
|
||||
cursorPos = {},
|
||||
themeBundle = [],
|
||||
updateBrew = ()=>{},
|
||||
assetUpload = null // [fork] ADR-0004
|
||||
})=>{
|
||||
const [snippets, setSnippets] = useState([]);
|
||||
const [historyExists, setHistoryExists] = useState(false);
|
||||
const [historyItems, setHistoryItems] = useState([]);
|
||||
|
||||
getInitialState : function() {
|
||||
return {
|
||||
renderer : this.props.renderer,
|
||||
themeSelector : false,
|
||||
snippets : [],
|
||||
showHistory : false,
|
||||
historyExists : false,
|
||||
historyItems : []
|
||||
};
|
||||
},
|
||||
useEffect(()=>{
|
||||
setSnippets(compileSnippets());
|
||||
}, []);
|
||||
|
||||
componentDidMount : async function(prevState) {
|
||||
const snippets = this.compileSnippets();
|
||||
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 mergeCustomizer = (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
|
||||
return result.filter((snip)=>snip.gen || snip.subsnippets);
|
||||
};
|
||||
},
|
||||
|
||||
compileSnippets : function() {
|
||||
};
|
||||
const compileSnippets = ()=>{
|
||||
let compiledSnippets = [];
|
||||
|
||||
let oldSnippets = _.keyBy(compiledSnippets, 'groupName');
|
||||
|
||||
if(this.props.themeBundle.snippets) {
|
||||
for (let snippets of this.props.themeBundle.snippets) {
|
||||
if(themeBundle.snippets) {
|
||||
for (let snippets of themeBundle.snippets) {
|
||||
if(typeof(snippets) == 'string') // load staticThemes as needed; they were sent as just a file name
|
||||
snippets = ThemeSnippets[snippets];
|
||||
|
||||
const newSnippets = _.keyBy(_.cloneDeep(snippets), 'groupName');
|
||||
compiledSnippets = _.values(_.mergeWith(oldSnippets, newSnippets, this.mergeCustomizer));
|
||||
compiledSnippets = _.values(_.mergeWith(oldSnippets, newSnippets, mergeCustomizer));
|
||||
|
||||
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);
|
||||
|
||||
return compiledSnippets;
|
||||
},
|
||||
};
|
||||
|
||||
handleSnippetClick : function(injectedText){
|
||||
this.props.onInject(injectedText);
|
||||
},
|
||||
useEffect(()=>{
|
||||
setSnippets(compileSnippets());
|
||||
}, [renderer, themeBundle, brew.snippets]);
|
||||
|
||||
toggleThemeSelector : function(e){
|
||||
if(e.target.tagName != 'SELECT'){
|
||||
this.setState({
|
||||
themeSelector : !this.state.themeSelector
|
||||
});
|
||||
}
|
||||
},
|
||||
useEffect(()=>{
|
||||
const updateHistory = async ()=>{
|
||||
// Update history list if it has changed
|
||||
const checkHistoryItems = await loadHistory(brew);
|
||||
|
||||
changeTheme : function(e){
|
||||
if(e.target.value == this.props.currentEditorTheme) return;
|
||||
this.props.updateEditorTheme(e.target.value);
|
||||
// If all items have the noData property, there is no saved data
|
||||
const checkHistoryExists = !checkHistoryItems.every(
|
||||
(historyItem)=>historyItem?.noData
|
||||
);
|
||||
|
||||
this.setState({
|
||||
showThemeSelector : false,
|
||||
});
|
||||
},
|
||||
if(historyExists !== checkHistoryExists) {
|
||||
setHistoryExists(checkHistoryExists);
|
||||
}
|
||||
|
||||
renderThemeSelector : function(){
|
||||
return <div className='themeSelector'>
|
||||
<select value={this.props.currentEditorTheme} onChange={this.changeTheme} >
|
||||
{EditorThemes.map((theme, key)=>{
|
||||
return <option key={key} value={theme}>{theme}</option>;
|
||||
})}
|
||||
</select>
|
||||
</div>;
|
||||
},
|
||||
// If any history items have changed, update the list
|
||||
if(!_.isEqual(checkHistoryItems, historyItems)) {
|
||||
setHistoryItems(checkHistoryItems);
|
||||
}
|
||||
};
|
||||
|
||||
renderSnippetGroups : function(){
|
||||
const snippets = this.state.snippets.filter((snippetGroup)=>snippetGroup.view === this.props.view);
|
||||
if(snippets.length === 0) return null;
|
||||
updateHistory();
|
||||
}, [brew]);
|
||||
|
||||
return <div className='snippets'>
|
||||
{_.map(snippets, (snippetGroup)=>{
|
||||
const handleSnippetClick = (injectedText)=>onInject(injectedText);
|
||||
|
||||
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
|
||||
brew={this.props.brew}
|
||||
brew={brew}
|
||||
groupName={snippetGroup.groupName}
|
||||
icon={snippetGroup.icon}
|
||||
snippets={snippetGroup.snippets}
|
||||
key={snippetGroup.groupName}
|
||||
onSnippetClick={this.handleSnippetClick}
|
||||
cursorPos={this.props.cursorPos}
|
||||
onSnippetClick={handleSnippetClick}
|
||||
cursorPos={cursorPos}
|
||||
/>;
|
||||
})
|
||||
}
|
||||
</div>;
|
||||
},
|
||||
</ul>;
|
||||
};
|
||||
|
||||
replaceContent : function(item){
|
||||
return this.props.updateBrew(item);
|
||||
},
|
||||
const replaceContent = (item)=>{
|
||||
return updateBrew(item);
|
||||
};
|
||||
|
||||
toggleHistoryMenu : function(){
|
||||
this.setState({
|
||||
showHistory : !this.state.showHistory
|
||||
});
|
||||
},
|
||||
const renderHistoryMenu = ()=>{
|
||||
return (
|
||||
<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() {
|
||||
if(!this.state.historyExists) return;
|
||||
const saveTime = new Date(item.savedAt);
|
||||
const diffMs = new Date() - saveTime;
|
||||
const diffSecs = Math.floor(diffMs / 1000);
|
||||
|
||||
return <div className='dropdown'>
|
||||
{_.map(this.state.historyItems, (item, index)=>{
|
||||
if(item.noData || !item.savedAt) return;
|
||||
let diffString = `about ${diffSecs} seconds ago`;
|
||||
|
||||
const saveTime = new Date(item.savedAt);
|
||||
const diffMs = new Date() - saveTime;
|
||||
const diffSecs = Math.floor(diffMs / 1000);
|
||||
if(diffSecs > 60)
|
||||
diffString = `about ${Math.floor(diffSecs / 60)} minutes ago`;
|
||||
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`;
|
||||
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`;
|
||||
|
||||
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;
|
||||
const renderEditorButtons =()=>{
|
||||
if(!showEditButtons) return;
|
||||
|
||||
return (
|
||||
<div className='editors'>
|
||||
{this.props.view !== 'meta' && <><div className='historyTools'>
|
||||
<div className={`editorTool snippetGroup history ${this.state.historyExists ? 'active' : ''}`}
|
||||
onClick={this.toggleHistoryMenu} >
|
||||
<i className='fas fa-clock-rotate-left' />
|
||||
{ this.state.showHistory && this.renderHistoryItems() }
|
||||
</div>
|
||||
<div className={`editorTool undo ${this.props.historySize.undo ? 'active' : ''}`}
|
||||
onClick={this.props.undo} >
|
||||
{view !== 'meta' && view !== 'settings' && <><div className='historyTools'>
|
||||
{renderHistoryMenu()}
|
||||
<button className={`editorTool undo ${historySize.done ? 'active' : ''}`}
|
||||
onClick={undo} >
|
||||
<i className='fas fa-undo' />
|
||||
</div>
|
||||
<div className={`editorTool redo ${this.props.historySize.redo ? 'active' : ''}`}
|
||||
onClick={this.props.redo} >
|
||||
</button>
|
||||
<button className={`editorTool redo ${historySize.undone ? 'active' : ''}`}
|
||||
onClick={redo} >
|
||||
<i className='fas fa-redo' />
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
<div className='codeTools'>
|
||||
<div className={`editorTool foldAll ${this.props.foldCode ? 'active' : ''}`}
|
||||
onClick={this.props.foldCode} >
|
||||
<button className={`editorTool foldAll ${foldCode ? 'active' : ''}`}
|
||||
onClick={foldCode} >
|
||||
<i className='fas fa-compress-alt' />
|
||||
</div>
|
||||
<div className={`editorTool unfoldAll ${this.props.unfoldCode ? 'active' : ''}`}
|
||||
onClick={this.props.unfoldCode} >
|
||||
</button>
|
||||
<button className={`editorTool unfoldAll ${unfoldCode ? 'active' : ''}`}
|
||||
onClick={unfoldCode} >
|
||||
<i className='fas fa-expand-alt' />
|
||||
</div>
|
||||
<div className={`editorTheme ${this.state.themeSelector ? 'active' : ''}`}
|
||||
onClick={this.toggleThemeSelector} >
|
||||
<i className='fas fa-palette' />
|
||||
{this.state.themeSelector && this.renderThemeSelector()}
|
||||
</div>
|
||||
</button>
|
||||
<button className={`editorTool formatCode ${formatCode ? 'active' : ''}`}
|
||||
onClick={formatCode} >
|
||||
<i className='fas fa-wand-magic-sparkles' />
|
||||
</button>
|
||||
{view === 'text' && <AssetUploadButton assetUpload={assetUpload} />}
|
||||
</div></>}
|
||||
|
||||
<div className='tabs'>
|
||||
<div className={cx('text', { selected: this.props.view === 'text' })}
|
||||
onClick={()=>this.props.onViewChange('text')}>
|
||||
<button className={cx('text', { selected: view === 'text' })}
|
||||
onClick={()=>onViewChange('text')}>
|
||||
<i className='fa fa-beer' />
|
||||
</div>
|
||||
<div className={cx('style', { selected: this.props.view === 'style' })}
|
||||
onClick={()=>this.props.onViewChange('style')}>
|
||||
</button>
|
||||
<button className={cx('style', { selected: view === 'style' })}
|
||||
onClick={()=>onViewChange('style')}>
|
||||
<i className='fa fa-paint-brush' />
|
||||
</div>
|
||||
<div className={cx('snippet', { selected: this.props.view === 'snippet' })}
|
||||
onClick={()=>this.props.onViewChange('snippet')}>
|
||||
</button>
|
||||
<button className={cx('snippet', { selected: view === 'snippet' })}
|
||||
onClick={()=>onViewChange('snippet')}>
|
||||
<i className='fas fa-th-list' />
|
||||
</div>
|
||||
<div className={cx('meta', { selected: this.props.view === 'meta' })}
|
||||
onClick={()=>this.props.onViewChange('meta')}>
|
||||
</button>
|
||||
<button className={cx('meta', { selected: view === 'meta' })}
|
||||
onClick={()=>onViewChange('meta')}>
|
||||
<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>
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
render : function(){
|
||||
return <div className='snippetBar'>
|
||||
{this.renderSnippetGroups()}
|
||||
{this.renderEditorButtons()}
|
||||
</div>;
|
||||
}
|
||||
});
|
||||
return <div className='snippetBar'>
|
||||
{renderSnippetGroups()}
|
||||
{renderEditorButtons()}
|
||||
</div>;
|
||||
};
|
||||
|
||||
export default Snippetbar;
|
||||
export default SnippetBar;
|
||||
|
||||
const SnippetGroup = createReactClass({
|
||||
displayName : 'SnippetGroup',
|
||||
getDefaultProps : function() {
|
||||
return {
|
||||
brew : {},
|
||||
groupName : '',
|
||||
icon : 'fas fa-rocket',
|
||||
snippets : [],
|
||||
onSnippetClick : function(){},
|
||||
};
|
||||
},
|
||||
handleSnippetClick : function(e, snippet){
|
||||
e.stopPropagation();
|
||||
this.props.onSnippetClick(execute(snippet.gen, this.props));
|
||||
},
|
||||
renderSnippets : function(snippets){
|
||||
const SnippetGroup = (props)=>{
|
||||
const {
|
||||
brew = {},
|
||||
groupName = '',
|
||||
icon = 'fas fa-rocket',
|
||||
snippets = [],
|
||||
onSnippetClick = function(){},
|
||||
} = props;
|
||||
|
||||
const handleSnippetClick = (e, snippet)=>{
|
||||
onSnippetClick(execute(snippet.gen, props));
|
||||
};
|
||||
const renderSnippets = (snippets)=>{
|
||||
return _.map(snippets, (snippet)=>{
|
||||
return <div className='snippet' key={snippet.name} onClick={(e)=>this.handleSnippetClick(e, snippet)}>
|
||||
<i className={snippet.icon} />
|
||||
<span className={`name${snippet.disabled ? ' disabled' : ''}`} title={snippet.name}>{snippet.name}</span>
|
||||
{snippet.experimental && <span className='beta'>beta</span>}
|
||||
{snippet.disabled && <span className='beta' title='temporarily disabled due to large slowdown; under re-design'>disabled</span>}
|
||||
{snippet.subsnippets && <>
|
||||
<i className='fas fa-caret-right'></i>
|
||||
<div className='dropdown side'>
|
||||
{this.renderSnippets(snippet.subsnippets)}
|
||||
</div></>}
|
||||
</div>;
|
||||
if(!snippet.subsnippets){
|
||||
return (
|
||||
<li key={snippet.name} role='none'>
|
||||
<button className='menu-item' onClick={(e)=>handleSnippetClick(e, snippet)} role='menuitem' aria-label={snippet.name} disabled={snippet.disabled}>
|
||||
<i className={snippet.icon} />
|
||||
<span className={`name${snippet.disabled ? ' disabled' : ''}`} title={snippet.name}>{snippet.name}</span>
|
||||
{snippet.experimental && <span className='status'>beta</span>}
|
||||
{snippet.disabled && <span className='status' title='temporarily disabled due to large slowdown; under re-design'>disabled</span>}
|
||||
</button>
|
||||
</li>
|
||||
);
|
||||
} else if(snippet.subsnippets){
|
||||
return (
|
||||
<Dropdown groupName={snippet.name} icon={snippet.icon} key={snippet.name}>
|
||||
{renderSnippets(snippet.subsnippets)}
|
||||
</Dropdown>
|
||||
);
|
||||
}
|
||||
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
render : function(){
|
||||
const snippetGroup = `snippetGroup snippetBarButton ${this.props.snippets.length === 0 ? 'disabledSnippets' : ''}`;
|
||||
return <div className={snippetGroup}>
|
||||
<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>;
|
||||
},
|
||||
});
|
||||
return <Dropdown groupName={groupName} id={groupName} icon={icon}>
|
||||
{renderSnippets(snippets)}
|
||||
</Dropdown>;
|
||||
};
|
||||
@@ -1,29 +1,33 @@
|
||||
@import '@sharedStyles/core.less';
|
||||
@import (less) './client/icons/customIcons.less';
|
||||
@import (less) '../../../icons/customIcons.less';
|
||||
@import (less) '@themes/fonts/5e/fonts.less';
|
||||
|
||||
.snippetBar {
|
||||
--menuColor : #DDDDDD;
|
||||
--textColor : black;
|
||||
--hoverMenuColor : #999999;
|
||||
|
||||
@menuHeight : 25px;
|
||||
position : relative;
|
||||
display : flex;
|
||||
flex-wrap : wrap-reverse;
|
||||
justify-content : space-between;
|
||||
height : auto;
|
||||
color : black;
|
||||
background-color : #DDDDDD;
|
||||
|
||||
.snippets {
|
||||
display : flex;
|
||||
justify-content : flex-start;
|
||||
min-width : 499.35px; //must be controlled every time an item is added, must be hardcoded for the wrapping as it is applied
|
||||
}
|
||||
font-family : 'Open Sans', sans-serif;
|
||||
font-size : 0.65rem;
|
||||
font-weight : 800;
|
||||
color : var(--textColor);
|
||||
text-transform : uppercase;
|
||||
background-color : var(--menuColor);
|
||||
reading-flow : flex-visual;
|
||||
|
||||
.editors {
|
||||
display : flex;
|
||||
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;}
|
||||
reading-order : 2;
|
||||
|
||||
>div {
|
||||
display : flex;
|
||||
@@ -32,7 +36,7 @@
|
||||
|
||||
&:first-child { border-left : none; }
|
||||
|
||||
& > div {
|
||||
& > button, & > li {
|
||||
position : relative;
|
||||
width : @menuHeight;
|
||||
height : @menuHeight;
|
||||
@@ -40,9 +44,9 @@
|
||||
text-align : center;
|
||||
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 {
|
||||
.tooltipLeft('Brew Editor');
|
||||
}
|
||||
@@ -55,37 +59,45 @@
|
||||
&.snippet {
|
||||
.tooltipLeft('Snippets');
|
||||
}
|
||||
&.settings {
|
||||
.tooltipLeft('Settings');
|
||||
}
|
||||
&.undo {
|
||||
.tooltipLeft('Undo');
|
||||
font-size : 0.75em;
|
||||
color : grey;
|
||||
&.active { color : inherit; }
|
||||
}
|
||||
&.redo {
|
||||
.tooltipLeft('Redo');
|
||||
font-size : 0.75em;
|
||||
color : grey;
|
||||
&.active { color : inherit; }
|
||||
}
|
||||
&.foldAll {
|
||||
.tooltipLeft('Fold All');
|
||||
font-size : 0.75em;
|
||||
color : grey;
|
||||
&.active { color : inherit; }
|
||||
}
|
||||
&.unfoldAll {
|
||||
.tooltipLeft('Unfold All');
|
||||
font-size : 0.75em;
|
||||
color : grey;
|
||||
&.active { color : inherit; }
|
||||
}
|
||||
&.formatCode {
|
||||
.tooltipLeft('Clean your Code');
|
||||
color : grey;
|
||||
&.active { color : inherit; }
|
||||
}
|
||||
&.history {
|
||||
font-size:.70rem;
|
||||
|
||||
i {
|
||||
min-width:auto;
|
||||
}
|
||||
.tooltipLeft('History');
|
||||
position : relative;
|
||||
font-size : 0.75em;
|
||||
color : grey;
|
||||
border : none;
|
||||
&.active { color : inherit; }
|
||||
&:not(:disabled) { color : inherit; }
|
||||
& > .dropdown {
|
||||
right : -1px;
|
||||
& > .snippet { padding-right : 10px; }
|
||||
@@ -93,18 +105,12 @@
|
||||
}
|
||||
&.editorTheme {
|
||||
.tooltipLeft('Editor Themes');
|
||||
font-size : 0.75em;
|
||||
color : inherit;
|
||||
&.active {
|
||||
position : relative;
|
||||
background-color : #999999;
|
||||
}
|
||||
}
|
||||
&.divider {
|
||||
width : 5px;
|
||||
background : linear-gradient(currentColor, currentColor) no-repeat center/1px 100%;
|
||||
&:hover { background-color : inherit; }
|
||||
}
|
||||
}
|
||||
.themeSelector {
|
||||
position : absolute;
|
||||
@@ -120,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 {
|
||||
position : absolute;
|
||||
top : 0px;
|
||||
@@ -144,112 +134,106 @@
|
||||
border-left : 1px solid black;
|
||||
.tooltipLeft('Edit Brew Properties');
|
||||
}
|
||||
.snippetGroup {
|
||||
|
||||
&:hover {
|
||||
& > .dropdown { visibility : visible; }
|
||||
.snippets {
|
||||
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 {
|
||||
position : absolute;
|
||||
top : 100%;
|
||||
z-index : 1000;
|
||||
visibility : hidden;
|
||||
padding : 0px;
|
||||
margin-left : -5px;
|
||||
background-color : #DDDDDD;
|
||||
.snippet {
|
||||
position : relative;
|
||||
display : flex;
|
||||
align-items : center;
|
||||
min-width : max-content;
|
||||
padding : 5px;
|
||||
font-size : 10px;
|
||||
cursor : pointer;
|
||||
.animate(background-color);
|
||||
i {
|
||||
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';
|
||||
}
|
||||
.menu-name {
|
||||
flex : 1;
|
||||
text-align : left;
|
||||
text-box-trim : trim-end;
|
||||
}
|
||||
i {
|
||||
min-width : 25px;
|
||||
height : 0.85rem;
|
||||
font-size : 1.2em;
|
||||
text-align : center;
|
||||
&.caret { margin-right : 0; }
|
||||
&.caret:is(.menu-wrapper .menu-wrapper *) { text-align : right; }
|
||||
/* Fonts */
|
||||
&.font {
|
||||
height : auto;
|
||||
&::before {
|
||||
font-size : 1em;
|
||||
content : 'ABC';
|
||||
}
|
||||
|
||||
&.OpenSans {font-family : 'OpenSans';}
|
||||
&.CodeBold {font-family : 'CodeBold';}
|
||||
&.CodeLight {font-family : 'CodeLight';}
|
||||
&.ScalySansRemake {font-family : 'ScalySansRemake';}
|
||||
&.BookInsanityRemake {font-family : 'BookInsanityRemake';}
|
||||
&.MrEavesRemake {font-family : 'MrEavesRemake';}
|
||||
&.SolberaImitationRemake {font-family : 'SolberaImitationRemake';}
|
||||
&.ScalySansSmallCapsRemake {font-family : 'ScalySansSmallCapsRemake';}
|
||||
&.WalterTurncoat {font-family : 'WalterTurncoat';}
|
||||
&.Lato {font-family : 'Lato';}
|
||||
&.Courier {font-family : 'Courier';}
|
||||
&.NodestoCapsCondensed {font-family : 'NodestoCapsCondensed';}
|
||||
&.Overpass {font-family : 'Overpass';}
|
||||
&.Davek {font-family : 'Davek';}
|
||||
&.Iokharic {font-family : 'Iokharic';}
|
||||
&.Rellanic {font-family : 'Rellanic';}
|
||||
&.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
&.OpenSans {font-family : 'OpenSans';}
|
||||
&.CodeBold {font-family : 'CodeBold';}
|
||||
&.CodeLight {font-family : 'CodeLight';}
|
||||
&.ScalySansRemake {font-family : 'ScalySansRemake';}
|
||||
&.BookInsanityRemake {font-family : 'BookInsanityRemake';}
|
||||
&.MrEavesRemake {font-family : 'MrEavesRemake';}
|
||||
&.SolberaImitationRemake {font-family : 'SolberaImitationRemake';}
|
||||
&.ScalySansSmallCapsRemake {font-family : 'ScalySansSmallCapsRemake';}
|
||||
&.WalterTurncoat {font-family : 'WalterTurncoat';}
|
||||
&.Lato {font-family : 'Lato';}
|
||||
&.Courier {font-family : 'Courier';}
|
||||
&.NodestoCapsCondensed {font-family : 'NodestoCapsCondensed';}
|
||||
&.Overpass {font-family : 'Overpass';}
|
||||
&.Davek {font-family : 'Davek';}
|
||||
&.Iokharic {font-family : 'Iokharic';}
|
||||
&.Rellanic {font-family : 'Rellanic';}
|
||||
&.TimesNewRoman {font-family : 'Times New Roman';}
|
||||
}
|
||||
}
|
||||
.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 {
|
||||
.editors {
|
||||
flex : 1;
|
||||
justify-content : space-between;
|
||||
border-bottom : 1px solid;
|
||||
reading-order : 1;
|
||||
}
|
||||
.snippets {
|
||||
flex : 1;
|
||||
justify-content : space-evenly;
|
||||
reading-order : 2;
|
||||
}
|
||||
.editors > div.history > .dropdown { right : unset; }
|
||||
}
|
||||
}
|
||||
|
||||
.editor.darkMode .snippetBar {
|
||||
--menuColor : #666666;
|
||||
--textColor : #EEEEEE;
|
||||
--hoverMenuColor : #444444;
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
import './tagInput.less';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import Combobox from '../../../components/combobox.jsx';
|
||||
import Combobox from '@components/combobox.jsx';
|
||||
|
||||
import { tagSuggestionList, canonizationList } from './curatedTagSuggestionList.js';
|
||||
|
||||
const TagInput = ({ tooltip, label, valuePatterns, values = [], unique = true, placeholder = '', smallText = '', onChange })=>{
|
||||
const TagInput = ({ id, tooltip, label, valuePatterns, values = [], unique = true, placeholder = '', smallText = '', onChange })=>{
|
||||
const [tagList, setTagList] = useState(
|
||||
values.map((value)=>({
|
||||
value,
|
||||
@@ -128,9 +128,10 @@ const TagInput = ({ tooltip, label, valuePatterns, values = [], unique = true, p
|
||||
return (
|
||||
<div className='tagInputWrap'>
|
||||
<Combobox
|
||||
id={id}
|
||||
trigger='click'
|
||||
className='tagInput-dropdown'
|
||||
default=''
|
||||
defaultValue=''
|
||||
placeholder={placeholder}
|
||||
options={label === 'tags' ? suggestionOptions : []}
|
||||
tooltip={tooltip}
|
||||
@@ -155,6 +156,7 @@ const TagInput = ({ tooltip, label, valuePatterns, values = [], unique = true, p
|
||||
<ul className='list'>
|
||||
{tagList.map((t, i)=>t.editing ? (
|
||||
<input
|
||||
id={`${id}-${i}`}
|
||||
key={i}
|
||||
type='text'
|
||||
value={t.draft} // always use draft
|
||||
@@ -181,6 +183,7 @@ const TagInput = ({ tooltip, label, valuePatterns, values = [], unique = true, p
|
||||
{t.value}
|
||||
<button
|
||||
type='button'
|
||||
aria-label={`remove ${t.value} tag`}
|
||||
onClick={(e)=>{
|
||||
e.stopPropagation();
|
||||
removeTag(i);
|
||||
|
||||
@@ -1,30 +1,20 @@
|
||||
.tags {
|
||||
|
||||
.tagInputWrap {
|
||||
display:grid;
|
||||
grid-template-columns: 200px 3fr;
|
||||
gap:10px;
|
||||
display : grid;
|
||||
grid-template-columns : 200px 3fr;
|
||||
gap : 10px;
|
||||
}
|
||||
|
||||
.list input {
|
||||
border-radius: 5px;
|
||||
}
|
||||
.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;
|
||||
}
|
||||
&.type { background-color : #00800035; }
|
||||
&.group { background-color : #50505035; }
|
||||
&.meta { background-color : #00008035; }
|
||||
&.system { background-color : #80000035; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -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,6 +1,5 @@
|
||||
import 'core-js/es/string/to-well-formed.js'; // Polyfill for older browsers
|
||||
import './homebrew.less';
|
||||
import React from 'react';
|
||||
import { BrowserRouter as Router, Routes, Route, useParams, useSearchParams } from 'react-router';
|
||||
|
||||
import { updateLocalStorage } from './utils/updateLocalStorage/updateLocalStorageKeys.js';
|
||||
@@ -18,6 +17,7 @@ const WithRoute = ({ el: Element, ...rest })=>{
|
||||
const params = useParams();
|
||||
const [searchParams] = useSearchParams();
|
||||
const queryParams = Object.fromEntries(searchParams?.entries() || []);
|
||||
queryParams.tag = searchParams.getAll('tag');
|
||||
return <Element {...rest} {...params} query={queryParams} />;
|
||||
};
|
||||
|
||||
@@ -37,11 +37,17 @@ const Homebrew = (props)=>{
|
||||
lang : ''
|
||||
},
|
||||
userThemes,
|
||||
brews
|
||||
brews,
|
||||
enablev4
|
||||
} = props;
|
||||
|
||||
global.account = account;
|
||||
global.version = version;
|
||||
global.config = config;
|
||||
global.enablev4 = enablev4;
|
||||
|
||||
const backgroundObject = ()=>{
|
||||
if(config?.deployment || (config?.local && config?.development)) {
|
||||
if(config?.deployment || config?.developmentStyle) {
|
||||
const bgText = config?.deployment || 'Local';
|
||||
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>")`
|
||||
@@ -55,7 +61,7 @@ const Homebrew = (props)=>{
|
||||
if(brew.pureError) {
|
||||
return (
|
||||
<Router>
|
||||
<div className={`homebrew${(config?.deployment || config?.local) ? ' deployment' : ''}`} style={backgroundObject()}>
|
||||
<div className={`homebrew${(config?.deployment || config?.developmentStyle) ? ' deployment' : ''}`} style={backgroundObject()}>
|
||||
<Routes>
|
||||
<Route path={brew.originalUrl} element={<WithRoute el={ErrorPage} brew={brew} />} />
|
||||
</Routes>
|
||||
@@ -64,25 +70,29 @@ const Homebrew = (props)=>{
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<Router>
|
||||
<div className={`homebrew${(config?.deployment || config?.local) ? ' deployment' : ''}`} style={backgroundObject()}>
|
||||
<div className={`homebrew${(config?.deployment || config?.developmentStyle) ? ' deployment' : ''}`} style={backgroundObject()}>
|
||||
<Routes>
|
||||
<Route path='/edit/:id' element={<WithRoute el={EditPage} brew={brew} userThemes={userThemes}/>} />
|
||||
<Route path='/share/:id' element={<WithRoute el={SharePage} 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='/' element={<WithRoute el={HomePage} brew={brew} />} />
|
||||
<Route path='/*' 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='/*' 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='/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>
|
||||
</div>
|
||||
</Router>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
@import '@sharedStyles/core.less';
|
||||
.homebrew {
|
||||
height : 100%;
|
||||
background-color:@steel;
|
||||
height : 100%;
|
||||
background-color : @steel;
|
||||
&.deployment { background-color : darkred; }
|
||||
|
||||
.sitePage {
|
||||
@@ -15,21 +15,5 @@
|
||||
height : calc(~'100% - 29px'); //Navbar height
|
||||
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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +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();
|
||||
@@ -2,6 +2,7 @@ import React from 'react';
|
||||
import createReactClass from 'create-react-class';
|
||||
import request from 'superagent';
|
||||
import Nav from './nav.jsx';
|
||||
import { getLoginUrl, getLogoutUrl, getOidcLabel, logoutViaServer, oidcEnabled, naturalcritEnabled } from '../../fork/auth/loginUrl.js';
|
||||
|
||||
const Account = createReactClass({
|
||||
displayName : 'AccountNavItem',
|
||||
@@ -23,6 +24,7 @@ const Account = createReactClass({
|
||||
if(confirm('Are you sure you want to log out?')) {
|
||||
// Reset divider position
|
||||
window.localStorage.removeItem('naturalcrit-pane-split');
|
||||
if(logoutViaServer()) { window.location = getLogoutUrl(); return; }
|
||||
// Clear login cookie
|
||||
let domain = '';
|
||||
if(window.location?.hostname) {
|
||||
@@ -97,7 +99,7 @@ const Account = createReactClass({
|
||||
|
||||
// Logged out
|
||||
// LOCAL ONLY
|
||||
if(global.config?.local) {
|
||||
if(global.config?.local && !oidcEnabled() && naturalcritEnabled()) {
|
||||
return <Nav.item color='teal' icon='fas fa-sign-in-alt' onClick={this.localLogin}>
|
||||
login
|
||||
</Nav.item>;
|
||||
@@ -105,8 +107,8 @@ const Account = createReactClass({
|
||||
|
||||
// Logged out
|
||||
// Production site
|
||||
return <Nav.item href={`https://www.naturalcrit.com/login?redirect=${this.state.url}`} color='teal' icon='fas fa-sign-in-alt'>
|
||||
login
|
||||
return <Nav.item href={getLoginUrl(this.state.url)} color='teal' icon='fas fa-sign-in-alt'>
|
||||
{oidcEnabled() ? getOidcLabel() : 'login'}
|
||||
</Nav.item>;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import './error-navitem.less';
|
||||
import React from 'react';
|
||||
import Nav from './nav.jsx';
|
||||
import GitErrorNavItem from '../../fork/git/GitErrorNavItem.jsx'; // [fork] ADR-0003
|
||||
|
||||
const ErrorNavItem = ({ error = '', clearError })=>{
|
||||
const ErrorNavItem = ({ error = '', clearError, brew })=>{
|
||||
const response = error.response;
|
||||
const errorCode = error.code;
|
||||
const status = response?.status;
|
||||
@@ -17,6 +18,8 @@ const ErrorNavItem = ({ error = '', clearError })=>{
|
||||
console.log(errMsg);
|
||||
} catch {}
|
||||
|
||||
if(typeof HBErrorCode === 'string' && /^G\d\d$/.test(HBErrorCode)) return <GitErrorNavItem error={error} clearError={clearError} brew={brew} />; // [fork] ADR-0003, vor der 409-Behandlung
|
||||
|
||||
if(status === 409) {
|
||||
return <Nav.item className='save error' icon='fas fa-exclamation-triangle'>
|
||||
Oops!
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
import './navbar.less';
|
||||
import React, { useState, useRef, useEffect } from 'react';
|
||||
import createReactClass from 'create-react-class';
|
||||
import _ from 'lodash';
|
||||
import cx from 'classnames';
|
||||
|
||||
import NaturalCritIcon from '../../components/svg/naturalcrit-d20.svg.jsx';
|
||||
import NaturalCritIcon from '@components/svg/naturalcrit-d20.svg.jsx';
|
||||
|
||||
const Nav = {
|
||||
base : createReactClass({
|
||||
displayName : 'Nav.base',
|
||||
render : function(){
|
||||
return <nav>
|
||||
{this.props.children}
|
||||
</nav>;
|
||||
}
|
||||
}),
|
||||
logo : function(){
|
||||
base : ({ children, className, ...props })=>{
|
||||
return <nav className={className}>
|
||||
{children}
|
||||
</nav>;
|
||||
},
|
||||
logo : ()=>{
|
||||
return <a className='navLogo' href='https://www.naturalcrit.com'>
|
||||
<NaturalCritIcon />
|
||||
<span className='name'>
|
||||
@@ -24,50 +19,26 @@ const Nav = {
|
||||
</a>;
|
||||
},
|
||||
|
||||
section : createReactClass({
|
||||
displayName : 'Nav.section',
|
||||
render : function(){
|
||||
return <div className={`navSection ${this.props.className ?? ''}`}>
|
||||
{this.props.children}
|
||||
</div>;
|
||||
section : ({ children, className, ...props })=>{
|
||||
return <div className={cx([`navSection`, className])}>
|
||||
{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 : createReactClass({
|
||||
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) {
|
||||
props = Object.assign({}, props, {
|
||||
|
||||
@@ -1,46 +1,28 @@
|
||||
import './navbar.less';
|
||||
import React from 'react';
|
||||
import createReactClass from 'create-react-class';
|
||||
|
||||
import Nav from './nav.jsx';
|
||||
import PatreonNavItem from './patreon.navitem.jsx';
|
||||
|
||||
const Navbar = createReactClass({
|
||||
displayName : 'Navbar',
|
||||
getInitialState : function() {
|
||||
return {
|
||||
// showNonChromeWarning: false, // uncomment if needed
|
||||
ver : global.version || '0.0.0'
|
||||
};
|
||||
},
|
||||
const Navbar = ({ children })=>{
|
||||
const version = global.version || '0.0.0';
|
||||
|
||||
/*
|
||||
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>
|
||||
return (
|
||||
<Nav.base>
|
||||
<Nav.section>
|
||||
<Nav.logo />
|
||||
<Nav.item href='/' className='homebrewLogo'>
|
||||
<div>The Homebrewery</div>
|
||||
</Nav.item>
|
||||
<Nav.item newTab={true} href='/changelog' color='purple' icon='far fa-file-alt'>
|
||||
{`v${this.state.ver}`}
|
||||
{`v${version}`}
|
||||
</Nav.item>
|
||||
<PatreonNavItem />
|
||||
{/*this.renderChromeWarning()*/}
|
||||
{/* this.renderChromeWarning() */}
|
||||
</Nav.section>
|
||||
{this.props.children}
|
||||
</Nav.base>;
|
||||
}
|
||||
});
|
||||
{children}
|
||||
</Nav.base>
|
||||
);
|
||||
};
|
||||
|
||||
export default Navbar;
|
||||
export default Navbar;
|
||||
@@ -39,9 +39,7 @@
|
||||
flex-grow : 1;
|
||||
min-width : 300px;
|
||||
}
|
||||
>.brewTitle {
|
||||
cursor:auto;
|
||||
}
|
||||
>.brewTitle { cursor : auto; }
|
||||
}
|
||||
// "NaturalCrit" logo
|
||||
.navLogo {
|
||||
|
||||
@@ -1,9 +1,25 @@
|
||||
import React from 'react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import Nav from './nav.jsx';
|
||||
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); };
|
||||
|
||||
return <Nav.item onClick={printCurrentBrew} color='purple' icon='far fa-file-pdf'>
|
||||
get PDF
|
||||
{printing ? 'loading' : 'get PDF'}
|
||||
</Nav.item>;
|
||||
};
|
||||
@@ -17,7 +17,7 @@ const getRedditLink = (brew)=>{
|
||||
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.item color='teal' icon='fas fa-share-alt'>
|
||||
share
|
||||
@@ -28,6 +28,12 @@ export default ({ brew })=>(
|
||||
<Nav.item color='blue' onClick={()=>{navigator.clipboard.writeText(`${global.config.baseUrl}/share/${getShareId(brew)}`);}}>
|
||||
copy url
|
||||
</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'>
|
||||
post to reddit
|
||||
</Nav.item>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import React from 'react';
|
||||
import moment from 'moment';
|
||||
import UIPage from '../basePages/uiPage/uiPage.jsx';
|
||||
import NaturalCritIcon from '../../../components/svg/naturalcrit-d20.svg.jsx';
|
||||
import NaturalCritIcon from '@components/svg/naturalcrit-d20.svg.jsx';
|
||||
import GitConnectionsPanel from '../../../fork/git/GitConnectionsPanel.jsx'; // [fork] ADR-0003
|
||||
|
||||
let SAVEKEY = '';
|
||||
|
||||
@@ -68,6 +69,7 @@ const AccountPage = (props)=>{
|
||||
{renderSaveLocationButton('Homebrewery', 'HOMEBREWERY')}
|
||||
{renderSaveLocationButton('Google Drive', 'GOOGLE-DRIVE', accountDetails.googleId)}
|
||||
</div>
|
||||
{accountDetails.username && <GitConnectionsPanel />}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,459 @@
|
||||
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';
|
||||
import GitNavItem from '../../../../fork/git/GitNavItem.jsx'; // [fork] ADR-0003
|
||||
import { SAVE_EVENT as GIT_SAVE_EVENT } from '../../../../fork/git/gitApi.js';
|
||||
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 GIT_SAVE_TIMEOUT = 60000; // [fork] ADR-0003 F6: Autosave für Git-verknüpfte Brews 60 s (ein Commit pro Save)
|
||||
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 [gitLinked, setGitLinked] = useState(false); // [fork]
|
||||
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);
|
||||
const handleGitSave = ()=>trySave(true, true, saveGoogle); // [fork] ADR-0003: "Meine Version behalten"
|
||||
document.addEventListener(GIT_SAVE_EVENT, handleGitSave);
|
||||
window.onbeforeunload = ()=>{
|
||||
if(unsavedChangesRef.current)
|
||||
return 'You have unsaved changes!';
|
||||
};
|
||||
return ()=>{
|
||||
document.removeEventListener('keydown', handleControlKeys);
|
||||
document.removeEventListener(GIT_SAVE_EVENT, handleGitSave);
|
||||
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 autoSaveTimeout = gitLinked ? GIT_SAVE_TIMEOUT : SAVE_TIMEOUT; // [fork] ADR-0003 F6
|
||||
const newTimeout = forceSave ? 0 : autoSaveTimeout;
|
||||
|
||||
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} brew={currentBrew} />
|
||||
: <Nav.dropdown className='save-menu'>
|
||||
{renderSaveButton()}
|
||||
{(pageName == 'editPage') && renderAutoSaveButton()}
|
||||
</Nav.dropdown>}
|
||||
{(pageName == 'editPage') && <GitNavItem brew={currentBrew} lastSavedTime={lastSavedTime} onLinkedChange={setGitLinked} />}
|
||||
<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,10 +1,11 @@
|
||||
import './brewItem.less';
|
||||
import React, { useCallback } from 'react';
|
||||
import React, { useCallback, useState } from 'react';
|
||||
import moment from 'moment';
|
||||
import request from '../../../../utils/request-middleware.js';
|
||||
|
||||
import googleDriveIcon from '../../../../googleDrive.svg';
|
||||
import homebreweryIcon from '../../../../thumbnail.svg';
|
||||
import homebreweryIconWhite from '@themes/assets/naturalCritLogoWhite.svg';
|
||||
import homebreweryIconBlack from '@themes/assets/naturalCritLogoBlack.svg';
|
||||
import dedent from 'dedent';
|
||||
|
||||
const BrewItem = ({
|
||||
@@ -16,9 +17,12 @@ const BrewItem = ({
|
||||
},
|
||||
updateListFilter = ()=>{},
|
||||
reportError = ()=>{},
|
||||
theme,
|
||||
renderStorage = true,
|
||||
})=>{
|
||||
|
||||
const [detailsOpen, setDetailsOpen] = useState(false);
|
||||
|
||||
const deleteBrew = useCallback(()=>{
|
||||
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;
|
||||
@@ -33,15 +37,13 @@ const BrewItem = ({
|
||||
});
|
||||
}, [brew, reportError]);
|
||||
|
||||
const updateFilter = useCallback((type, term)=>updateListFilter(type, term), [updateListFilter]);
|
||||
|
||||
const renderDeleteBrewLink = ()=>{
|
||||
if(!brew.editId) return null;
|
||||
|
||||
return (
|
||||
<a className='deleteLink' onClick={deleteBrew}>
|
||||
<i className='fas fa-trash-alt' title='Delete' />
|
||||
</a>
|
||||
<button aria-label={`Delete ${brew.title}`} className='deleteLink' onClick={deleteBrew}>
|
||||
<i className='fas fa-trash-alt' aria-hidden='true' title='Delete' />
|
||||
</button>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -52,7 +54,7 @@ const BrewItem = ({
|
||||
if(brew.googleId && !brew.stubbed) editLink = brew.googleId + editLink;
|
||||
|
||||
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' />
|
||||
</a>
|
||||
);
|
||||
@@ -67,7 +69,7 @@ const BrewItem = ({
|
||||
}
|
||||
|
||||
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' />
|
||||
</a>
|
||||
);
|
||||
@@ -82,7 +84,7 @@ const BrewItem = ({
|
||||
}
|
||||
|
||||
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' />
|
||||
</a>
|
||||
);
|
||||
@@ -92,17 +94,16 @@ const BrewItem = ({
|
||||
if(!renderStorage) return null;
|
||||
if(brew.googleId) {
|
||||
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'>
|
||||
<img className='googleDriveIcon' src={googleDriveIcon} alt='googleDriveIcon' />
|
||||
<img className='googleDriveIcon' src={googleDriveIcon} alt='Google Drive Storage' />
|
||||
</a>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<span title='Homebrewery Storage'>
|
||||
<img className='homebreweryIcon' src={homebreweryIcon} alt='homebreweryIcon' />
|
||||
<span className='storage' title='Homebrewery Storage'>
|
||||
<img className='homebreweryIcon' src={theme === 'light' ? homebreweryIconBlack : homebreweryIconWhite} alt='Homebrewery Storage' />
|
||||
</span>
|
||||
);
|
||||
};
|
||||
@@ -117,24 +118,23 @@ const BrewItem = ({
|
||||
const dateFormatString = 'YYYY-MM-DD HH:mm:ss';
|
||||
|
||||
return (
|
||||
<div className='brewItem'>
|
||||
<div className={`brewItem${detailsOpen ? ' detailsOpen' : ''}`} onClick={() => setDetailsOpen(!detailsOpen)} >
|
||||
{brew.thumbnail && <div className='thumbnail' style={{ backgroundImage: `url(${brew.thumbnail})` }}></div>}
|
||||
<div className='text'>
|
||||
<h2>{brew.title}</h2>
|
||||
<h2 title={brew.title}>{brew.title}</h2>
|
||||
<p className='description'>{brew.description}</p>
|
||||
</div>
|
||||
<hr />
|
||||
<div className='info'>
|
||||
{brew.tags?.length ? (
|
||||
<div className='brewTags' title={`${brew.tags.length} tags:\n${brew.tags.join('\n')}`}>
|
||||
<i className='fas fa-tags' />
|
||||
{brew.tags.map((tag, idx)=>{
|
||||
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>
|
||||
) : null}
|
||||
<span title={`Authors:\n${brew.authors?.join('\n')}`}>
|
||||
<div className='brewAuthors' title={`Authors:\n${brew.authors?.join('\n')}`}>
|
||||
<i className='fas fa-user' />{' '}
|
||||
{brew.authors?.map((author, index)=>(
|
||||
<React.Fragment key={index}>
|
||||
@@ -146,21 +146,22 @@ const BrewItem = ({
|
||||
{index < brew.authors.length - 1 && ', '}
|
||||
</React.Fragment>
|
||||
))}
|
||||
</span>
|
||||
<br />
|
||||
<span title={`Last viewed: ${moment(brew.lastViewed).local().format(dateFormatString)}`}>
|
||||
<i className='fas fa-eye' /> {brew.views}
|
||||
</span>
|
||||
</div>
|
||||
{brew.pageCount && (
|
||||
<span title={`Page count: ${brew.pageCount}`}>
|
||||
<i className='far fa-file' /> {brew.pageCount}
|
||||
<span className='brewPages' aria-label={`${brew.pageCount} pages`} title={`Page count: ${brew.pageCount}`}>
|
||||
<span aria-hidden='true'><i className='far fa-file' /> {brew.pageCount}</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
|
||||
className='lastUpdated'
|
||||
aria-label={`Last updated ${moment(brew.updatedAt).fromNow()}`}
|
||||
title={dedent` Created: ${moment(brew.createdAt).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>
|
||||
{renderStorageIcon()}
|
||||
</div>
|
||||
|
||||
@@ -1,30 +1,32 @@
|
||||
@import '@sharedStyles/core.less';
|
||||
@import '@themes/assets/assets.less';
|
||||
@import url('https://fonts.googleapis.com/css2?family=Alata&display=swap');
|
||||
|
||||
.brewItem {
|
||||
--bg-clr : #EEEEEE;
|
||||
--bg-image : @backgroundImageAlt;
|
||||
--text-clr : black;
|
||||
--text-shadow-clr : white;
|
||||
--hb-logo: url('@themes/assets/naturalCritLogoBlack.svg');
|
||||
|
||||
position : relative;
|
||||
box-sizing : border-box;
|
||||
display : inline-block;
|
||||
width : 48%;
|
||||
min-height : 105px;
|
||||
padding : 5px 15px 2px 6px;
|
||||
padding-right : 15px;
|
||||
margin-right : 15px;
|
||||
margin-bottom : 15px;
|
||||
display : flex;
|
||||
flex-direction : column;
|
||||
overflow : hidden;
|
||||
vertical-align : top;
|
||||
background-color : #CAB2802E;
|
||||
border : 1px solid #C9AD6A;
|
||||
border-radius : 5px;
|
||||
box-shadow : 0px 4px 5px 0px #333333;
|
||||
font-size : 15px;
|
||||
color : var(--text-clr);
|
||||
background-color : var(--bg-clr);
|
||||
background-image : var(--bg-image);
|
||||
background-size : cover;
|
||||
isolation : isolate;
|
||||
break-inside : avoid;
|
||||
-webkit-column-break-inside : avoid;
|
||||
page-break-inside : avoid;
|
||||
.thumbnail {
|
||||
position : absolute;
|
||||
top : 0;
|
||||
right : 0;
|
||||
right : 30px;
|
||||
z-index : -1;
|
||||
width : 150px;
|
||||
width : 155px;
|
||||
height : 100%;
|
||||
background-repeat : no-repeat;
|
||||
background-position : right top;
|
||||
@@ -34,17 +36,14 @@
|
||||
mask-image : linear-gradient(80deg, #00000000 20%, #005500 40%);
|
||||
}
|
||||
.text {
|
||||
min-height : 54px;
|
||||
h4 {
|
||||
margin-bottom : 5px;
|
||||
font-size : 2.2em;
|
||||
h2 {
|
||||
font-family : 'Alata';
|
||||
font-size : 1.25em;
|
||||
}
|
||||
}
|
||||
.info {
|
||||
position : initial;
|
||||
bottom : 2px;
|
||||
font-family : "ScalySansRemake";
|
||||
font-size : 1.2em;
|
||||
a { color : inherit; }
|
||||
font-size : 0.9em;
|
||||
& > span {
|
||||
margin-right : 12px;
|
||||
line-height : 1.5em;
|
||||
@@ -59,72 +58,404 @@
|
||||
font-weight : bold;
|
||||
white-space : nowrap;
|
||||
cursor : pointer;
|
||||
background-color : #C8AC6E3B;
|
||||
border : 1px solid #C8AC6E;
|
||||
border-color : currentColor;
|
||||
color:black;
|
||||
background : hsl(from currentColor h 20% 80%);
|
||||
border : 1px solid currentColor;
|
||||
border-radius : 4px;
|
||||
|
||||
&::before {
|
||||
margin-right : 3px;
|
||||
font-family : 'Font Awesome 6 Free';
|
||||
font-size : 12px;
|
||||
}
|
||||
--tag-base : #C8AC6E;
|
||||
--tag-type : #008000;
|
||||
--tag-group : #000000;
|
||||
--tag-meta : #000080;
|
||||
--tag-system : #800000;
|
||||
&.type {
|
||||
color : #008000;
|
||||
background-color : #0080003B;
|
||||
color : var(--tag-type);
|
||||
&::before { content : '\f0ad'; }
|
||||
}
|
||||
&.group {
|
||||
color : #000000;
|
||||
background-color : #5050503B;
|
||||
color : var(--tag-group);
|
||||
&::before { content : '\f500'; }
|
||||
}
|
||||
&.meta {
|
||||
color : #000080;
|
||||
background-color : #0000803B;
|
||||
color : var(--tag-meta);
|
||||
&::before { content : '\f05a'; }
|
||||
}
|
||||
&.system {
|
||||
color : #800000;
|
||||
background-color : #8000003B;
|
||||
color : var(--tag-system);
|
||||
&::before { content : '\f518'; }
|
||||
}
|
||||
}
|
||||
&:hover {
|
||||
.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; }
|
||||
}
|
||||
}
|
||||
&:nth-child(2n + 1) { margin-right : 0; }
|
||||
.googleDriveIcon {
|
||||
padding : 0px;
|
||||
margin : -5px;
|
||||
height : 18px;
|
||||
padding : 0;
|
||||
margin : -5px;
|
||||
}
|
||||
.homebreweryIcon {
|
||||
position : relative;
|
||||
padding : 0px;
|
||||
top : 5px;
|
||||
left : -7.5px;
|
||||
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}]*/
|
||||
import './listPage.less';
|
||||
import React from 'react';
|
||||
import createReactClass from 'create-react-class';
|
||||
import _ from 'lodash';
|
||||
import React, { useEffect, useState, useMemo } from 'react';
|
||||
import moment from 'moment';
|
||||
import _ from 'lodash';
|
||||
|
||||
import BrewItem from './brewItem/brewItem.jsx';
|
||||
|
||||
const USERPAGE_SORT_DIR = 'HB_listPage_sortDir';
|
||||
const USERPAGE_SORT_TYPE = 'HB_listPage_sortType';
|
||||
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_DIR = 'asc';
|
||||
const DEFAULT_LAYOUT_MODE = 'grid';
|
||||
const DEFAULT_THEME_MODE = 'light';
|
||||
|
||||
const ListPage = createReactClass({
|
||||
displayName : 'ListPage',
|
||||
getDefaultProps : function() {
|
||||
return {
|
||||
brewCollection : [
|
||||
{
|
||||
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;
|
||||
});
|
||||
const brewSorters = {
|
||||
'alpha' : (brew)=>_.deburr(brew.title).trim().toLowerCase(),
|
||||
'created' : (brew)=>moment(brew.createdAt).format(),
|
||||
'updated' : (brew)=>moment(brew.updatedAt).format(),
|
||||
'views' : (brew)=>brew.views
|
||||
};
|
||||
|
||||
return {
|
||||
filterString : this.props.query?.filter || '',
|
||||
filterTags : [],
|
||||
sortType : this.props.query?.sort || null,
|
||||
sortDir : this.props.query?.dir || null,
|
||||
query : this.props.query,
|
||||
brewCollection : brewCollection
|
||||
};
|
||||
},
|
||||
const ListPage = ({ brewCollection = [{ title: '', class: '', brews: [] }], navItems = <></>, reportError = null, query })=>{
|
||||
const [filterString, setFilterString] = useState(query?.filter || '');
|
||||
const [filterTags, setFilterTags] = useState(query?.tag || []);
|
||||
const [sortType, setSortType] = useState(query?.sort || null);
|
||||
const [sortDir, setSortDir] = useState(query?.dir || null);
|
||||
const [groupVisibility, setGroupVisibility] = useState({});
|
||||
const [layoutMode, setLayoutMode] = useState(DEFAULT_LAYOUT_MODE);
|
||||
const [themeMode, setThemeMode] = useState(DEFAULT_THEME_MODE);
|
||||
|
||||
componentDidMount : function() {
|
||||
// SAVE TO LOCAL STORAGE WHEN LEAVING PAGE
|
||||
window.onbeforeunload = this.saveToLocalStorage;
|
||||
useEffect(()=>{
|
||||
if(typeof window === 'undefined') return;
|
||||
|
||||
// LOAD FROM LOCAL STORAGE
|
||||
if(typeof window !== 'undefined') {
|
||||
const newSortType = (this.state.sortType ?? (localStorage.getItem(USERPAGE_SORT_TYPE) || DEFAULT_SORT_TYPE));
|
||||
const newSortDir = (this.state.sortDir ?? (localStorage.getItem(USERPAGE_SORT_DIR) || DEFAULT_SORT_DIR));
|
||||
this.updateUrl(this.state.filterString, newSortType, newSortDir);
|
||||
const newSortType = sortType ?? (localStorage.getItem(USERPAGE_SORT_TYPE) || DEFAULT_SORT_TYPE);
|
||||
const newSortDir = sortDir ?? (localStorage.getItem(USERPAGE_SORT_DIR) || DEFAULT_SORT_DIR);
|
||||
const newLayoutMode = localStorage.getItem(USERPAGE_LAYOUT_MODE) || DEFAULT_LAYOUT_MODE;
|
||||
const newThemeMode = localStorage.getItem(USERPAGE_THEME_MODE) || DEFAULT_THEME_MODE;
|
||||
|
||||
const brewCollection = this.props.brewCollection.map((brewGroup)=>{
|
||||
brewGroup.visible = (localStorage.getItem(`${USERPAGE_GROUP_VISIBILITY_PREFIX}_${brewGroup.class}`) ?? 'true')=='true';
|
||||
return brewGroup;
|
||||
});
|
||||
const initialGroupVisibility = brewCollection.reduce((visibility, brewGroup)=>{
|
||||
visibility[brewGroup.class] = (localStorage.getItem(`${USERPAGE_GROUP_VISIBILITY_PREFIX}_${brewGroup.class}`) ?? 'true') == 'true';
|
||||
return visibility;
|
||||
}, {});
|
||||
|
||||
this.setState({
|
||||
brewCollection : brewCollection,
|
||||
sortType : newSortType,
|
||||
sortDir : newSortDir
|
||||
});
|
||||
};
|
||||
},
|
||||
setGroupVisibility(initialGroupVisibility);
|
||||
setSortType(newSortType);
|
||||
setSortDir(newSortDir);
|
||||
setLayoutMode(newLayoutMode);
|
||||
setThemeMode(newThemeMode);
|
||||
|
||||
componentWillUnmount : function() {
|
||||
window.onbeforeunload = function(){};
|
||||
},
|
||||
updateUrl(filterString, newSortType, newSortDir, filterTags);
|
||||
}, []);
|
||||
|
||||
saveToLocalStorage : function() {
|
||||
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 updateUrl = (filterTerm, sortType, sortDir, filterTags)=>{
|
||||
const url = new URL(window.location.href);
|
||||
const urlParams = new URLSearchParams(url.search);
|
||||
|
||||
urlParams.set('sort', sortType);
|
||||
urlParams.set('dir', sortDir);
|
||||
url.searchParams.set('sort', sortType);
|
||||
url.searchParams.set('dir', sortDir);
|
||||
|
||||
let filterTags = urlParams.getAll('tag');
|
||||
if(filterTag != '') {
|
||||
if(filterTags.findIndex((tag)=>{return tag.toLowerCase()==filterTag.toLowerCase();}) == -1){
|
||||
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());
|
||||
});
|
||||
// Add tags to URL in alphabetical order
|
||||
url.searchParams.delete('tag');
|
||||
filterTags.forEach((tag)=>url.searchParams.append('tag', tag));
|
||||
|
||||
this.setState({
|
||||
filterTags
|
||||
});
|
||||
if(!filterTerm) url.searchParams.delete('filter');
|
||||
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);
|
||||
},
|
||||
};
|
||||
|
||||
renderFilterOption : function(){
|
||||
return <div className='filter-option'>
|
||||
const renderBrews = (brews)=>{
|
||||
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>
|
||||
<i className='fas fa-search'></i>
|
||||
<input
|
||||
type='search'
|
||||
placeholder='filter title/description'
|
||||
onChange={this.handleFilterTextChange}
|
||||
value={this.state.filterString}
|
||||
/>
|
||||
<input type='search' placeholder='filter title/description/tags' onChange={handleFilterTextChange} value={filterString} />
|
||||
</label>
|
||||
</div>;
|
||||
},
|
||||
</div>
|
||||
);
|
||||
|
||||
renderTagsOptions : function(){
|
||||
if(this.state.filterTags?.length == 0) return;
|
||||
return <div className='tags-container'>
|
||||
{_.map(this.state.filterTags, (tag, idx)=>{
|
||||
const matches = tag.match(/^(?:([^:]+):)?([^:]+)$/);
|
||||
return <span key={idx} className={matches[1]} onClick={()=>{ this.updateUrl(this.state.filterString, this.state.sortType, this.state.sortDir, tag); }}>{matches[2]}</span>;
|
||||
})}
|
||||
</div>;
|
||||
},
|
||||
|
||||
renderSortOptions : function(){
|
||||
return <div className='sort-container'>
|
||||
<h6>Sort by :</h6>
|
||||
{this.renderSortOption('Title', 'alpha')}
|
||||
{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>
|
||||
const renderTagsOptions = ()=>{
|
||||
if(!filterTags.length) return;
|
||||
return (
|
||||
<div className='tags-container'>
|
||||
Tags:
|
||||
{filterTags.map((tag, idx)=>{
|
||||
const matches = tag.match(/^(?:([^:]+):)?([^:]+)$/);
|
||||
return (
|
||||
<span
|
||||
key={idx}
|
||||
className={matches[1]}
|
||||
onClick={()=>handleFilterTagChange(tag)}>
|
||||
{matches[2]}
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>;
|
||||
}
|
||||
});
|
||||
);
|
||||
};
|
||||
|
||||
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() {
|
||||
column-count : auto;
|
||||
column-fill : auto;
|
||||
column-gap : normal;
|
||||
-webkit-column-width : auto;
|
||||
-moz-column-width : auto;
|
||||
column-width : auto;
|
||||
-webkit-column-count : auto;
|
||||
-moz-column-count : auto;
|
||||
-webkit-column-width : auto;
|
||||
-moz-column-width : auto;
|
||||
column-count : auto;
|
||||
column-fill : auto;
|
||||
-webkit-column-gap : normal;
|
||||
-moz-column-gap : normal;
|
||||
column-gap : normal;
|
||||
height : auto;
|
||||
min-height : 279.4mm;
|
||||
margin : 20px auto;
|
||||
contain : unset;
|
||||
}
|
||||
.listPage {
|
||||
|
||||
.sitePage.listPage {
|
||||
--bg-clr : white;
|
||||
container-type: inline-size;
|
||||
.content {
|
||||
z-index : 1;
|
||||
.page {
|
||||
.noColumns() !important; //Needed to override PHB Theme since this is on a lower @layer
|
||||
&::after { display : none; }
|
||||
.noBrews {
|
||||
margin : 10px 0px;
|
||||
font-size : 1.3em;
|
||||
font-style : italic;
|
||||
padding : clamp(20px, 5vh, 200px) clamp(20px, 20cqi, 200px);
|
||||
overflow-y : scroll;
|
||||
scrollbar-gutter : stable;
|
||||
@container (max-width : 1200px) {
|
||||
padding : clamp(20px, 5vh, 200px) clamp(20px, 10cqi, 200px);
|
||||
}
|
||||
@container (max-width : 800px) {
|
||||
padding : clamp(20px, 5vh, 200px) clamp(20px, 5cqi, 200px);
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width : 15px;
|
||||
&:horizontal {
|
||||
width : auto;
|
||||
height : 20px;
|
||||
}
|
||||
.brewCollection {
|
||||
h1:hover { cursor : pointer; }
|
||||
.active::before, .inactive::before {
|
||||
&-thumb {
|
||||
background : linear-gradient(90deg, var(--bg-clr) 12px, #00000000 12px);
|
||||
&: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;
|
||||
font-family : 'Font Awesome 6 Free';
|
||||
font-size : 0.6cm;
|
||||
font-weight : 900;
|
||||
}
|
||||
.active { color : var(--HB_Color_HeaderText); }
|
||||
.active::before { content : '\f107'; }
|
||||
.inactive { color : #707070; }
|
||||
.inactive::before { content : '\f105'; }
|
||||
&.active {
|
||||
color : white;
|
||||
&::before { content : '\f107'; }
|
||||
}
|
||||
&.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;
|
||||
top : 0;
|
||||
left : 0;
|
||||
z-index : 1;
|
||||
display : flex;
|
||||
flex-wrap : wrap;
|
||||
row-gap : 5px;
|
||||
column-gap : 15px;
|
||||
align-items : baseline;
|
||||
justify-content : center;
|
||||
width : 100%;
|
||||
height : 30px;
|
||||
font-family : 'Open Sans', sans-serif;
|
||||
color : white;
|
||||
text-align : center;
|
||||
background-color : #555555;
|
||||
border-top : 1px solid #666666;
|
||||
border-bottom : 1px solid #666666;
|
||||
h6 {
|
||||
font-family : 'Open Sans', sans-serif;
|
||||
font-size : 11px;
|
||||
font-weight : bold;
|
||||
text-transform : uppercase;
|
||||
|
||||
.listPageNav {
|
||||
position : relative;
|
||||
display : flex;
|
||||
flex-wrap : wrap;
|
||||
row-gap : 10px;
|
||||
column-gap : 20px;
|
||||
align-items : center;
|
||||
justify-content : center;
|
||||
width : 100%;
|
||||
height : fit-content;
|
||||
font-family : 'Open Sans', sans-serif;
|
||||
color : white;
|
||||
background : #555555;
|
||||
border-top : 1px solid #666666;
|
||||
border-bottom : 1px solid #666666;
|
||||
row-rule : 1px solid #666666;
|
||||
|
||||
> div {
|
||||
width : fit-content;
|
||||
height : 30px;
|
||||
padding-inline : 10px;
|
||||
}
|
||||
.sort-option {
|
||||
display : flex;
|
||||
align-items : center;
|
||||
height : 100%;
|
||||
padding : 0 8px;
|
||||
color : #CCCCCC;
|
||||
|
||||
&:hover { background-color : #444444; }
|
||||
|
||||
&.active {
|
||||
font-weight : bold;
|
||||
color : #DDDDDD;
|
||||
background-color : #333333;
|
||||
|
||||
button {
|
||||
height : 100%;
|
||||
font-weight : 800;
|
||||
color : white;
|
||||
& + .sortDir { padding-left : 5px; }
|
||||
}
|
||||
.radio-toggle {
|
||||
z-index : 1;
|
||||
display : flex;
|
||||
flex-wrap : wrap;
|
||||
row-gap : 5px;
|
||||
align-items : center;
|
||||
justify-content : center;
|
||||
text-align : center;
|
||||
h6 {
|
||||
font-size : 14px;
|
||||
margin-right: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 {
|
||||
margin-left : 20px;
|
||||
display : grid;
|
||||
place-items : center;
|
||||
font-size : 11px;
|
||||
background-color : transparent !important;
|
||||
i { padding-right : 5px; }
|
||||
}
|
||||
button {
|
||||
padding : 0;
|
||||
font-family : 'Open Sans', sans-serif;
|
||||
font-size : 11px;
|
||||
font-weight : normal;
|
||||
color : #CCCCCC;
|
||||
text-transform : uppercase;
|
||||
background-color : transparent;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
.tags-container {
|
||||
display : flex;
|
||||
flex-wrap : wrap;
|
||||
row-gap : 5px;
|
||||
column-gap : 15px;
|
||||
align-items : center;
|
||||
justify-content : center;
|
||||
height : 30px;
|
||||
color : white;
|
||||
background-color : #555555;
|
||||
border-top : 1px solid #666666;
|
||||
border-bottom : 1px solid #666666;
|
||||
span {
|
||||
padding : 3px;
|
||||
font-family : 'Open Sans', sans-serif;
|
||||
font-size : 11px;
|
||||
font-weight : bold;
|
||||
color : #DFDFDF;
|
||||
cursor : pointer;
|
||||
border : 1px solid;
|
||||
border-radius : 3px;
|
||||
&::before {
|
||||
margin-right : 3px;
|
||||
font-family : 'Font Awesome 6 Free';
|
||||
font-size : 12px;
|
||||
}
|
||||
&::after {
|
||||
margin-left : 3px;
|
||||
font-family : 'Font Awesome 6 Free';
|
||||
font-size : 12px;
|
||||
content : '\f00d';
|
||||
}
|
||||
&.type {
|
||||
background-color : #008000;
|
||||
border-color : #00A000;
|
||||
&::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'; }
|
||||
.tags-container {
|
||||
display : flex;
|
||||
flex-wrap : wrap;
|
||||
row-gap : 5px;
|
||||
column-gap : 15px;
|
||||
align-items : center;
|
||||
justify-content : center;
|
||||
height : 30px;
|
||||
span {
|
||||
padding : 3px;
|
||||
font-family : 'Open Sans', sans-serif;
|
||||
font-size : 11px;
|
||||
font-weight : bold;
|
||||
color : #DFDFDF;
|
||||
cursor : pointer;
|
||||
border : 1px solid;
|
||||
border-radius : 3px;
|
||||
&::before {
|
||||
margin-right : 3px;
|
||||
font-family : 'Font Awesome 6 Free';
|
||||
font-size : 12px;
|
||||
}
|
||||
&::after {
|
||||
margin-left : 3px;
|
||||
font-family : 'Font Awesome 6 Free';
|
||||
font-size : 12px;
|
||||
content : '\f00d';
|
||||
}
|
||||
&.type {
|
||||
background-color : #008000;
|
||||
border-color : #00A000;
|
||||
&::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,7 +1,4 @@
|
||||
import './uiPage.less';
|
||||
import React from 'react';
|
||||
import createReactClass from 'create-react-class';
|
||||
|
||||
import Nav from '../../../navbar/nav.jsx';
|
||||
import Navbar from '../../../navbar/navbar.jsx';
|
||||
import NewBrewItem from '../../../navbar/newbrew.navitem.jsx';
|
||||
@@ -10,30 +7,22 @@ import RecentNavItems from '../../../navbar/recent.navitem.jsx';
|
||||
const { both: RecentNavItem } = RecentNavItems;
|
||||
import Account from '../../../navbar/account.navitem.jsx';
|
||||
|
||||
const UIPage = ({ brew, children })=><div className='sitePage uiPage'>
|
||||
<Navbar>
|
||||
<Nav.section>
|
||||
<Nav.item className='brewTitle'>{brew?.title}</Nav.item>
|
||||
</Nav.section>
|
||||
<Nav.section>
|
||||
<NewBrewItem />
|
||||
<HelpNavItem />
|
||||
<RecentNavItem />
|
||||
<Account />
|
||||
</Nav.section>
|
||||
</Navbar>
|
||||
|
||||
const UIPage = createReactClass({
|
||||
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>;
|
||||
}
|
||||
});
|
||||
<div className='content'>
|
||||
{children}
|
||||
</div>
|
||||
</div>;
|
||||
|
||||
export default UIPage;
|
||||
@@ -1,55 +1,15 @@
|
||||
/* eslint-disable max-lines */
|
||||
import './editPage.less';
|
||||
|
||||
// Common imports
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import request from '../../utils/request-middleware.js';
|
||||
import Markdown from '@shared/markdown.js';
|
||||
import _ from 'lodash';
|
||||
|
||||
import { DEFAULT_BREW_LOAD } from '../../../../server/brewDefaults.js';
|
||||
import { printCurrentBrew, fetchThemeBundle } from '@shared/helpers.js';
|
||||
|
||||
import SplitPane from '../../../components/splitPane/splitPane.jsx';
|
||||
import Editor from '../../editor/editor.jsx';
|
||||
import BrewRenderer from '../../brewRenderer/brewRenderer.jsx';
|
||||
|
||||
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 RecentNavItems from '@navbar/recent.navitem.jsx';
|
||||
const { both: RecentNavItem } = RecentNavItems;
|
||||
import React from 'react';
|
||||
import request from '../../utils/request-middleware.js';
|
||||
import _ from 'lodash';
|
||||
import EditorPage from '../basePages/editPage/editorPage.jsx';
|
||||
import { DEFAULT_BREW_LOAD } from '../../../../server/brewDefaults.js';
|
||||
|
||||
// Page specific imports
|
||||
import Headtags from '../../../../vitreum/headtags.js';
|
||||
const Meta = Headtags.Meta;
|
||||
import { md5 } from 'hash-wasm';
|
||||
import { gzipSync, strToU8 } from 'fflate';
|
||||
import { makePatches, stringifyPatches } from '@sanity/diff-match-patch';
|
||||
|
||||
import ShareNavItem from '@navbar/share.navitem.jsx';
|
||||
import LockNotification from './lockNotification/lockNotification.jsx';
|
||||
import { consumeGitOverwrite } from '../../../fork/git/gitApi.js'; // [fork] ADR-0003
|
||||
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)=>{
|
||||
props = {
|
||||
@@ -57,364 +17,47 @@ const EditPage = (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(null); // 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)=>{
|
||||
setHTMLErrors(Markdown.validate(brew.text));
|
||||
|
||||
await updateHistory(brew).catch(console.error);
|
||||
await versionHistoryGarbageCollection().catch(console.error);
|
||||
|
||||
//Prepare content to send to server
|
||||
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.normalize('NFC')),
|
||||
textBin : undefined,
|
||||
version : lastSavedBrew.current.version
|
||||
};
|
||||
|
||||
const compressedBrew = gzipSync(strToU8(JSON.stringify(brewToSave)));
|
||||
const compressedBrew = gzipSync(strToU8(JSON.stringify(brew)));
|
||||
const transfer = saveToGoogle === _.isNil(brew.googleId);
|
||||
const params = transfer ? `?${saveToGoogle ? 'saveToGoogle' : 'removeFromGoogle'}=true` : '';
|
||||
const gitOverwrite = consumeGitOverwrite(); // [fork] ADR-0003: nur nach "Meine Version behalten"
|
||||
const params = [transfer && `${saveToGoogle ? 'saveToGoogle' : 'removeFromGoogle'}=true`, gitOverwrite && `gitOverwrite=${encodeURIComponent(gitOverwrite)}`].filter(Boolean).join('&');
|
||||
|
||||
const res = await request
|
||||
.put(`/api/update/${brewToSave.editId}${params}`)
|
||||
.put(`/api/update/${brew.editId}${params ? `?${params}` : ''}`)
|
||||
.set('Content-Encoding', 'gzip')
|
||||
.set('Content-Type', 'application/json')
|
||||
.send(compressedBrew)
|
||||
.catch((err)=>{
|
||||
console.error('Error Updating Local Brew');
|
||||
setError(err);
|
||||
});
|
||||
if(!res) return;
|
||||
.send(compressedBrew);
|
||||
|
||||
const updatedFields = {
|
||||
googleId : res.body.googleId ?? null,
|
||||
editId : res.body.editId,
|
||||
googleId : res.body.googleId ?? null, //TODO: investigate if we can set googleId:null in server/update instead of undefined
|
||||
editId : res.body.editId, //then, editPage can just apply res.body instead of breaking out these fields.
|
||||
shareId : res.body.shareId,
|
||||
version : res.body.version
|
||||
};
|
||||
|
||||
lastSavedBrew.current = {
|
||||
...brew,
|
||||
...updatedFields
|
||||
};
|
||||
|
||||
setCurrentBrew((prevBrew)=>({
|
||||
...prevBrew,
|
||||
...updatedFields
|
||||
}));
|
||||
|
||||
history.replaceState(null, null, `/edit/${res.body.editId}`);
|
||||
return updatedFields;
|
||||
};
|
||||
|
||||
const renderGoogleDriveIcon = ()=>(
|
||||
<Nav.item className='googleDriveStorage' onClick={handleGoogleClick}>
|
||||
<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>;
|
||||
const onSaveSuccess = (savedBrew)=>{
|
||||
history.replaceState(null, null, `/edit/${savedBrew.editId}`);;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='editPage sitePage'>
|
||||
<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={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>
|
||||
);
|
||||
<EditorPage
|
||||
useLocalStorage = {false}
|
||||
sandbox = {false}
|
||||
showFloatingButtons = {false}
|
||||
showEditorButtons = {true}
|
||||
pageName = {'editPage'}
|
||||
brew = {props.brew}
|
||||
userThemes = {props.userThemes}
|
||||
save = {save}
|
||||
onSaveSuccess = {onSaveSuccess}
|
||||
></EditorPage>);
|
||||
};
|
||||
|
||||
export default EditPage;
|
||||
@@ -1,7 +1,7 @@
|
||||
import './lockNotification.less';
|
||||
import * as React from 'react';
|
||||
import request from '../../../utils/request-middleware.js';
|
||||
import Dialog from '../../../../components/dialog.jsx';
|
||||
import Dialog from '@components/dialog.jsx';
|
||||
|
||||
function LockNotification(props) {
|
||||
props = {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import './errorPage.less';
|
||||
import React from 'react';
|
||||
import UIPage from '../basePages/uiPage/uiPage.jsx';
|
||||
import Markdown from '@shared/markdown.js';
|
||||
import { hbfm } from 'marked-hbfm';
|
||||
import ErrorIndex from './errors/errorIndex.js';
|
||||
|
||||
const ErrorPage = ({ brew })=>{
|
||||
@@ -16,7 +16,7 @@ const ErrorPage = ({ brew })=>{
|
||||
<h4>{brew?.text || 'No error text'}</h4>
|
||||
</div>
|
||||
<hr />
|
||||
<div dangerouslySetInnerHTML={{ __html: Markdown.render(errorText) }} />
|
||||
<div dangerouslySetInnerHTML={{ __html: hbfm.render(errorText) }} />
|
||||
</div>
|
||||
</UIPage>
|
||||
);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import dedent from 'dedent';
|
||||
|
||||
const loginUrl = 'https://www.naturalcrit.com/login';
|
||||
import { getLoginUrl } from '../../../../fork/auth/loginUrl.js';
|
||||
|
||||
// Prevent parsing text (e.g. document titles) as markdown
|
||||
const escape = (text = '')=>{
|
||||
@@ -105,7 +104,7 @@ const errorIndex = (props)=>{
|
||||
## Sign-in required to edit this brew.
|
||||
|
||||
You must be logged in to one of the accounts listed as an author of this brew.
|
||||
User is not logged in. Please log in [here](${loginUrl}).
|
||||
User is not logged in. Please log in [here](${getLoginUrl()}).
|
||||
|
||||
:
|
||||
|
||||
@@ -208,7 +207,7 @@ const errorIndex = (props)=>{
|
||||
|
||||
You are trying to access the account page, but are not signed in to an account.
|
||||
|
||||
Please login or signup at our [login page](https://www.naturalcrit.com/login?redirect=https://homebrewery.naturalcrit.com/account).`,
|
||||
Please login or signup at our [login page](${getLoginUrl('/account')}).`,
|
||||
|
||||
// Brew locked by Administrators error
|
||||
'51' : dedent`
|
||||
|
||||
@@ -1,236 +1,42 @@
|
||||
|
||||
import './homePage.less';
|
||||
|
||||
// Common imports
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import request from '../../utils/request-middleware.js';
|
||||
import Markdown from '@shared/markdown.js';
|
||||
import _ from 'lodash';
|
||||
|
||||
import { DEFAULT_BREW } from '../../../../server/brewDefaults.js';
|
||||
import { printCurrentBrew, fetchThemeBundle } from '@shared/helpers.js';
|
||||
|
||||
import SplitPane from '../../../components/splitPane/splitPane.jsx';
|
||||
import Editor from '../../editor/editor.jsx';
|
||||
import BrewRenderer from '../../brewRenderer/brewRenderer.jsx';
|
||||
|
||||
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 RecentNavItems from '@navbar/recent.navitem.jsx';
|
||||
const { both: RecentNavItem } = RecentNavItems;
|
||||
|
||||
|
||||
// Page specific imports
|
||||
import Headtags from '@vitreum/headtags.js';
|
||||
const Meta = Headtags.Meta;
|
||||
|
||||
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;
|
||||
import React from 'react';
|
||||
import request from '../../utils/request-middleware.js';
|
||||
import _ from 'lodash';
|
||||
import EditorPage from '../basePages/editPage/editorPage.jsx';
|
||||
import { DEFAULT_BREW } from '../../../../server/brewDefaults.js';
|
||||
|
||||
const HomePage =(props)=>{
|
||||
props = {
|
||||
brew : DEFAULT_BREW,
|
||||
ver : '0.0.0',
|
||||
...props
|
||||
};
|
||||
|
||||
const [currentBrew, setCurrentBrew] = useState(props.brew);
|
||||
const [error, setError] = useState(undefined);
|
||||
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 [isSaving, setIsSaving] = useState(false);
|
||||
const [autoSaveEnabled, setAutoSaveEnable] = useState(false);
|
||||
const save = async (brew, saveToGoogle)=>{
|
||||
const res = await request
|
||||
.post(`/api${saveToGoogle ? '?saveToGoogle=true' : ''}`)
|
||||
.send(brew);
|
||||
|
||||
const editorRef = useRef(null);
|
||||
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}`;
|
||||
});
|
||||
return res.body;
|
||||
};
|
||||
|
||||
useEffect(()=>{
|
||||
const hasChange = !_.isEqual(currentBrew, lastSavedBrew.current);
|
||||
setUnsavedChanges(hasChange);
|
||||
|
||||
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>;
|
||||
const onSaveSuccess = (savedBrew)=>{
|
||||
window.onbeforeunload = null;
|
||||
window.location = `/edit/${savedBrew.editId}`;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='homePage sitePage'>
|
||||
<Meta name='google-site-verification' content='NwnAQSSJZzAT7N-p5MY6ydQ7Njm67dtbu73ZSyE5Fy4' />
|
||||
{renderNavbar()}
|
||||
<div className='content'>
|
||||
<SplitPane onDragFinish={handleSplitMove}>
|
||||
<Editor
|
||||
ref={editorRef}
|
||||
brew={currentBrew}
|
||||
onBrewChange={handleBrewChange}
|
||||
renderer={currentBrew.renderer}
|
||||
showEditButtons={false}
|
||||
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>
|
||||
);
|
||||
<EditorPage
|
||||
useLocalStorage = {false}
|
||||
sandbox = {true}
|
||||
showFloatingButtons = {true}
|
||||
showEditorButtons = {false}
|
||||
pageName = {'homePage'}
|
||||
brew = {props.brew}
|
||||
userThemes = {{}}
|
||||
save = {save}
|
||||
onSaveSuccess = {onSaveSuccess}
|
||||
></EditorPage>);
|
||||
};
|
||||
|
||||
export default HomePage;
|
||||
@@ -37,14 +37,14 @@
|
||||
|
||||
.navItem.save {
|
||||
background-color : @orange;
|
||||
transition:all 0.2s;
|
||||
transition : all 0.2s;
|
||||
&:hover { background-color : @green; }
|
||||
|
||||
&.neverSaved {
|
||||
translate:-100%;
|
||||
opacity: 0;
|
||||
background-color :#333;
|
||||
cursor:auto;
|
||||
cursor : auto;
|
||||
background-color : #333333;
|
||||
opacity : 0;
|
||||
translate : -100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,10 @@
|
||||
/* eslint-disable max-lines */
|
||||
import './newPage.less';
|
||||
|
||||
// Common imports
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import request from '../../utils/request-middleware.js';
|
||||
import Markdown from '@shared/markdown.js';
|
||||
import _ from 'lodash';
|
||||
|
||||
import { DEFAULT_BREW } from '../../../../server/brewDefaults.js';
|
||||
import { printCurrentBrew, fetchThemeBundle, splitTextStyleAndMetadata } from '@shared/helpers.js';
|
||||
|
||||
import SplitPane from '../../../components/splitPane/splitPane.jsx';
|
||||
import Editor from '../../editor/editor.jsx';
|
||||
import BrewRenderer from '../../brewRenderer/brewRenderer.jsx';
|
||||
|
||||
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 RecentNavItems from '@navbar/recent.navitem.jsx';
|
||||
const { both: RecentNavItem } = RecentNavItems;
|
||||
|
||||
// Page specific imports
|
||||
|
||||
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;
|
||||
import React from 'react';
|
||||
import request from '../../utils/request-middleware.js';
|
||||
import _ from 'lodash';
|
||||
import EditorPage from '../basePages/editPage/editorPage.jsx';
|
||||
import { DEFAULT_BREW } from '../../../../server/brewDefaults.js';
|
||||
|
||||
const NewPage = (props)=>{
|
||||
props = {
|
||||
@@ -42,238 +12,31 @@ const NewPage = (props)=>{
|
||||
...props
|
||||
};
|
||||
|
||||
const [currentBrew, setCurrentBrew] = useState(props.brew);
|
||||
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(null); // 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 save = async (brew, saveToGoogle)=>{
|
||||
const res = await request
|
||||
.post(`/api${saveGoogle ? '?saveToGoogle=true' : ''}`)
|
||||
.send(updatedBrew)
|
||||
.catch((err)=>{
|
||||
setIsSaving(false);
|
||||
setError(err);
|
||||
});
|
||||
.post(`/api${saveToGoogle ? '?saveToGoogle=true' : ''}`)
|
||||
.send(brew);
|
||||
|
||||
setIsSaving(false);
|
||||
if(!res) return;
|
||||
return res.body;
|
||||
};
|
||||
|
||||
const savedBrew = res.body;
|
||||
|
||||
localStorage.removeItem(BREWKEY);
|
||||
localStorage.removeItem(STYLEKEY);
|
||||
localStorage.removeItem(METAKEY);
|
||||
const onSaveSuccess = (savedBrew)=>{
|
||||
window.onbeforeunload = null;
|
||||
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 (
|
||||
<div className='newPage sitePage'>
|
||||
{renderNavbar()}
|
||||
<div className='content'>
|
||||
<SplitPane onDragFinish={handleSplitMove}>
|
||||
<Editor
|
||||
ref={editorRef}
|
||||
brew={currentBrew}
|
||||
onBrewChange={handleBrewChange}
|
||||
renderer={currentBrew.renderer}
|
||||
userThemes={props.userThemes}
|
||||
themeBundle={themeBundle}
|
||||
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>
|
||||
);
|
||||
<EditorPage
|
||||
useLocalStorage = {true}
|
||||
sandbox = {true}
|
||||
showFloatingButtons = {false}
|
||||
showEditorButtons = {true}
|
||||
pageName = {'newPage'}
|
||||
brew = {props.brew}
|
||||
userThemes = {props.userThemes}
|
||||
save = {save}
|
||||
onSaveSuccess = {onSaveSuccess}
|
||||
></EditorPage>);
|
||||
};
|
||||
|
||||
export default NewPage;
|
||||
@@ -3,14 +3,14 @@
|
||||
.newPage {
|
||||
.navItem.save {
|
||||
background-color : @orange;
|
||||
transition:all 0.2s;
|
||||
transition : all 0.2s;
|
||||
&:hover { background-color : @green; }
|
||||
|
||||
&.neverSaved {
|
||||
translate:-100%;
|
||||
opacity: 0;
|
||||
background-color :#333;
|
||||
cursor:auto;
|
||||
cursor : auto;
|
||||
background-color : #333333;
|
||||
opacity : 0;
|
||||
translate : -100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,12 +12,15 @@ const { both: RecentNavItem } = RecentNavItems;
|
||||
import Account from '@navbar/account.navitem.jsx';
|
||||
import BrewRenderer from '../../brewRenderer/brewRenderer.jsx';
|
||||
|
||||
import request from '../../utils/request-middleware.js';
|
||||
|
||||
import { DEFAULT_BREW_LOAD } from '../../../../server/brewDefaults.js';
|
||||
import { printCurrentBrew, fetchThemeBundle } from '@shared/helpers.js';
|
||||
|
||||
const SharePage = (props)=>{
|
||||
const { brew = DEFAULT_BREW_LOAD, disableMeta = false } = props;
|
||||
const { disableMeta = false } = props;
|
||||
|
||||
const [currentBrew, setCurrentBrew] = useState(props.brew || DEFAULT_BREW_LOAD);
|
||||
const [themeBundle, setThemeBundle] = useState({});
|
||||
const [currentBrewRendererPageNum, setCurrentBrewRendererPageNum] = useState(1);
|
||||
|
||||
@@ -35,23 +38,51 @@ const SharePage = (props)=>{
|
||||
}
|
||||
};
|
||||
|
||||
const fetchUpdatedBrew = async ()=>{
|
||||
const response = await request
|
||||
.get(`/api/fetch/${currentBrew.shareId}`)
|
||||
.catch((error)=>{
|
||||
console.log('error at fetching updated brew: ', error);
|
||||
});
|
||||
if(response.ok && !!response.body.brew) {
|
||||
setCurrentBrew(response.body.brew);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(()=>{
|
||||
document.addEventListener('keydown', handleControlKeys);
|
||||
fetchThemeBundle(undefined, setThemeBundle, brew.renderer, brew.theme);
|
||||
fetchThemeBundle(undefined, setThemeBundle, currentBrew.renderer, currentBrew.theme);
|
||||
|
||||
let eventSource;
|
||||
// Start a stream if the brew has been updated in the last month
|
||||
if(Date.parse(props.brew?.updatedAt) > (new Date).setDate((new Date).getDate() - 30)){
|
||||
// listen for changes in the brew version
|
||||
eventSource = new EventSource(`/api/stream/${props.brew.shareId}`);
|
||||
|
||||
eventSource.addEventListener('brewUpdated', (evt)=>{
|
||||
const messageData = JSON.parse(evt.data);
|
||||
|
||||
if(messageData.version != currentBrew.version) {
|
||||
console.log('should fetch brew');
|
||||
fetchUpdatedBrew();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return ()=>{
|
||||
document.removeEventListener('keydown', handleControlKeys);
|
||||
eventSource?.close();
|
||||
};
|
||||
}, []);
|
||||
|
||||
const processShareId = ()=>{
|
||||
return brew.googleId && !brew.stubbed ? brew.googleId + brew.shareId : brew.shareId;
|
||||
return currentBrew.googleId && !currentBrew.stubbed ? currentBrew.googleId + currentBrew.shareId : currentBrew.shareId;
|
||||
};
|
||||
|
||||
const renderEditLink = ()=>{
|
||||
if(!brew.editId) return null;
|
||||
if(!currentBrew.editId) return null;
|
||||
|
||||
const editLink = brew.googleId && ! brew.stubbed ? brew.googleId + brew.editId : brew.editId;
|
||||
const editLink = currentBrew.googleId && ! currentBrew.stubbed ? currentBrew.googleId + currentBrew.editId : currentBrew.editId;
|
||||
|
||||
return (
|
||||
<Nav.item color='orange' icon='fas fa-pencil-alt' href={`/edit/${editLink}`}>
|
||||
@@ -62,7 +93,7 @@ const SharePage = (props)=>{
|
||||
|
||||
const titleEl = (
|
||||
<Nav.item className='brewTitle' style={disableMeta ? { cursor: 'default' } : {}}>
|
||||
{brew.title}
|
||||
{currentBrew.title}
|
||||
</Nav.item>
|
||||
);
|
||||
|
||||
@@ -71,11 +102,11 @@ const SharePage = (props)=>{
|
||||
<Meta name='robots' content='noindex, nofollow' />
|
||||
<Navbar>
|
||||
<Nav.section className='titleSection'>
|
||||
{disableMeta ? titleEl : <MetadataNav brew={brew}>{titleEl}</MetadataNav>}
|
||||
{disableMeta ? titleEl : <MetadataNav brew={currentBrew}>{titleEl}</MetadataNav>}
|
||||
</Nav.section>
|
||||
|
||||
<Nav.section>
|
||||
{brew.shareId && (
|
||||
{currentBrew.shareId && (
|
||||
<>
|
||||
<PrintNavItem />
|
||||
<Nav.dropdown>
|
||||
@@ -92,24 +123,36 @@ const SharePage = (props)=>{
|
||||
<Nav.item color='blue' icon='fas fa-clone' href={`/new/${processShareId()}`}>
|
||||
clone to new
|
||||
</Nav.item>
|
||||
<Nav.item
|
||||
color='blue'
|
||||
icon='fas fa-link'
|
||||
onClick={()=>{navigator.clipboard.writeText(`${global.config.baseUrl}/share/${processShareId()}`);}}>
|
||||
copy url
|
||||
</Nav.item>
|
||||
{currentBrewRendererPageNum > 1 &&
|
||||
<Nav.item
|
||||
color='blue'
|
||||
icon='fas fa-hashtag'
|
||||
onClick={()=>{navigator.clipboard.writeText(`${global.config.baseUrl}/share/${processShareId()}#p${currentBrewRendererPageNum}`);}}>
|
||||
copy url (page {currentBrewRendererPageNum})
|
||||
</Nav.item>}
|
||||
</Nav.dropdown>
|
||||
</>
|
||||
)}
|
||||
<RecentNavItem brew={brew} storageKey='view' />
|
||||
<RecentNavItem brew={currentBrew} storageKey='view' />
|
||||
<Account />
|
||||
</Nav.section>
|
||||
</Navbar>
|
||||
|
||||
<div className='content'>
|
||||
<BrewRenderer
|
||||
text={brew.text}
|
||||
style={brew.style}
|
||||
lang={brew.lang}
|
||||
renderer={brew.renderer}
|
||||
theme={brew.theme}
|
||||
text={currentBrew.text}
|
||||
style={currentBrew.style}
|
||||
lang={currentBrew.lang}
|
||||
renderer={currentBrew.renderer}
|
||||
theme={currentBrew.theme}
|
||||
themeBundle={themeBundle}
|
||||
onPageChange={handleBrewRendererPageChange}
|
||||
currentBrewRendererPageNum={currentBrewRendererPageNum}
|
||||
allowPrint={true}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -11,11 +11,18 @@ import Account from '@navbar/account.navitem.jsx';
|
||||
import NewBrew from '@navbar/newbrew.navitem.jsx';
|
||||
import HelpNavItem from '@navbar/help.navitem.jsx';
|
||||
import BrewItem from '../basePages/listPage/brewItem/brewItem.jsx';
|
||||
import SplitPane from '../../../components/splitPane/splitPane.jsx';
|
||||
import SplitPane from '@components/splitPane/splitPane.jsx';
|
||||
import ErrorIndex from '../errorPage/errors/errorIndex.js';
|
||||
|
||||
import request from '../../utils/request-middleware.js';
|
||||
|
||||
const DEFAULT_SORT_TYPE = 'alpha';
|
||||
const DEFAULT_SORT_DIR = 'asc';
|
||||
const DEFAULT_LAYOUT_MODE = 'grid';
|
||||
const DEFAULT_THEME_MODE = 'light';
|
||||
const USERPAGE_LAYOUT_MODE = 'HB_listPage_layout_mode';
|
||||
const USERPAGE_THEME_MODE = 'HB_listPage_theme_mode';
|
||||
|
||||
const VaultPage = (props)=>{
|
||||
const [pageState, setPageState] = useState(parseInt(props.query.page) || 1);
|
||||
|
||||
@@ -27,6 +34,8 @@ const VaultPage = (props)=>{
|
||||
const [totalBrews, setTotalBrews] = useState(null);
|
||||
const [searching, setSearching] = useState(false);
|
||||
const [error, setError] = useState(null);
|
||||
const [layoutMode, setLayoutMode] = useState(DEFAULT_LAYOUT_MODE);
|
||||
const [themeMode, setThemeMode] = useState(DEFAULT_THEME_MODE);
|
||||
|
||||
const titleRef = useRef(null);
|
||||
const authorRef = useRef(null);
|
||||
@@ -37,6 +46,13 @@ const VaultPage = (props)=>{
|
||||
|
||||
useEffect(()=>{
|
||||
disableSubmitIfFormInvalid();
|
||||
|
||||
const newLayoutMode = localStorage.getItem(USERPAGE_LAYOUT_MODE) || DEFAULT_LAYOUT_MODE;
|
||||
const newThemeMode = localStorage.getItem(USERPAGE_THEME_MODE) || DEFAULT_THEME_MODE;
|
||||
|
||||
setLayoutMode(newLayoutMode);
|
||||
setThemeMode(newThemeMode);
|
||||
|
||||
loadPage(pageState, true, props.query.sort, props.query.dir);
|
||||
}, []);
|
||||
|
||||
@@ -74,7 +90,7 @@ const VaultPage = (props)=>{
|
||||
updateStateWithBrews([], 1);
|
||||
});
|
||||
|
||||
if(response.ok)
|
||||
if(response?.ok)
|
||||
updateStateWithBrews(response.body.brews, page);
|
||||
};
|
||||
|
||||
@@ -83,7 +99,8 @@ const VaultPage = (props)=>{
|
||||
|
||||
const response = await request.get(`/api/vault/total?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}`)
|
||||
.catch((error)=>{
|
||||
console.log('error at loadTotal: ', error);
|
||||
console.log('error at loadTotal: ');
|
||||
console.error(error);
|
||||
setError(error);
|
||||
updateStateWithBrews([], 1);
|
||||
});
|
||||
@@ -261,7 +278,7 @@ const VaultPage = (props)=>{
|
||||
const oppositeDir = dirState === 'asc' ? 'desc' : 'asc';
|
||||
|
||||
return (
|
||||
<div className={`sort-option ${sortState === optionValue ? `active` : ''}`}>
|
||||
<div className={`option ${sortState === optionValue ? `active` : ''}`}>
|
||||
<button onClick={()=>loadPage(1, false, optionValue, oppositeDir)}>
|
||||
{optionTitle}
|
||||
</button>
|
||||
@@ -272,10 +289,10 @@ const VaultPage = (props)=>{
|
||||
);
|
||||
};
|
||||
|
||||
const renderSortBar = ()=>{
|
||||
const renderSortOptions = ()=>{
|
||||
|
||||
return (
|
||||
<div className='sort-container'>
|
||||
<div className='radio-toggle sort-container'>
|
||||
{renderSortOption('Title', 'title', props.query.dir)}
|
||||
{renderSortOption('Created Date', 'createdAt', props.query.dir)}
|
||||
{renderSortOption('Updated Date', 'updatedAt', props.query.dir)}
|
||||
@@ -284,6 +301,64 @@ const VaultPage = (props)=>{
|
||||
);
|
||||
};
|
||||
|
||||
const handleLayoutChange = (e, mode)=>{
|
||||
setLayoutMode(e.target.checked ? mode : DEFAULT_LAYOUT_MODE);
|
||||
localStorage.setItem(USERPAGE_LAYOUT_MODE, e.target.checked ? mode : DEFAULT_LAYOUT_MODE);
|
||||
return;
|
||||
};
|
||||
const renderLayoutModeOptions = ()=>{
|
||||
return (
|
||||
<div className='radio-toggle layout-container'>
|
||||
<h6>View:</h6>
|
||||
<label className='option' title='grid'>
|
||||
<input name='layout-mode' type='radio' onChange={(e)=>handleLayoutChange(e, 'grid')} checked={layoutMode === 'grid'} />
|
||||
<i className='fac compressed-grid'></i>
|
||||
</label>
|
||||
<label className='option' title='list'>
|
||||
<input name='layout-mode' type='radio' onChange={(e)=>handleLayoutChange(e, 'list')} checked={layoutMode === 'list'} />
|
||||
<i className='fas fa-bars'></i>
|
||||
</label>
|
||||
<label className='option' title='card'>
|
||||
<input name='layout-mode' type='radio' onChange={(e)=>handleLayoutChange(e, 'card')} checked={layoutMode === 'card'} />
|
||||
<i className='fac format-card'></i>
|
||||
</label>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
const handleThemeChange = (e, mode)=>{
|
||||
setThemeMode(e.target.checked ? mode : DEFAULT_THEME_MODE);
|
||||
localStorage.setItem(USERPAGE_THEME_MODE, e.target.checked ? mode : DEFAULT_THEME_MODE);
|
||||
return;
|
||||
};
|
||||
|
||||
const renderThemePicker = ()=>{
|
||||
return (
|
||||
<div className="radio-toggle theme-container">
|
||||
<h6>Theme:</h6>
|
||||
<label className="option">
|
||||
<input type="radio" name="theme" onChange={(e)=>handleThemeChange(e, 'light')} checked={themeMode === 'light'}/>
|
||||
<i className="fas fa-sun"/>
|
||||
</label>
|
||||
<label className="option">
|
||||
<input type="radio" name="theme" onChange={(e)=>handleThemeChange(e, 'dark')} checked={themeMode === 'dark'}/>
|
||||
<i className="fas fa-moon"/>
|
||||
</label>
|
||||
</div>
|
||||
)
|
||||
};
|
||||
|
||||
|
||||
const renderNav = () =>{
|
||||
return (
|
||||
<div className="listPageNav">
|
||||
{renderLayoutModeOptions()}
|
||||
{renderThemePicker()}
|
||||
{renderSortOptions()}
|
||||
</div>
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
const renderPaginationControls = ()=>{
|
||||
if(!totalBrews || totalBrews < 10) return null;
|
||||
|
||||
@@ -364,13 +439,23 @@ const VaultPage = (props)=>{
|
||||
}
|
||||
|
||||
if(error) {
|
||||
const errorText = ErrorIndex()[error.HBErrorCode.toString()] || '';
|
||||
if(error.HBErrorCode === undefined) {
|
||||
return (
|
||||
<div className='foundBrews noBrews'>
|
||||
<h3>Error: Unknown error</h3>
|
||||
</div>
|
||||
)
|
||||
} else {
|
||||
|
||||
return (
|
||||
<div className='foundBrews noBrews'>
|
||||
const errorText = ErrorIndex()[error.HBErrorCode.toString()] || '';
|
||||
|
||||
return (
|
||||
<div className='foundBrews noBrews'>
|
||||
<h3>Error: {errorText}</h3>
|
||||
</div>
|
||||
);
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!brewCollection) {
|
||||
@@ -390,22 +475,26 @@ const VaultPage = (props)=>{
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='foundBrews'>
|
||||
<div className={`foundBrews ${themeMode + 'Mode'}`}>
|
||||
<span className='totalBrews'>
|
||||
{`Brews found: `}
|
||||
<span>{totalBrews}</span>
|
||||
</span>
|
||||
{brewCollection.length > 10 && renderPaginationControls()}
|
||||
{brewCollection.map((brew, index)=>{
|
||||
return (
|
||||
<BrewItem
|
||||
brew={{ ...brew }}
|
||||
key={index}
|
||||
reportError={props.reportError}
|
||||
renderStorage={false}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
<div className='brewCollection'>
|
||||
<div className={`brewGroup ${layoutMode}`}>
|
||||
{brewCollection.map((brew, index)=>{
|
||||
return (
|
||||
<BrewItem
|
||||
brew={{ ...brew }}
|
||||
key={index}
|
||||
reportError={props.reportError}
|
||||
renderStorage={false}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
{renderPaginationControls()}
|
||||
</div>
|
||||
);
|
||||
@@ -420,7 +509,7 @@ const VaultPage = (props)=>{
|
||||
<SplitPane showDividerButtons={false}>
|
||||
<div className='form dataGroup'>{renderForm()}</div>
|
||||
<div className='resultsContainer dataGroup'>
|
||||
{renderSortBar()}
|
||||
{renderNav()}
|
||||
{renderFoundBrews()}
|
||||
</div>
|
||||
</SplitPane>
|
||||
|
||||
@@ -1,22 +1,38 @@
|
||||
@import '@themes/assets/assets.less';
|
||||
@import '@sharedStyles/core.less';
|
||||
|
||||
.vaultPage {
|
||||
height : 100%;
|
||||
overflow-y : hidden;
|
||||
|
||||
--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;
|
||||
|
||||
*:not(input) { user-select : none; }
|
||||
|
||||
.form {
|
||||
background:white;
|
||||
}
|
||||
.form { background : white; }
|
||||
|
||||
:where(.content .dataGroup) {
|
||||
width : 100%;
|
||||
height : 100%;
|
||||
|
||||
&.form .brewLookup {
|
||||
color : var(--label-clr);
|
||||
background-color : var(--bg-clr);
|
||||
background-image : var(--bg-image);
|
||||
background-size : cover;
|
||||
height:100%;
|
||||
|
||||
position : relative;
|
||||
padding : 50px clamp(20px, 4vw, 50px);
|
||||
|
||||
|
||||
small {
|
||||
font-size : 10pt;
|
||||
@@ -35,6 +51,7 @@
|
||||
h1, h2, h3, h4 {
|
||||
font-family : 'CodeBold';
|
||||
letter-spacing : 2px;
|
||||
color : var(--h1-clr);
|
||||
}
|
||||
|
||||
legend {
|
||||
@@ -89,14 +106,14 @@
|
||||
align-items : center;
|
||||
margin : 10px 0;
|
||||
}
|
||||
select { margin : 0 10px; }
|
||||
|
||||
input {
|
||||
input[type='text'], textarea, select {
|
||||
margin : 0 10px;
|
||||
|
||||
&:invalid { background : rgb(255, 188, 181); }
|
||||
|
||||
|
||||
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); }
|
||||
&:invalid { background : #ffbcb5; }
|
||||
}
|
||||
|
||||
#searchButton {
|
||||
@@ -119,69 +136,40 @@
|
||||
height : 100%;
|
||||
overflow-y : auto;
|
||||
font-size : 0.34cm;
|
||||
|
||||
h3 {
|
||||
font-family : 'Open Sans';
|
||||
font-weight : 900;
|
||||
color : white;
|
||||
}
|
||||
|
||||
.sort-container {
|
||||
display : flex;
|
||||
flex-wrap : wrap;
|
||||
column-gap : 15px;
|
||||
justify-content : center;
|
||||
height : 30px;
|
||||
color : white;
|
||||
background-color : #555555;
|
||||
border-top : 1px solid #666666;
|
||||
border-bottom : 1px solid #666666;
|
||||
|
||||
.sort-option {
|
||||
display : flex;
|
||||
align-items : center;
|
||||
padding : 0 8px;
|
||||
|
||||
&:hover { background-color : #444444; }
|
||||
|
||||
&.active {
|
||||
background-color : #333333;
|
||||
|
||||
button {
|
||||
font-weight : 800;
|
||||
color : white;
|
||||
|
||||
& + .sortDir { padding-left : 5px; }
|
||||
}
|
||||
}
|
||||
|
||||
button {
|
||||
padding : 0;
|
||||
font-size : 11px;
|
||||
font-weight : normal;
|
||||
color : #CCCCCC;
|
||||
text-transform : uppercase;
|
||||
background-color : transparent;
|
||||
|
||||
&:hover { background : none; }
|
||||
}
|
||||
}
|
||||
}
|
||||
container-type : inline-size;
|
||||
|
||||
.foundBrews {
|
||||
position : relative;
|
||||
width : 100%;
|
||||
height : 100%;
|
||||
max-height : 100%;
|
||||
padding : 70px 50px;
|
||||
display:flex;
|
||||
flex-direction: column;
|
||||
gap:20px;
|
||||
padding : clamp(20px, 5vh, 200px) clamp(20px, 20vw, 200px);
|
||||
overflow-y : scroll;
|
||||
container-type : inline-size;
|
||||
scrollbar-gutter : stable;
|
||||
@container (max-width : 1200px) {
|
||||
padding : clamp(20px, 5vh, 200px) clamp(20px, 10vw, 200px);
|
||||
}
|
||||
@container (max-width : 800px) {
|
||||
padding : clamp(20px, 5vh, 200px) clamp(20px, 5vw, 200px);
|
||||
}
|
||||
|
||||
h3 { font-size : 25px; }
|
||||
&::-webkit-scrollbar {
|
||||
width : 15px;
|
||||
&:horizontal {
|
||||
width : auto;
|
||||
height : 20px;
|
||||
}
|
||||
&-thumb {
|
||||
background : linear-gradient(90deg, var(--bg-clr) 12px, #00000000 12px);
|
||||
&:horizontal { background : linear-gradient(0deg, var(--bg-clr) 15px, #00000000 15px); }
|
||||
}
|
||||
&-corner { visibility : hidden; }
|
||||
}
|
||||
|
||||
&.noBrews {
|
||||
display : grid;
|
||||
place-items : center;
|
||||
margin : 10px 0px;
|
||||
font-size : 25px;
|
||||
font-style : italic;
|
||||
font-weight : 900;
|
||||
color : white;
|
||||
}
|
||||
|
||||
@@ -204,6 +192,64 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.brewCollection {
|
||||
h1 {
|
||||
width : fit-content;
|
||||
margin-bottom : 20px;
|
||||
font-size : 25px;
|
||||
color : #DDDDDD;
|
||||
|
||||
&.active::before,
|
||||
&.inactive::before {
|
||||
padding-right : 0.5em;
|
||||
font-family : 'Font Awesome 6 Free';
|
||||
font-size : 0.6cm;
|
||||
font-weight : 900;
|
||||
}
|
||||
&.active {
|
||||
color : white;
|
||||
&::before { content : '\f107'; }
|
||||
}
|
||||
&.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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.totalBrews {
|
||||
position : fixed;
|
||||
right : 0;
|
||||
@@ -235,66 +281,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
.brewItem {
|
||||
width : 47%;
|
||||
margin-right : 40px;
|
||||
color : black;
|
||||
isolation : isolate;
|
||||
transition : width 0.5s;
|
||||
|
||||
&::after {
|
||||
position : absolute;
|
||||
inset : 0;
|
||||
z-index : -2;
|
||||
display : block;
|
||||
content : '';
|
||||
background-image : url('/assets/parchmentBackground.jpg');
|
||||
}
|
||||
|
||||
&:nth-child(even of .brewItem) { margin-right : 0; }
|
||||
|
||||
h2 {
|
||||
font-family : 'MrEavesRemake';
|
||||
font-size : 0.75cm;
|
||||
font-weight : 800;
|
||||
line-height : 0.988em;
|
||||
color : var(--HB_Color_HeaderText);
|
||||
}
|
||||
.info {
|
||||
position : relative;
|
||||
z-index : 2;
|
||||
font-family : 'ScalySansRemake';
|
||||
font-size : 1.2em;
|
||||
|
||||
>span {
|
||||
margin-right : 12px;
|
||||
line-height : 1.5em;
|
||||
}
|
||||
}
|
||||
.links { z-index : 2; }
|
||||
|
||||
hr {
|
||||
visibility : hidden;
|
||||
margin : 0px;
|
||||
}
|
||||
|
||||
.thumbnail { z-index : -1; }
|
||||
}
|
||||
|
||||
.paginationControls {
|
||||
position : absolute;
|
||||
top : 35px;
|
||||
left : 50%;
|
||||
display : grid;
|
||||
grid-template-areas : 'previousPage currentPage nextPage';
|
||||
grid-template-columns : 50px 1fr 50px;
|
||||
gap : 20px;
|
||||
place-items : center;
|
||||
width : auto;
|
||||
width : fit-content;
|
||||
margin-inline:auto;
|
||||
font-size : 15px;
|
||||
translate : -50%;
|
||||
|
||||
&:last-child { top : unset; }
|
||||
|
||||
.pages {
|
||||
display : flex;
|
||||
@@ -316,8 +311,11 @@
|
||||
text-underline-position : under;
|
||||
cursor : pointer;
|
||||
|
||||
&.currentPage {
|
||||
&:hover {
|
||||
color : gold;
|
||||
}
|
||||
&.currentPage {
|
||||
color:@yellow;
|
||||
text-decoration : underline;
|
||||
pointer-events : none;
|
||||
}
|
||||
@@ -341,6 +339,77 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.listPageNav {
|
||||
position : relative;
|
||||
display : flex;
|
||||
flex-wrap : wrap;
|
||||
row-gap : 10px;
|
||||
column-gap : 20px;
|
||||
align-items : center;
|
||||
justify-content : center;
|
||||
width : 100%;
|
||||
height : fit-content;
|
||||
font-family : 'Open Sans', sans-serif;
|
||||
color : white;
|
||||
background : #555555;
|
||||
border-top : 1px solid #666666;
|
||||
border-bottom : 1px solid #666666;
|
||||
row-rule : 1px solid #666666;
|
||||
|
||||
> div {
|
||||
width : fit-content;
|
||||
height : 30px;
|
||||
padding-inline : 10px;
|
||||
}
|
||||
|
||||
.radio-toggle {
|
||||
z-index : 1;
|
||||
display : flex;
|
||||
flex-wrap : wrap;
|
||||
row-gap : 5px;
|
||||
align-items : center;
|
||||
justify-content : center;
|
||||
text-align : center;
|
||||
h6 {
|
||||
margin-right : 5px;
|
||||
font-size : 14px;
|
||||
}
|
||||
|
||||
.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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes trailingDots {
|
||||
@@ -353,16 +422,4 @@
|
||||
|
||||
66%,
|
||||
100% { content : ' ...'; }
|
||||
}
|
||||
|
||||
@container (width < 670px) {
|
||||
.vaultPage {
|
||||
|
||||
.dataGroup.form .brewLookup { padding : 1px 20px 20px 10px; }
|
||||
|
||||
.dataGroup.resultsContainer .foundBrews .brewItem {
|
||||
width : 100%;
|
||||
margin-inline : auto;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg id="Layer_2" data-name="Layer 2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 399.76 400.41">
|
||||
<g id="Layer_1-2" data-name="Layer 1">
|
||||
<rect width="183.16" height="77.61" rx="16.76" ry="16.76"/>
|
||||
<rect y="107.6" width="183.16" height="77.61" rx="16.76" ry="16.76"/>
|
||||
<rect y="215.2" width="183.16" height="77.61" rx="16.76" ry="16.76"/>
|
||||
<rect y="322.8" width="183.16" height="77.61" rx="16.76" ry="16.76"/>
|
||||
<rect x="216.6" width="183.16" height="77.61" rx="16.76" ry="16.76"/>
|
||||
<rect x="216.6" y="107.6" width="183.16" height="77.61" rx="16.76" ry="16.76"/>
|
||||
<rect x="216.6" y="215.2" width="183.16" height="77.61" rx="16.76" ry="16.76"/>
|
||||
<rect x="216.6" y="322.8" width="183.16" height="77.61" rx="16.76" ry="16.76"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 807 B |
@@ -32,3 +32,5 @@
|
||||
.single-spread { mask-image : url('../icons/single-spread.svg'); }
|
||||
.facing-spread { mask-image : url('../icons/facing-spread.svg'); }
|
||||
.flow-spread { mask-image : url('../icons/flow-spread.svg'); }
|
||||
.format-card { mask-image: url('../icons/format-card.svg'); }
|
||||
.compressed-grid { mask-image: url('../icons//compressed-grid.svg'); }
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg id="Layer_2" data-name="Layer 2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 324.38 433.46" width="324.38" height="433.46" xml:space="preserve">
|
||||
<g id="Layer_2-2" data-name="Layer 2">
|
||||
<path d="M267.61,0H56.77C25.42,0,0,25.42,0,56.77v319.92c0,31.35,25.42,56.77,56.77,56.77h210.84c31.35,0,56.77-25.42,56.77-56.77V56.77c0-31.35-25.42-56.77-56.77-56.77ZM94.52,45.62c12.6,0,22.81,10.21,22.81,22.81s-10.21,22.81-22.81,22.81-22.81-10.21-22.81-22.81,10.21-22.81,22.81-22.81ZM73.06,187.38l34.38-57.2c4.29-7.14,14.6-7.26,19.05-.22l7.7,12.17c1.02,1.61,3.36,1.65,4.44.08l31.31-45.56c4.44-6.45,13.96-6.47,18.42-.04l62.23,89.65c5.3,7.63-.16,18.07-9.45,18.07H82.65c-8.7.01-14.07-9.49-9.59-16.95ZM258.24,388.61H67.91c-6.8,0-12.31-5.51-12.31-12.31s5.51-12.31,12.31-12.31h190.33c6.8,0,12.31,5.51,12.31,12.31s-5.51,12.31-12.31,12.31ZM258.24,348.81H67.91c-6.8,0-12.31-5.51-12.31-12.31s5.51-12.31,12.31-12.31h190.33c6.8,0,12.31,5.51,12.31,12.31s-5.51,12.31-12.31,12.31ZM258.24,309H67.91c-6.8,0-12.31-5.51-12.31-12.31s5.51-12.31,12.31-12.31h190.33c6.8,0,12.31,5.51,12.31,12.31s-5.51,12.31-12.31,12.31Z"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
+3
-2
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"development": true,
|
||||
"development_style": false,
|
||||
"host" : "homebrewery.local.naturalcrit.com:8000",
|
||||
"naturalcrit_url" : "local.naturalcrit.com:8010",
|
||||
"secret" : "secret",
|
||||
@@ -7,5 +7,6 @@
|
||||
"local_environments" : ["docker", "local"],
|
||||
"publicUrl" : "https://homebrewery.naturalcrit.com",
|
||||
"hb_images" : null,
|
||||
"hb_fonts" : null
|
||||
"hb_fonts" : null,
|
||||
"enablev4" : true
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
# Wird von `docker compose` automatisch zusätzlich zu docker-compose.yml (Upstream) geladen.
|
||||
# Enthält alle Fork-Erweiterungen, damit docker-compose.yml unverändert bleibt.
|
||||
services:
|
||||
mongodb:
|
||||
image: mongo:${MONGO_TAG:-8}
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "mongosh --quiet --eval \"db.adminCommand('ping')\" || mongo --quiet --eval \"db.adminCommand('ping')\""]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
homebrewery:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: docker/Dockerfile
|
||||
depends_on:
|
||||
mongodb:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
# Storage-Backend (ADR 0002): mongo (Standard) oder postgres. Postgres: Compose-Profil `postgres`, Service `homebrewery-pg`.
|
||||
HB_DB_DRIVER: ${HB_DB_DRIVER:-mongo}
|
||||
MONGODB_URI: ${MONGODB_URI:-mongodb://mongodb/homebrewery}
|
||||
# Auth (ADR 0001). Leer lassen = Upstream-Verhalten (nur naturalcrit-Login). Siehe docs/auth/.
|
||||
HB_AUTH_PROVIDERS: ${HB_AUTH_PROVIDERS:-}
|
||||
HB_PUBLIC_URL: ${HB_PUBLIC_URL:-}
|
||||
HB_OIDC_ISSUER: ${HB_OIDC_ISSUER:-}
|
||||
HB_OIDC_CLIENT_ID: ${HB_OIDC_CLIENT_ID:-}
|
||||
HB_OIDC_CLIENT_SECRET: ${HB_OIDC_CLIENT_SECRET:-}
|
||||
HB_OIDC_SCOPES: ${HB_OIDC_SCOPES:-}
|
||||
HB_OIDC_USERNAME_CLAIM: ${HB_OIDC_USERNAME_CLAIM:-}
|
||||
HB_OIDC_LINK_BY_EMAIL: ${HB_OIDC_LINK_BY_EMAIL:-}
|
||||
HB_OIDC_END_SESSION: ${HB_OIDC_END_SESSION:-}
|
||||
HB_OIDC_LABEL: ${HB_OIDC_LABEL:-}
|
||||
HB_SESSION_SECRET: ${HB_SESSION_SECRET:-}
|
||||
HB_SESSION_TTL: ${HB_SESSION_TTL:-}
|
||||
HB_NATURALCRIT_RENAME: ${HB_NATURALCRIT_RENAME:-}
|
||||
# Git-Backend (ADR 0003, docs/git/). Ohne HB_GIT_TOKEN_KEY ist es deaktiviert.
|
||||
HB_GIT_TOKEN_KEY: ${HB_GIT_TOKEN_KEY:-}
|
||||
HB_GIT_TOKEN_KEYS_OLD: ${HB_GIT_TOKEN_KEYS_OLD:-}
|
||||
HB_GIT_ALLOWED_HOSTS: ${HB_GIT_ALLOWED_HOSTS:-}
|
||||
HB_GIT_ALLOW_PRIVATE: ${HB_GIT_ALLOW_PRIVATE:-}
|
||||
HB_GIT_ALLOW_HTTP: ${HB_GIT_ALLOW_HTTP:-}
|
||||
HB_GIT_TIMEOUT_MS: ${HB_GIT_TIMEOUT_MS:-}
|
||||
HB_GIT_OPEN_TIMEOUT_MS: ${HB_GIT_OPEN_TIMEOUT_MS:-}
|
||||
HB_GIT_MAX_FILE_BYTES: ${HB_GIT_MAX_FILE_BYTES:-}
|
||||
HB_GIT_MAX_CONCURRENCY: ${HB_GIT_MAX_CONCURRENCY:-}
|
||||
HB_GIT_COMMITTER_NAME: ${HB_GIT_COMMITTER_NAME:-}
|
||||
HB_GIT_COMMITTER_EMAIL: ${HB_GIT_COMMITTER_EMAIL:-}
|
||||
# Bild-Upload (ADR 0004, nur mit aktivem Git-Backend)
|
||||
HB_ASSETS_ENABLED: ${HB_ASSETS_ENABLED:-}
|
||||
HB_ASSET_MAX_BYTES: ${HB_ASSET_MAX_BYTES:-}
|
||||
HB_ASSET_MAX_BYTES_PER_BREW: ${HB_ASSET_MAX_BYTES_PER_BREW:-}
|
||||
HB_ASSET_TYPES: ${HB_ASSET_TYPES:-}
|
||||
ports: !override
|
||||
- "${APP_PORT:-8000}:8000"
|
||||
|
||||
# --- Profil: postgres (ADR 0002) ---
|
||||
# Startet die App mit PostgreSQL 18 ohne Mongo:
|
||||
# docker compose --profile postgres up --build homebrewery-pg
|
||||
# (Die Service-Namen müssen angegeben werden, sonst startet Compose zusätzlich `homebrewery` und `mongodb`.)
|
||||
homebrewery-pg:
|
||||
profiles: ["postgres"]
|
||||
extends:
|
||||
service: homebrewery
|
||||
image: homebrewery
|
||||
depends_on: !override
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
HB_DB_DRIVER: postgres
|
||||
HB_POSTGRES_URL: ${HB_POSTGRES_URL:-postgres://${POSTGRES_USER:-homebrewery}:${POSTGRES_PASSWORD:-homebrewery-dev}@postgres:5432/${POSTGRES_DB:-homebrewery}}
|
||||
HB_POSTGRES_POOL_MAX: ${HB_POSTGRES_POOL_MAX:-10}
|
||||
postgres:
|
||||
profiles: ["postgres"]
|
||||
image: postgres:18
|
||||
environment:
|
||||
POSTGRES_DB: ${POSTGRES_DB:-homebrewery}
|
||||
POSTGRES_USER: ${POSTGRES_USER:-homebrewery}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-homebrewery-dev}
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql
|
||||
ports:
|
||||
- "127.0.0.1:${POSTGRES_PORT:-5432}:5432"
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
|
||||
# --- Profil: keycloak (Test-IdP, Realm "homebrewery") ---
|
||||
keycloak:
|
||||
profiles: ["keycloak"]
|
||||
image: quay.io/keycloak/keycloak:${KEYCLOAK_TAG:-26.4}
|
||||
command: ["start-dev", "--import-realm"]
|
||||
environment:
|
||||
KC_BOOTSTRAP_ADMIN_USERNAME: ${KEYCLOAK_ADMIN:-admin}
|
||||
KC_BOOTSTRAP_ADMIN_PASSWORD: ${KEYCLOAK_ADMIN_PASSWORD:-admin-dev}
|
||||
KC_HTTP_PORT: ${KEYCLOAK_PORT:-8080}
|
||||
# Einheitlicher Issuer für Browser (Host) und App-Container: http://keycloak.localhost:<KEYCLOAK_PORT>
|
||||
KC_HOSTNAME: http://keycloak.localhost:${KEYCLOAK_PORT:-8080}
|
||||
volumes:
|
||||
- ./docker/keycloak/realm-homebrewery.json:/opt/keycloak/data/import/realm-homebrewery.json:ro
|
||||
ports:
|
||||
- "127.0.0.1:${KEYCLOAK_PORT:-8080}:${KEYCLOAK_PORT:-8080}"
|
||||
networks:
|
||||
default:
|
||||
aliases: [keycloak.localhost]
|
||||
|
||||
# --- Profil: authentik (Test-IdP, per Blueprint vorkonfiguriert) ---
|
||||
authentik-db:
|
||||
profiles: ["authentik"]
|
||||
image: postgres:18
|
||||
environment:
|
||||
POSTGRES_DB: authentik
|
||||
POSTGRES_USER: authentik
|
||||
POSTGRES_PASSWORD: ${AUTHENTIK_DB_PASSWORD:-authentik-dev}
|
||||
volumes:
|
||||
- authentikdb:/var/lib/postgresql
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U authentik -d authentik"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
authentik:
|
||||
profiles: ["authentik"]
|
||||
image: ghcr.io/goauthentik/server:${AUTHENTIK_TAG:-2026.2}
|
||||
command: server
|
||||
environment: &authentik-env
|
||||
AUTHENTIK_SECRET_KEY: ${AUTHENTIK_SECRET_KEY:-dev-only-insecure-secret-key-change-me}
|
||||
AUTHENTIK_POSTGRESQL__HOST: authentik-db
|
||||
AUTHENTIK_POSTGRESQL__USER: authentik
|
||||
AUTHENTIK_POSTGRESQL__NAME: authentik
|
||||
AUTHENTIK_POSTGRESQL__PASSWORD: ${AUTHENTIK_DB_PASSWORD:-authentik-dev}
|
||||
AUTHENTIK_BOOTSTRAP_PASSWORD: ${AUTHENTIK_BOOTSTRAP_PASSWORD:-admin-dev}
|
||||
AUTHENTIK_BOOTSTRAP_EMAIL: admin@example.test
|
||||
AUTHENTIK_ERROR_REPORTING__ENABLED: "false"
|
||||
AUTHENTIK_LISTEN__HTTP: 0.0.0.0:${AUTHENTIK_PORT:-9000}
|
||||
volumes:
|
||||
- ./docker/authentik/blueprints:/blueprints/custom:ro
|
||||
ports:
|
||||
- "127.0.0.1:${AUTHENTIK_PORT:-9000}:${AUTHENTIK_PORT:-9000}"
|
||||
# Einheitlicher Issuer: http://authentik.localhost:9000 (Browser und App-Container)
|
||||
networks:
|
||||
default:
|
||||
aliases: [authentik.localhost]
|
||||
depends_on:
|
||||
authentik-db:
|
||||
condition: service_healthy
|
||||
authentik-worker:
|
||||
profiles: ["authentik"]
|
||||
image: ghcr.io/goauthentik/server:${AUTHENTIK_TAG:-2026.2}
|
||||
command: worker
|
||||
environment: *authentik-env
|
||||
volumes:
|
||||
- ./docker/authentik/blueprints:/blueprints/custom:ro
|
||||
depends_on:
|
||||
authentik-db:
|
||||
condition: service_healthy
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
authentikdb:
|
||||
@@ -0,0 +1,11 @@
|
||||
# Eigenes Dockerfile für den Fork (Upstream-Dockerfile erwartet eine nicht eingecheckte config/docker.json).
|
||||
FROM node:26.4.0-alpine
|
||||
RUN apk --no-cache add git
|
||||
ENV NODE_ENV=docker
|
||||
WORKDIR /usr/src/app
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci --ignore-scripts
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
EXPOSE 8000
|
||||
CMD [ "npm", "start" ]
|
||||
@@ -0,0 +1,10 @@
|
||||
node_modules
|
||||
npm-debug.log
|
||||
.git
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
.npm-cache
|
||||
.runtime-tmp
|
||||
tests
|
||||
docker-compose*.yml
|
||||
Loaded 100 of 263 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user