├── .gitignore ├── .nvmrc ├── .prettierignore ├── .prettierrc.yaml ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── lerna.json ├── package.json ├── packages ├── login │ ├── README.md │ ├── package.json │ ├── src │ │ └── index.tsx │ └── tsconfig.json ├── manager │ ├── .env │ ├── .gitignore │ ├── README.md │ ├── netlify.toml │ ├── package.json │ ├── public │ │ ├── favicon.ico │ │ ├── index.html │ │ └── manifest.json │ ├── src │ │ ├── backend │ │ │ └── auth-callback.js │ │ ├── common │ │ │ └── oauth-config.js │ │ ├── frontend │ │ │ ├── App.test.js │ │ │ ├── App.tsx │ │ │ ├── Repository │ │ │ │ ├── Add.tsx │ │ │ │ ├── Edit.tsx │ │ │ │ └── List.tsx │ │ │ └── common │ │ │ │ └── usePromise.ts │ │ ├── index.js │ │ ├── react-app-env.d.ts │ │ ├── serviceWorker.js │ │ └── theme.js │ ├── tsconfig.json │ └── yarn.lock ├── template │ ├── README.md │ ├── index.html │ └── very-nested-data.json ├── viewer │ ├── .env │ ├── .storybook │ │ ├── config.js │ │ └── main.js │ ├── README.md │ ├── docs │ │ └── Intro.stories.mdx │ ├── package.json │ ├── public │ │ ├── baseFolder │ │ │ └── files │ │ │ │ ├── Screen Shot 2020-07-11 at 9.42.39 am.png │ │ │ │ └── example.md │ │ ├── very-nested-data.json │ │ └── youtube.json │ ├── src │ │ ├── Viewer │ │ │ ├── FixedToolbar.tsx │ │ │ ├── ItemNode.tsx │ │ │ ├── Node.tsx │ │ │ ├── TimelineNode.tsx │ │ │ ├── ToolbarButton.tsx │ │ │ ├── ToolbarUploadButton.tsx │ │ │ ├── Viewer.stories.tsx │ │ │ ├── Viewer.test.tsx │ │ │ ├── array-util.ts │ │ │ ├── duck.ts │ │ │ ├── emptyState.json │ │ │ ├── examples │ │ │ │ ├── cookingExample.json │ │ │ │ ├── file-example.json │ │ │ │ ├── timelineExample.json │ │ │ │ └── youtube.json │ │ │ ├── index.tsx │ │ │ └── isHref.ts │ │ ├── WebViewer │ │ │ ├── WebViewer.stories.tsx │ │ │ ├── index.tsx │ │ │ └── theme.js │ │ ├── index.ts │ │ └── react-app-env.d.ts │ ├── tsconfig.json │ └── webpack.config.js └── website │ ├── .eslintrc │ ├── .gitignore │ ├── .nvmrc │ ├── README.md │ ├── gatsby-config.js │ ├── netlify.toml │ ├── package.json │ ├── src │ ├── components │ │ ├── Header │ │ │ └── index.tsx │ │ └── ViewerContainer │ │ │ └── index.tsx │ ├── gatsby-plugin-theme-ui │ │ └── index.js │ └── pages │ │ ├── examples │ │ ├── data │ │ │ └── youtube.json │ │ └── youtube.tsx │ │ ├── get-started.js │ │ └── index.js │ └── yarn.lock ├── tsconfig.json └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | node_modules 5 | .pnp 6 | .pnp.js 7 | 8 | # testing 9 | coverage 10 | 11 | # production 12 | build 13 | dist 14 | 15 | # misc 16 | .DS_Store 17 | .env.local 18 | .env.development.local 19 | .env.test.local 20 | .env.production.local 21 | 22 | npm-debug.log* 23 | yarn-debug.log* 24 | yarn-error.log* 25 | 26 | storybook-static 27 | 28 | # microbundle 29 | .rts2* 30 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 12.17.0 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | package.json -------------------------------------------------------------------------------- /.prettierrc.yaml: -------------------------------------------------------------------------------- 1 | useTabs: true 2 | trailingComma: es5 -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true 3 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Very Nested 2 | 3 | Infinitely nested lists published on GitHub. 4 | 5 | ## Packages 6 | 7 | - `manager` - Create, edit and view your Very Nested GitHub repos. 8 | - `viewer` - Render a Very Nested list from JSON data. 9 | - `template` - The GitHub template that new Very Nested repos are created from. 10 | - `website` - The Very Nested public website. 11 | - `login` - A small package for generating a GitHub login link. 12 | 13 | ## Commands 14 | 15 | - `yarn` - Install dependencies. 16 | - `npm run deploy` - Version packages with Lerna and publish Viewer to NPM. 17 | - `yarn bump` - Version all packages with Lerna. Called by `npm run deploy`.. 18 | - `yarn prepare` - Build dependencies like Viewer and Login so they can be used by other packages. Run automatically after `yarn` but sometimes isn't if `yarn` fails. 19 | - `clean` - Delete previous builds. 20 | 21 | ## 💻 Running Locally 22 | 23 | 1. Install dependencies. 24 | 25 | ``` 26 | yarn 27 | ``` 28 | 29 | If it fails, you may need to run prepare manually afterwards. 30 | 31 | ``` 32 | yarn prepare 33 | ``` 34 | 35 | 1. Start the manager development server. 36 | 37 | ``` 38 | cd packages/manager 39 | yarn start 40 | ``` 41 | 42 | 1. In another browser tab, login to GitHub in production at [https://verynested.cadell.dev/](https://verynested.cadell.dev/). 43 | 1. Open your browser tools, go to Application and copy the accessToken value. 44 | 1. In the tab for your local, open dev tools, go to console and set the access token. 45 | 46 | ``` 47 | localStorage.setItem("accessToken", "{PASTE_ACCESS_TOKEN_HERE}") 48 | ``` 49 | 50 | 1. Refresh your local. 51 | 52 | ### Manager 53 | 54 | Create, edit and view your Very Nested GitHub repos. 55 | 56 | ``` 57 | cd packages/manager 58 | yarn start 59 | ``` 60 | 61 | Copy the `accessToken` from production Local Storage to login. 62 | 63 | [Read more...](./packages/manager/README.md) 64 | 65 | ### Viewer 66 | 67 | Render a Very Nested list from JSON data. 68 | 69 | #### Storybook 70 | 71 | You can develop the viewer in isolation using Storybook. 72 | 73 | ``` 74 | cd packages/viewer 75 | yarn storybook 76 | ``` 77 | 78 | #### Watch Build 79 | 80 | You can build the viewer in watch mode to have it reload into the Manager app. 81 | 82 | Run this in separate terminal. 83 | 84 | ``` 85 | cd packages/package-template 86 | yarn build-watch 87 | ``` 88 | 89 | [Read more...](./packages/viewer/README.md) 90 | 91 | ### Template 92 | 93 | The GitHub template that new Very Nested repos are created from. 94 | 95 | 1. Build the Viewer. 96 | 1. Add this script tag to the template. 97 | 98 | ``` 99 | 103 | ``` 104 | 105 | 1. Run `serve` in the root. 106 | ``` 107 | serve 108 | ``` 109 | 1. Go to this url: [http://localhost:5000/packages/template/](http://localhost:5000/packages/template/). 110 | 111 | ## Technical Problems Solved 112 | 113 | - GitHub OAuth with Netlify Functions 114 | - This includes setting up Netlify Dev so we can develop functions locally 115 | - Would have been nice if GitHub supported the implicit flow so we didn't need any server side code. 116 | - The Netlify Functions OAuth examples included the initial auth request but this doesn't work with the popup flow (instead of a redirect flow where you lose page state) since you would get the url asynchronously where popups are blocked because they require user interaction. 117 | - This meant moving the url generation to the client side. 118 | - The pouplar OAuth library I used doesn't work in the browser. 119 | - Created the request myself with the queryString library. 120 | - Redux structure 121 | - This is the 3rd rewrite of the structure for the redux code. 122 | 1. Used the spread operator for immutable reducers 123 | 2. Replaced those with Immer and wrote a weird, OOP style, translator that felt very weird. 124 | 3. Replaced that with Redux Toolkit (which uses immer), typescript and removed the translator in favour of some functional style functions. 125 | - Building the viewer library 126 | - Initially used microbundle, which uses rollup underneath, and that worked great with the CRA manager app. 127 | - The standalone viewer uses unpkg to load the viewer so I needed the umd build to bundle the dependencies, otherwise I would have to add them to the standalone viewer and that didn't sound so great. 128 | - Microbundle fails to bundle the React-Hotkeys dependency for something and it's something to do with rollup that I think they're working on. 129 | - Tried a lot of combinations here with Rollup directly but I think it's an issue they're working on. 130 | - Switched to webpack for the umd build and that worked great. 131 | - I still kept microbundle around because it can create the modern and efficient module build for the manager app wheras webpack can't yet. 132 | - Gatsby transpiles workspace packages whereas CRA doesn't 133 | - Gatsby tries to transpile and lint the built module which fails because it's a production build. 134 | - Originally I just made the versions mismatched but settled on adding an empty eslintrc to disable linting. 135 | - To get netlify to build all the packages in the monorepo, I had to change the build command to cd to the root then cd back down to build the package. 136 | - There's still some weird stuff happening with regards to netlify dev on this one, see this ticket for more: https://github.com/netlify/cli/issues/859 137 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.39", 3 | "npmClient": "yarn", 4 | "useWorkspaces": true, 5 | "packages": [ 6 | "packages/*" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "very-nested", 3 | "private": true, 4 | "workspaces": { 5 | "packages": [ 6 | "packages/*" 7 | ], 8 | "nohoist": [ 9 | "**/react-scripts", 10 | "**/react-scripts/**" 11 | ] 12 | }, 13 | "scripts": { 14 | "prepare": "lerna run prepare", 15 | "clean": "lerna run clean", 16 | "bump": "lerna version --force-publish", 17 | "deploy": "npm run bump && cd packages/viewer && npm publish" 18 | }, 19 | "devDependencies": { 20 | "lerna": "^3.20.2" 21 | } 22 | } -------------------------------------------------------------------------------- /packages/login/README.md: -------------------------------------------------------------------------------- 1 | # Auth 2 | 3 | A simple package that uses typescript for building. 4 | -------------------------------------------------------------------------------- /packages/login/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "very-nested-login", 3 | "version": "1.0.39", 4 | "description": "", 5 | "private": true, 6 | "module": "dist/index.js", 7 | "files": [ 8 | "dist/" 9 | ], 10 | "scripts": { 11 | "prepare": "yarn build", 12 | "build": "tsc -p .", 13 | "test": "echo \"Error: no test specified\" && exit 1" 14 | }, 15 | "devDependencies": { 16 | "typescript": "^3.9.3" 17 | }, 18 | "dependencies": { 19 | "query-string": "^6.12.1" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /packages/login/src/index.tsx: -------------------------------------------------------------------------------- 1 | import queryString from "query-string"; 2 | 3 | const clientId = "c7381fe587f3cdaf4e30"; 4 | const siteUrl = "https://verynestedapp.cadell.dev"; 5 | 6 | const oauthApi = "https://github.com/login/oauth"; 7 | 8 | export const oauthConfg = { 9 | clientId, 10 | clientSecret: "", 11 | tokenHost: oauthApi, 12 | authorizePath: `${oauthApi}/authorize`, 13 | tokenPath: `${oauthApi}/access_token`, 14 | redirectUri: `${siteUrl}/.netlify/functions/auth-callback`, 15 | }; 16 | 17 | export interface GenerateAuthorizeUrlArguments { 18 | scope?: string; 19 | } 20 | 21 | export const generateAuthorizeUrl = ({ 22 | scope = "public_repo", 23 | }: GenerateAuthorizeUrlArguments) => { 24 | const params = { 25 | response_type: "code", 26 | client_id: oauthConfg.clientId, 27 | redirect_uri: oauthConfg.redirectUri, 28 | scope, 29 | state: "", 30 | }; 31 | 32 | return oauthConfg.authorizePath + "?" + queryString.stringify(params); 33 | }; 34 | -------------------------------------------------------------------------------- /packages/login/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "src", 4 | 5 | "target": "ES2015", 6 | "module": "ES2020", 7 | "outDir": "dist", 8 | "declaration": true, 9 | 10 | "strict": true, 11 | "skipLibCheck": true, 12 | "moduleResolution": "node", 13 | "esModuleInterop": true, 14 | "allowSyntheticDefaultImports": true, 15 | "forceConsistentCasingInFileNames": true, 16 | "jsx": "react" 17 | }, 18 | "include": ["src"] 19 | } 20 | -------------------------------------------------------------------------------- /packages/manager/.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=true -------------------------------------------------------------------------------- /packages/manager/.gitignore: -------------------------------------------------------------------------------- 1 | built-lambda 2 | # Local Netlify folder 3 | .netlify -------------------------------------------------------------------------------- /packages/manager/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | 3 | ## Setting Up 4 | 5 | Install Netlify dev 6 | `npm install -g netlify-cli@2.57.0` 7 | 8 | Login with Netlify 9 | `netlify login` 10 | 11 | Link with Netlify 12 | `netlify link` 13 | 14 | ## Running Locally 15 | 16 | `yarn start` 17 | 18 | Grab the localstorage entry from the production app to authenticate. A lot easier than running the backend. 19 | 20 | ## Running the Backend 21 | 22 | `netlify dev` 23 | 24 | Change the redirect_uri in github oauth app. 25 | -------------------------------------------------------------------------------- /packages/manager/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "cd ../.. && yarn && cd packages/manager && yarn build" 3 | publish = "build" 4 | functions = "built-lambda" -------------------------------------------------------------------------------- /packages/manager/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "very-nested-manager", 3 | "version": "1.0.39", 4 | "private": true, 5 | "dependencies": { 6 | "@octokit/rest": "^18.0.0", 7 | "bootstrap": "^4.4.1", 8 | "debounce": "^1.2.0", 9 | "js-base64": "^2.5.2", 10 | "react": "^16.12.0", 11 | "react-dom": "^16.12.0", 12 | "react-hotkeys": "^1.1.4", 13 | "react-redux": "7.2", 14 | "react-router-dom": "^5.1.2", 15 | "react-scripts": "3.4.1", 16 | "redux": "^4.0.5", 17 | "redux-persist": "^6.0.0", 18 | "redux-thunk": "^2.3.0", 19 | "shortid": "^2.2.15", 20 | "simple-oauth2": "^3.4.0", 21 | "theme-ui": "^0.3.1", 22 | "typeface-source-sans-pro": "^1.1.5", 23 | "very-nested-login": "^1.0.39", 24 | "very-nested-viewer": "^1.0.39" 25 | }, 26 | "scripts": { 27 | "start": "react-scripts start", 28 | "build:app": "CI=false react-scripts build", 29 | "test": "react-scripts test --env=jsdom", 30 | "eject": "react-scripts eject", 31 | "start:lambda": "netlify-lambda serve src/backend", 32 | "build:lambda": "netlify-lambda build src/backend", 33 | "build": "run-p build:**", 34 | "clean": "rimraf node_modules built-lambda build" 35 | }, 36 | "browserslist": { 37 | "production": [ 38 | ">0.2%", 39 | "not dead", 40 | "not op_mini all" 41 | ], 42 | "development": [ 43 | "last 1 chrome version", 44 | "last 1 firefox version", 45 | "last 1 safari version" 46 | ] 47 | }, 48 | "devDependencies": { 49 | "@types/jest": "^25.2.1", 50 | "@types/js-base64": "^2.3.1", 51 | "@types/node": "^13.11.0", 52 | "@types/react": "^16.9.32", 53 | "@types/react-dom": "^16.9.6", 54 | "@types/react-redux": "^7.1.7", 55 | "@types/react-router-dom": "^5.1.4", 56 | "netlify-lambda": "^1.6.3", 57 | "npm-run-all": "^4.1.5", 58 | "rimraf": "^3.0.2", 59 | "typescript": "^3.8.3" 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /packages/manager/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cadbox1/very-nested/8b5d4ac64f35a78d551a61a8207265c21959cf1a/packages/manager/public/favicon.ico -------------------------------------------------------------------------------- /packages/manager/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 16 | 25 | Very Nested Manager 26 | 27 | 28 | 29 |
30 | 40 | 41 | -------------------------------------------------------------------------------- /packages/manager/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /packages/manager/src/backend/auth-callback.js: -------------------------------------------------------------------------------- 1 | import simpleOauth from "simple-oauth2"; 2 | import { commonConfig } from "../common/oauth-config"; 3 | 4 | export const backendSimpleConfig = { 5 | client: { 6 | id: commonConfig.clientId, 7 | secret: process.env.CLIENT_SECRET, 8 | }, 9 | auth: { 10 | tokenHost: commonConfig.tokenHost, 11 | tokenPath: commonConfig.tokenPath, 12 | authorizePath: commonConfig.authorizePath, 13 | }, 14 | }; 15 | 16 | if (!backendSimpleConfig.client.secret) { 17 | throw new Error("MISSING REQUIRED ENV VARS. Please set CLIENT_SECRET"); 18 | } 19 | 20 | const oauth2 = simpleOauth.create(backendSimpleConfig); 21 | 22 | /* Function to handle intercom auth callback */ 23 | exports.handler = (event, context, callback) => { 24 | const code = event.queryStringParameters.code; 25 | /* state helps mitigate CSRF attacks & Restore the previous state of your app */ 26 | const state = event.queryStringParameters.state; 27 | 28 | /* Take the grant code and exchange for an accessToken */ 29 | oauth2.authorizationCode 30 | .getToken({ 31 | code, 32 | redirect_uri: commonConfig.redirectUri, 33 | client_id: backendSimpleConfig.client.id, 34 | client_secret: backendSimpleConfig.client.secret, 35 | }) 36 | .then(result => { 37 | const accessToken = oauth2.accessToken.create(result); 38 | console.log(accessToken.token); 39 | return callback(null, { 40 | statusCode: 301, 41 | headers: { 42 | Location: "/#?accessToken=" + accessToken.token.access_token, 43 | }, 44 | body: "", 45 | }); 46 | }) 47 | .catch(error => { 48 | console.log("Access Token Error", error.message); 49 | console.log(error); 50 | return callback(null, { 51 | statusCode: error.statusCode || 500, 52 | body: JSON.stringify({ 53 | error: error.message, 54 | }), 55 | }); 56 | }); 57 | }; 58 | -------------------------------------------------------------------------------- /packages/manager/src/common/oauth-config.js: -------------------------------------------------------------------------------- 1 | const oauthApi = "https://github.com/login/oauth"; 2 | const siteUrl = process.env.REACT_APP_URL; 3 | // const siteUrl = "http://localhost:8888"; 4 | 5 | if (!siteUrl) { 6 | throw new Error("MISSING REQUIRED ENV VARS. Please set REACT_APP_URL"); 7 | } 8 | 9 | export const commonConfig = { 10 | clientId: process.env.REACT_APP_CLIENT_ID, 11 | clientSecret: "", // this isn't common, it's defined in auth-callback 12 | tokenHost: oauthApi, 13 | authorizePath: `${oauthApi}/authorize`, 14 | tokenPath: `${oauthApi}/access_token`, 15 | redirectUri: `${siteUrl}/.netlify/functions/auth-callback`, 16 | }; 17 | 18 | if (!commonConfig.clientId) { 19 | throw new Error("MISSING REQUIRED ENV VARS. Please set CLIENT_ID"); 20 | } 21 | -------------------------------------------------------------------------------- /packages/manager/src/frontend/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render(, div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/manager/src/frontend/App.tsx: -------------------------------------------------------------------------------- 1 | /** @jsx jsx */ 2 | import { HashRouter as Router } from "react-router-dom"; 3 | import { Container, jsx } from "theme-ui"; 4 | import { List } from "./Repository/List"; 5 | 6 | const App = () => ( 7 | 8 | 9 | 10 | 11 | 12 | ); 13 | 14 | export default App; 15 | -------------------------------------------------------------------------------- /packages/manager/src/frontend/Repository/Add.tsx: -------------------------------------------------------------------------------- 1 | /** @jsx jsx */ 2 | import { jsx, Button } from "theme-ui"; 3 | import React, { useState } from "react"; 4 | import { octokit } from "./List"; 5 | import { usePromise } from "frontend/common/usePromise"; 6 | import { Redirect, Link } from "react-router-dom"; 7 | 8 | function timeout(timeoutInMs: number) { 9 | return new Promise(resolve => setTimeout(resolve, timeoutInMs)); 10 | } 11 | 12 | export interface AddProps { 13 | currentUser: string; 14 | } 15 | 16 | export const Add = ({ currentUser }: AddProps) => { 17 | const [name, setName] = useState(""); 18 | 19 | const { pending, rejected, fulfilled, call } = usePromise({ 20 | promiseFunction: async () => { 21 | await octokit.repos.createUsingTemplate({ 22 | template_owner: "cadbox1", 23 | template_repo: "very-nested-template", 24 | name, 25 | }); 26 | 27 | await timeout(1000); // timeout to cater for asynchronous branch creation. 28 | 29 | const owner = currentUser; 30 | const repo = name; 31 | 32 | return octokit.repos.createPagesSite({ 33 | owner, 34 | repo, 35 | source: { 36 | branch: "master", 37 | path: "/", 38 | }, 39 | }); 40 | }, 41 | }); 42 | 43 | const handleChange = (evt: React.ChangeEvent) => { 44 | setName(evt.target.value); 45 | }; 46 | 47 | const handleSubmit = async (evt: React.SyntheticEvent) => { 48 | evt.preventDefault(); 49 | call(); 50 | }; 51 | 52 | if (fulfilled) { 53 | return ; 54 | } 55 | 56 | return ( 57 |
58 |
59 | 60 | {"< Home"} 61 | 62 |
63 |
64 |
65 | {"Name: "} 66 | 74 |
75 |

76 | No spaces please - spaces are not allowed in GitHub repository names. 77 |

78 | {rejected &&

There was an issue creating this repository.

} 79 | 82 |
83 |
84 | ); 85 | }; 86 | -------------------------------------------------------------------------------- /packages/manager/src/frontend/Repository/Edit.tsx: -------------------------------------------------------------------------------- 1 | /** @jsx jsx */ 2 | import { jsx, Styled, Button } from "theme-ui"; 3 | import { useEffect } from "react"; 4 | import { octokit } from "./List"; 5 | import { usePromise } from "frontend/common/usePromise"; 6 | import { useParams, Link } from "react-router-dom"; 7 | import { useSelector, useDispatch } from "react-redux"; 8 | import { Base64 } from "js-base64"; 9 | import { persistor } from "index"; 10 | 11 | // @ts-ignore 12 | import { load, Viewer } from "very-nested-viewer"; 13 | import { FileWithName } from "very-nested-viewer/dist/Viewer/ToolbarUploadButton"; 14 | 15 | const veryNestedDataFile = "very-nested-data.json"; 16 | const filesFolder = "files/"; 17 | 18 | export const Edit = () => { 19 | const { owner = "", repo = "" } = useParams(); 20 | 21 | const repoRequest = usePromise({ 22 | promiseFunction: async () => { 23 | return octokit.repos.get({ 24 | owner, 25 | repo, 26 | }); 27 | }, 28 | }); 29 | 30 | const getPagesRequest = usePromise({ 31 | promiseFunction: async () => { 32 | return octokit.repos.getPages({ 33 | owner, 34 | repo, 35 | }); 36 | }, 37 | }); 38 | 39 | useEffect(() => { 40 | if (repoRequest.value && repoRequest.value.data.has_pages) { 41 | getPagesRequest.call(); 42 | } 43 | }, [repoRequest.value]); 44 | 45 | const dispatch = useDispatch(); 46 | 47 | const getRequest = usePromise({ 48 | promiseFunction: async () => { 49 | const response: any = await octokit.repos.getContent({ 50 | repo, 51 | owner, 52 | path: veryNestedDataFile, 53 | }); 54 | 55 | const data = response.data; 56 | 57 | const content = JSON.parse(Base64.decode(data.content)); 58 | dispatch(load({ data: content })); 59 | 60 | return data; 61 | }, 62 | }); 63 | 64 | useEffect(() => { 65 | repoRequest.call(); 66 | getRequest.call(); 67 | }, [repo, owner]); 68 | 69 | // @ts-ignore 70 | const itemState = useSelector(state => state.item); 71 | 72 | const saveRequest = usePromise({ 73 | promiseFunction: async () => { 74 | const jsonState = JSON.stringify(itemState, null, 1); 75 | const base64JsonState = Base64.encode(jsonState); 76 | 77 | await octokit.repos.createOrUpdateFileContents({ 78 | owner, 79 | repo, 80 | path: veryNestedDataFile, 81 | sha: getRequest.value.sha, 82 | content: base64JsonState, 83 | message: "Updated very-nested-data", 84 | }); 85 | return getRequest.call(); 86 | }, 87 | }); 88 | 89 | const handleSave = async () => { 90 | await saveRequest.call(); 91 | 92 | // hide the saved prompt after 10 seconds 93 | setTimeout(() => { 94 | saveRequest.reset(); 95 | }, 10000); 96 | }; 97 | 98 | const handleRevert = () => { 99 | persistor.purge(); 100 | getRequest.call(); 101 | }; 102 | 103 | const uploadRequest = usePromise({ 104 | promiseFunction: async ({ name, base64 }: FileWithName) => { 105 | let path = filesFolder + name; 106 | try { 107 | await octokit.repos.createOrUpdateFileContents({ 108 | owner, 109 | repo, 110 | path, 111 | content: base64, 112 | message: "Uploaded a file", 113 | }); 114 | } catch (error) { 115 | if (error.status !== 422) { 116 | throw error; 117 | } 118 | // file is a duplicate, append something to it 119 | const pathWithoutExtension = path.substr(0, path.lastIndexOf(".")); 120 | const extensionIncludingDot = path.substr(path.lastIndexOf(".")); 121 | path = 122 | pathWithoutExtension + 123 | " - " + 124 | new Date().toUTCString() + 125 | extensionIncludingDot; 126 | 127 | await octokit.repos.createOrUpdateFileContents({ 128 | owner, 129 | repo, 130 | path, 131 | content: base64, 132 | message: "Uploaded a file", 133 | }); 134 | } 135 | return path; 136 | }, 137 | }); 138 | 139 | const handleUpload = async (fileWithName: FileWithName) => { 140 | const path = await uploadRequest.call(fileWithName); 141 | return "./" + path; 142 | }; 143 | 144 | const getBaseUrl = () => { 145 | const domain = "https://raw.githubusercontent.com"; 146 | const branch = "master"; 147 | return domain + "/" + owner + "/" + repo + "/" + branch; 148 | }; 149 | 150 | return ( 151 |
152 |
153 | 154 | {"< Home"} 155 | 156 |
157 | {repo} 158 |
159 |
160 | Public Link:{" "} 161 | {repoRequest.pending 162 | ? "loading..." 163 | : repoRequest.rejected 164 | ? "error loading url" 165 | : repoRequest.value && 166 | (!repoRequest.value.data.has_pages 167 | ? "no pages url found" 168 | : getPagesRequest.pending 169 | ? "loading..." 170 | : getPagesRequest.rejected 171 | ? "error loading url" 172 | : getPagesRequest.value && ( 173 | 178 | {getPagesRequest.value.data.html_url} 179 | 180 | ))} 181 |
182 |
183 | GitHub Repo:{" "} 184 | {repoRequest.pending 185 | ? "loading..." 186 | : repoRequest.rejected 187 | ? "error loading url" 188 | : repoRequest.value && ( 189 | 194 | {repoRequest.value.data.html_url} 195 | 196 | )} 197 |
198 |
199 | {saveRequest.fulfilled && ( 200 |
201 | Saved! It might take up to 10 minutes before your changes are 202 | displayed. 203 |
204 | )} 205 |
217 | 225 | {/* */} 234 |
235 |
236 | {saveRequest.rejected &&

There was an issue saving your repo :(

} 237 | {getRequest.pending &&

Loading...

} 238 | {getRequest.rejected && ( 239 |

240 | We couldn't read this repository, are you sure it's a very nested 241 | repo? 242 |

243 | )} 244 | {getRequest.fulfilled && ( 245 | 246 | )} 247 |
248 |
249 | ); 250 | }; 251 | -------------------------------------------------------------------------------- /packages/manager/src/frontend/Repository/List.tsx: -------------------------------------------------------------------------------- 1 | /** @jsx jsx */ 2 | import { jsx, Styled } from "theme-ui"; 3 | import { useEffect, useState } from "react"; 4 | import { Octokit } from "@octokit/rest"; 5 | import { Switch, Route, Link, useLocation } from "react-router-dom"; 6 | import queryString from "query-string"; 7 | import { usePromise } from "frontend/common/usePromise"; 8 | // @ts-ignore 9 | import { generateAuthorizeUrl } from "very-nested-login"; 10 | import { Add } from "./Add"; 11 | import { Edit } from "./Edit"; 12 | 13 | export let octokit: Octokit; 14 | 15 | const scope = "public_repo"; 16 | 17 | export const List = () => { 18 | const [accessToken, setAccessToken] = useState( 19 | localStorage.getItem("accessToken") 20 | ); 21 | 22 | const { search } = useLocation(); 23 | useEffect(() => { 24 | const { accessToken: accessTokenFromUrl } = queryString.parse(search); 25 | if (accessTokenFromUrl && accessTokenFromUrl != accessToken) { 26 | // @ts-ignore 27 | localStorage.setItem("accessToken", accessTokenFromUrl); 28 | window.location.href = "/"; 29 | } 30 | }, [search]); 31 | 32 | const setupOktokit = (accessToken: string) => { 33 | octokit = octokit = new Octokit({ 34 | auth: accessToken, 35 | }); 36 | octokit.hook.error("request", async (error, options) => { 37 | if (error.status === 401) { 38 | setAccessToken(""); 39 | localStorage.setItem("accessToken", ""); 40 | } 41 | throw error; 42 | }); 43 | }; 44 | 45 | const repos = usePromise({ 46 | promiseFunction: async () => 47 | octokit.repos.listForAuthenticatedUser({ per_page: 100 }), 48 | }); 49 | const currentUser = usePromise({ 50 | promiseFunction: async () => octokit.users.getAuthenticated(), 51 | }); 52 | 53 | useEffect(() => { 54 | setupOktokit(accessToken || ""); 55 | 56 | if (accessToken) { 57 | repos.call(); 58 | currentUser.call(); 59 | } 60 | }, [accessToken]); 61 | 62 | return ( 63 |
64 | {!accessToken && ( 65 | 66 | Login with GitHub 67 | 68 | )} 69 | {accessToken && octokit && ( 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | Very Nested Manager 79 |
80 | 84 | Back to Homepage 85 | 86 |
87 |
88 |
89 | 90 | Add 91 | 92 |
93 |
94 | {repos.pending &&

pending

} 95 | {repos.value?.data?.some((repo: any) => 96 | repo.name.startsWith("very-nested") 97 | ) && ( 98 | Very Nested Repos 99 | )} 100 | {repos.value?.data 101 | ?.filter((repo: any) => repo.name.startsWith("very-nested")) 102 | .map((repo: any) => ( 103 |
104 | 105 | {repo.name} 106 | 107 |
108 | ))} 109 | {repos.value?.data?.some( 110 | (repo: any) => !repo.name.startsWith("very-nested") 111 | ) && ( 112 | Other Repos 113 | )} 114 | {repos.value?.data 115 | ?.filter((repo: any) => !repo.name.startsWith("very-nested")) 116 | .map((repo: any) => ( 117 |
118 | 119 | {repo.name} 120 | 121 |
122 | ))} 123 |
124 |
125 |
126 |
127 | )} 128 |
129 | ); 130 | }; 131 | -------------------------------------------------------------------------------- /packages/manager/src/frontend/common/usePromise.ts: -------------------------------------------------------------------------------- 1 | import { useState } from "react"; 2 | 3 | export enum PromiseStatus { 4 | NotStarted = "not_started", 5 | Pending = "pending", 6 | Fulfilled = "fulfilled", 7 | Rejected = "rejected", 8 | } 9 | 10 | export interface PromiseState { 11 | pending: boolean; 12 | fulfilled: boolean; 13 | rejected: boolean; 14 | value: T | undefined; 15 | reason: Error | undefined; 16 | } 17 | 18 | export interface UsePromise extends PromiseState { 19 | call: (...args: any[]) => Promise; 20 | reset: () => void; 21 | } 22 | 23 | export interface UpdateableState { 24 | state: T; 25 | setState: any; 26 | } 27 | 28 | export const initialRequest: PromiseState = { 29 | pending: false, 30 | fulfilled: false, 31 | rejected: false, 32 | value: undefined, 33 | reason: undefined, 34 | }; 35 | 36 | export interface UsePromiseArguments { 37 | promiseFunction: (...promiseFunctionParameters: any[]) => Promise; 38 | updateableRequest?: UpdateableState>; 39 | } 40 | 41 | export function usePromise({ 42 | promiseFunction, 43 | updateableRequest: updateableRequestProp, 44 | }: UsePromiseArguments): UsePromise { 45 | const [localRequest, setLocalRequest] = useState( 46 | initialRequest 47 | ); 48 | const localUpdateableState: UpdateableState = { 49 | state: localRequest, 50 | setState: setLocalRequest, 51 | }; 52 | 53 | const updateableRequest = updateableRequestProp || localUpdateableState; 54 | 55 | const updateRequest = (patchRequest: Partial) => { 56 | updateableRequest.setState({ 57 | ...updateableRequest.state, 58 | ...patchRequest, 59 | }); 60 | }; 61 | 62 | const wrappedPromiseFunction = (...args: []): Promise => { 63 | updateRequest({ pending: true }); 64 | return promiseFunction.apply(null, args).then( 65 | result => { 66 | updateRequest({ 67 | pending: false, 68 | fulfilled: true, 69 | rejected: false, 70 | value: result, 71 | }); 72 | return result; 73 | }, 74 | error => { 75 | updateRequest({ 76 | pending: false, 77 | fulfilled: false, 78 | rejected: true, 79 | reason: error, 80 | }); 81 | throw error; 82 | } 83 | ); 84 | }; 85 | 86 | return { 87 | ...updateableRequest.state, 88 | call: wrappedPromiseFunction, 89 | reset: () => { 90 | updateableRequest.setState({ ...initialRequest }); 91 | }, 92 | }; 93 | } 94 | -------------------------------------------------------------------------------- /packages/manager/src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import { applyMiddleware, compose, createStore } from "redux"; 4 | import { Provider } from "react-redux"; 5 | import thunk from "redux-thunk"; 6 | import { persistStore, persistReducer } from "redux-persist"; 7 | import storage from "redux-persist/lib/storage"; 8 | import { PersistGate } from "redux-persist/integration/react"; 9 | import { reducer } from "very-nested-viewer"; 10 | import { ThemeProvider } from "theme-ui"; 11 | import theme from "./theme"; 12 | 13 | import App from "./frontend/App"; 14 | import * as serviceWorker from "./serviceWorker"; 15 | 16 | import "bootstrap/dist/css/bootstrap-reboot.css"; 17 | 18 | const persistedReducer = persistReducer( 19 | { 20 | key: "root", 21 | storage, 22 | }, 23 | reducer 24 | ); 25 | 26 | export let persistor; 27 | 28 | function configureStore() { 29 | // @ts-ignore 30 | const composeEnhancers = 31 | window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; 32 | const store = createStore( 33 | persistedReducer, 34 | composeEnhancers(applyMiddleware(thunk)) 35 | ); 36 | persistor = persistStore(store); 37 | return store; 38 | } 39 | 40 | ReactDOM.render( 41 | 42 | 43 | 44 | 45 | 46 | 47 | , 48 | document.getElementById("root") 49 | ); 50 | 51 | // If you want your app to work offline and load faster, you can change 52 | // unregister() to register() below. Note this comes with some pitfalls. 53 | // Learn more about service workers: https://bit.ly/CRA-PWA 54 | serviceWorker.unregister(); 55 | -------------------------------------------------------------------------------- /packages/manager/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /packages/manager/src/serviceWorker.js: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === "localhost" || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === "[::1]" || 17 | // 127.0.0.0/8 are considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | export function register(config) { 24 | if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) { 25 | // The URL constructor is available in all browsers that support SW. 26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); 27 | if (publicUrl.origin !== window.location.origin) { 28 | // Our service worker won't work if PUBLIC_URL is on a different origin 29 | // from what our page is served on. This might happen if a CDN is used to 30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 31 | return; 32 | } 33 | 34 | window.addEventListener("load", () => { 35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 36 | 37 | if (isLocalhost) { 38 | // This is running on localhost. Let's check if a service worker still exists or not. 39 | checkValidServiceWorker(swUrl, config); 40 | 41 | // Add some additional logging to localhost, pointing developers to the 42 | // service worker/PWA documentation. 43 | navigator.serviceWorker.ready.then(() => { 44 | console.log( 45 | "This web app is being served cache-first by a service " + 46 | "worker. To learn more, visit https://bit.ly/CRA-PWA" 47 | ); 48 | }); 49 | } else { 50 | // Is not localhost. Just register service worker 51 | registerValidSW(swUrl, config); 52 | } 53 | }); 54 | } 55 | } 56 | 57 | function registerValidSW(swUrl, config) { 58 | navigator.serviceWorker 59 | .register(swUrl) 60 | .then(registration => { 61 | registration.onupdatefound = () => { 62 | const installingWorker = registration.installing; 63 | if (installingWorker == null) { 64 | return; 65 | } 66 | installingWorker.onstatechange = () => { 67 | if (installingWorker.state === "installed") { 68 | if (navigator.serviceWorker.controller) { 69 | // At this point, the updated precached content has been fetched, 70 | // but the previous service worker will still serve the older 71 | // content until all client tabs are closed. 72 | console.log( 73 | "New content is available and will be used when all " + 74 | "tabs for this page are closed. See https://bit.ly/CRA-PWA." 75 | ); 76 | 77 | // Execute callback 78 | if (config && config.onUpdate) { 79 | config.onUpdate(registration); 80 | } 81 | } else { 82 | // At this point, everything has been precached. 83 | // It's the perfect time to display a 84 | // "Content is cached for offline use." message. 85 | console.log("Content is cached for offline use."); 86 | 87 | // Execute callback 88 | if (config && config.onSuccess) { 89 | config.onSuccess(registration); 90 | } 91 | } 92 | } 93 | }; 94 | }; 95 | }) 96 | .catch(error => { 97 | console.error("Error during service worker registration:", error); 98 | }); 99 | } 100 | 101 | function checkValidServiceWorker(swUrl, config) { 102 | // Check if the service worker can be found. If it can't reload the page. 103 | fetch(swUrl, { 104 | headers: { "Service-Worker": "script" }, 105 | }) 106 | .then(response => { 107 | // Ensure service worker exists, and that we really are getting a JS file. 108 | const contentType = response.headers.get("content-type"); 109 | if ( 110 | response.status === 404 || 111 | (contentType != null && contentType.indexOf("javascript") === -1) 112 | ) { 113 | // No service worker found. Probably a different app. Reload the page. 114 | navigator.serviceWorker.ready.then(registration => { 115 | registration.unregister().then(() => { 116 | window.location.reload(); 117 | }); 118 | }); 119 | } else { 120 | // Service worker found. Proceed as normal. 121 | registerValidSW(swUrl, config); 122 | } 123 | }) 124 | .catch(() => { 125 | console.log( 126 | "No internet connection found. App is running in offline mode." 127 | ); 128 | }); 129 | } 130 | 131 | export function unregister() { 132 | if ("serviceWorker" in navigator) { 133 | navigator.serviceWorker.ready.then(registration => { 134 | registration.unregister(); 135 | }); 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /packages/manager/src/theme.js: -------------------------------------------------------------------------------- 1 | import "typeface-source-sans-pro"; 2 | 3 | export default { 4 | // useColorSchemeMediaQuery: true, 5 | fonts: { 6 | body: 7 | '"source sans pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial', 8 | heading: 9 | '"source sans pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial', 10 | monospace: `Consolas, Menlo, Monaco, source-code-pro, Courier New, monospace`, 11 | }, 12 | colors: { 13 | text: "#000", 14 | background: "#fff", 15 | primary: "#007bff", 16 | danger: "#dc3545", 17 | muted: "hsl(0, 0%, 96%)", 18 | heading: "text", 19 | modes: { 20 | dark: { 21 | text: "#fff", 22 | background: "#000", 23 | primary: "#007bff", 24 | muted: "hsl(0, 0%, 10%)", 25 | }, 26 | }, 27 | }, 28 | space: [0, 4, 8, 12, 16, 24, 32, 64, 96, 128], 29 | sizes: { 30 | container: 850, 31 | }, 32 | fontSizes: [16, 18, 20, 24, 32, 36, 44], 33 | lineHeights: { 34 | body: 1.7, 35 | heading: 1.2, 36 | }, 37 | fontWeights: { 38 | body: 400, 39 | heading: 600, 40 | bold: 600, 41 | }, 42 | container: { 43 | p: 2, 44 | }, 45 | viewer: { 46 | item: { 47 | fontSize: 1, 48 | }, 49 | }, 50 | buttons: { 51 | primary: { 52 | color: "background", 53 | bg: "primary", 54 | }, 55 | danger: { 56 | color: "background", 57 | bg: "danger", 58 | }, 59 | }, 60 | styles: { 61 | root: { 62 | fontFamily: "body", 63 | lineHeight: "body", 64 | fontWeight: "body", 65 | }, 66 | a: { 67 | textDecoration: "none", 68 | ":active, :hover": { 69 | textDecoration: "underline", 70 | }, 71 | }, 72 | p: { 73 | fontSize: 2, 74 | }, 75 | pre: { 76 | fontSize: 0, 77 | }, 78 | }, 79 | }; 80 | -------------------------------------------------------------------------------- /packages/manager/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "baseUrl": "src" 5 | }, 6 | "include": ["src"] 7 | } 8 | -------------------------------------------------------------------------------- /packages/manager/yarn.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cadbox1/very-nested/8b5d4ac64f35a78d551a61a8207265c21959cf1a/packages/manager/yarn.lock -------------------------------------------------------------------------------- /packages/template/README.md: -------------------------------------------------------------------------------- 1 | # Very Nested Template 2 | -------------------------------------------------------------------------------- /packages/template/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Very Nested 5 | 9 | 10 | 11 |
12 | 16 | 20 | 24 | 25 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /packages/template/very-nested-data.json: -------------------------------------------------------------------------------- 1 | { 2 | "vLlFS3csq": { 3 | "id": "vLlFS3csq", 4 | "content": "Home", 5 | "children": [ 6 | "r2_QCE3iV", 7 | "Qm5eeXGEw" 8 | ] 9 | }, 10 | "r2_QCE3iV": { 11 | "id": "r2_QCE3iV", 12 | "content": "Recent", 13 | "children": [ 14 | "eZshFR2JI" 15 | ] 16 | }, 17 | "eZshFR2JI": { 18 | "id": "eZshFR2JI", 19 | "content": "something", 20 | "children": [] 21 | }, 22 | "Qm5eeXGEw": { 23 | "id": "Qm5eeXGEw", 24 | "content": "All", 25 | "children": [ 26 | "eZshFR2JI", 27 | "wKwkOZbRk" 28 | ] 29 | }, 30 | "wKwkOZbRk": { 31 | "id": "wKwkOZbRk", 32 | "content": "something else", 33 | "children": [] 34 | } 35 | } -------------------------------------------------------------------------------- /packages/viewer/.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=true -------------------------------------------------------------------------------- /packages/viewer/.storybook/config.js: -------------------------------------------------------------------------------- 1 | import { configure } from "@storybook/react"; 2 | 3 | const loadStories = () => { 4 | return [ 5 | // Ensure we load Welcome First 6 | require.context("../docs", true, /Intro.stories.mdx/), 7 | ]; 8 | }; 9 | 10 | configure(loadStories(), module); 11 | -------------------------------------------------------------------------------- /packages/viewer/.storybook/main.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | stories: ["../src/**/*.stories.(js|mdx|tsx)"], 3 | addons: [ 4 | "@storybook/preset-create-react-app", 5 | { 6 | name: "@storybook/addon-docs", 7 | options: { 8 | configureJSX: true, 9 | }, 10 | }, 11 | "@storybook/addon-actions", 12 | "@storybook/addon-links", 13 | "@storybook/addon-viewport/register", 14 | ], 15 | }; 16 | -------------------------------------------------------------------------------- /packages/viewer/README.md: -------------------------------------------------------------------------------- 1 | # Very Nested Viewer 2 | 3 | ## 🔧 Tools 4 | 5 | - [Typescript](https://www.typescriptlang.org/). 6 | - [Microbundle](https://github.com/developit/microbundle) for bundling. 7 | - [Storybook](https://github.com/storybookjs/presets/tree/master/packages/preset-create-react-app) with [Docs Addon](https://github.com/storybookjs/storybook/tree/master/addons/docs) for component developent and documentation. 8 | - [Jest](https://create-react-app.dev/docs/running-tests/) for testing. 9 | 10 | ## 🔮 Future Development 11 | 12 | - Try out my own rollup config when they fix this [typescript issue](https://github.com/rollup/plugins/issues/287). 13 | 14 | ## Commands 15 | 16 | - `yarn` - Install dependencies. 17 | - `yarn storybook` - Start the Storybook dev server. 18 | - `yarn test` - Run tests. 19 | - `yarn build` - Build the package. 20 | - `yarn build-watch` - Build the package continuously. 21 | - `npm run deploy` - Shortcut to the project root deploy process. 22 | 23 | ## Deploy 24 | 25 | Run the deploy script in this package or the project root. 26 | 27 | ``` 28 | npm run deploy 29 | ``` 30 | 31 | This will version all packages using Lerna and publish this package to NPM. 32 | 33 | ## Serialise current state 34 | 35 | Select the storybook iframe in your console then run this. 36 | 37 | ``` 38 | console.log(JSON.stringify(window.store.getState().item, null, 1)) 39 | ``` 40 | 41 | You can then add this to a storybook example. 42 | -------------------------------------------------------------------------------- /packages/viewer/docs/Intro.stories.mdx: -------------------------------------------------------------------------------- 1 | import { Meta } from '@storybook/addon-docs/blocks'; 2 | 3 | 4 | 5 | # Introduction 6 | 7 | This is our CRA Storybook example -------------------------------------------------------------------------------- /packages/viewer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "very-nested-viewer", 3 | "version": "1.0.39", 4 | "license": "GPL-3.0-only", 5 | "private": false, 6 | "source": "src/index.ts", 7 | "main": "dist/index.js", 8 | "module": "dist/index.module.js", 9 | "unpkg": "dist/bundle.js", 10 | "files": [ 11 | "dist" 12 | ], 13 | "peerDependencies": { 14 | "react": "^16.12.0", 15 | "react-dom": "^16.12.0", 16 | "react-redux": "^7.2.0", 17 | "redux": "^4.0.5" 18 | }, 19 | "scripts": { 20 | "prepare": "yarn build", 21 | "build": "yarn build-rollup && yarn build-webpack", 22 | "build-webpack": "webpack-cli", 23 | "build-rollup": "microbundle --jsx React.createElement --format modern,es,cjs", 24 | "build-watch": "microbundle watch --jsx React.createElement --format modern,es,cjs", 25 | "storybook": "start-storybook -s ./public -p 6006", 26 | "build-storybook": "build-storybook", 27 | "test": "react-scripts test", 28 | "clean": "rimraf node_modules dist .rts2*", 29 | "deploy": "cd ../.. && npm run deploy" 30 | }, 31 | "dependencies": { 32 | "@cadbox1/use-promise": "1.0.0", 33 | "@reduxjs/toolkit": "^1.3.6", 34 | "axios": "^0.19.2", 35 | "react-hotkeys": "^1.1.4", 36 | "react-icons": "^3.10.0", 37 | "redux": "^4.0.5", 38 | "redux-thunk": "^2.3.0", 39 | "shortid": "^2.2.15", 40 | "theme-ui": "^0.3.1" 41 | }, 42 | "devDependencies": { 43 | "@babel/core": "^7.9.0", 44 | "@storybook/addon-actions": "^5.3.18", 45 | "@storybook/addon-docs": "^5.3.13", 46 | "@storybook/addon-links": "^5.3.18", 47 | "@storybook/addon-viewport": "^5.3.18", 48 | "@storybook/addons": "^5.3.18", 49 | "@storybook/preset-create-react-app": "^2.1.1", 50 | "@storybook/react": "^5.3.18", 51 | "@testing-library/jest-dom": "^4.2.4", 52 | "@testing-library/react": "^9.3.2", 53 | "@testing-library/user-event": "^7.1.2", 54 | "@types/jest": "^24.0.0", 55 | "@types/node": "^12.0.0", 56 | "@types/react": "^16.9.0", 57 | "@types/react-dom": "^16.9.0", 58 | "@types/react-router-dom": "^5.1.3", 59 | "@types/shortid": "^0.0.29", 60 | "@types/theme-ui": "^0.3.0", 61 | "babel-loader": "^8.1.0", 62 | "microbundle": "^0.12.0-next.8", 63 | "prettier": "^1.19.1", 64 | "react-scripts": "^3.4.1", 65 | "rimraf": "^3.0.2", 66 | "ts-loader": "^7.0.1", 67 | "typescript": "^3.7.2", 68 | "webpack": "^4.43.0", 69 | "webpack-cli": "^3.3.11" 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /packages/viewer/public/baseFolder/files/Screen Shot 2020-07-11 at 9.42.39 am.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cadbox1/very-nested/8b5d4ac64f35a78d551a61a8207265c21959cf1a/packages/viewer/public/baseFolder/files/Screen Shot 2020-07-11 at 9.42.39 am.png -------------------------------------------------------------------------------- /packages/viewer/public/baseFolder/files/example.md: -------------------------------------------------------------------------------- 1 | # Markdown file! 2 | 3 | Markdown content! 4 | -------------------------------------------------------------------------------- /packages/viewer/public/very-nested-data.json: -------------------------------------------------------------------------------- 1 | { 2 | "vLlFS3csq": { 3 | "id": "vLlFS3csq", 4 | "content": "Home", 5 | "children": [ 6 | "r2_QCE3iV", 7 | "Qm5eeXGEw" 8 | ] 9 | }, 10 | "r2_QCE3iV": { 11 | "id": "r2_QCE3iV", 12 | "content": "Recent", 13 | "children": [ 14 | "eZshFR2JI" 15 | ] 16 | }, 17 | "eZshFR2JI": { 18 | "id": "eZshFR2JI", 19 | "content": "something", 20 | "children": [] 21 | }, 22 | "Qm5eeXGEw": { 23 | "id": "Qm5eeXGEw", 24 | "content": "All", 25 | "children": [ 26 | "eZshFR2JI", 27 | "wKwkOZbRk" 28 | ] 29 | }, 30 | "wKwkOZbRk": { 31 | "id": "wKwkOZbRk", 32 | "content": "something else", 33 | "children": [] 34 | } 35 | } -------------------------------------------------------------------------------- /packages/viewer/public/youtube.json: -------------------------------------------------------------------------------- 1 | { 2 | "vLlFS3csq": { 3 | "id": "vLlFS3csq", 4 | "content": "YouTube", 5 | "children": [ 6 | "r2_QCE3iV", 7 | "oCNyqY2fW", 8 | "ike9y2a84", 9 | "rxvATLeIe" 10 | ] 11 | }, 12 | "r2_QCE3iV": { 13 | "id": "r2_QCE3iV", 14 | "content": "Recent", 15 | "children": [ 16 | "_Mf5KW0Yc", 17 | "oFAYCtTA0" 18 | ] 19 | }, 20 | "_Mf5KW0Yc": { 21 | "id": "_Mf5KW0Yc", 22 | "content": "Matt Corby - Miracle Love (Live At Manchester Cathedral)", 23 | "children": [ 24 | "5Bjpmj_6D" 25 | ] 26 | }, 27 | "rxvATLeIe": { 28 | "id": "rxvATLeIe", 29 | "content": "All", 30 | "children": [ 31 | "_Mf5KW0Yc", 32 | "oFAYCtTA0", 33 | "w8V8LNKPO", 34 | "NbYhHhFVz" 35 | ] 36 | }, 37 | "5Bjpmj_6D": { 38 | "id": "5Bjpmj_6D", 39 | "content": "https://youtu.be/wHBcO4bjBXs", 40 | "children": [] 41 | }, 42 | "ike9y2a84": { 43 | "id": "ike9y2a84", 44 | "content": "Music", 45 | "children": [ 46 | "_Mf5KW0Yc", 47 | "w8V8LNKPO" 48 | ] 49 | }, 50 | "oCNyqY2fW": { 51 | "id": "oCNyqY2fW", 52 | "content": "Cooking", 53 | "children": [ 54 | "oFAYCtTA0", 55 | "NbYhHhFVz" 56 | ] 57 | }, 58 | "NbYhHhFVz": { 59 | "id": "NbYhHhFVz", 60 | "content": "Binging with Babish: Huevos Rancheros from Breaking Bad", 61 | "children": [ 62 | "krSktDi7Y" 63 | ] 64 | }, 65 | "w8V8LNKPO": { 66 | "id": "w8V8LNKPO", 67 | "content": "Ed Sheeran - Take Me Back To London (Sir Spyro Remix) [feat. Stormzy, Jaykae & Aitch]", 68 | "children": [ 69 | "Du1zDI_lh" 70 | ] 71 | }, 72 | "Du1zDI_lh": { 73 | "id": "Du1zDI_lh", 74 | "content": "https://youtu.be/XJQy_R9CYR4", 75 | "children": [] 76 | }, 77 | "krSktDi7Y": { 78 | "id": "krSktDi7Y", 79 | "content": "https://youtu.be/pdNm4ug9PpE", 80 | "children": [] 81 | }, 82 | "oFAYCtTA0": { 83 | "id": "oFAYCtTA0", 84 | "content": "Spicy garlic fried chicken (Kkanpunggi: 깐풍기)", 85 | "children": [ 86 | "bOoXzLrLW" 87 | ] 88 | }, 89 | "bOoXzLrLW": { 90 | "id": "bOoXzLrLW", 91 | "content": "https://youtu.be/VjneaJ0hmgs", 92 | "children": [] 93 | } 94 | } -------------------------------------------------------------------------------- /packages/viewer/src/Viewer/FixedToolbar.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from "react"; 2 | import { Fragment } from "react"; 3 | 4 | export const FixedToolbar = ({ children }: { children: React.ReactNode }) => { 5 | const [topOffset, setTopOffset] = useState(0); 6 | 7 | const handleViewport = () => { 8 | const layoutViewport = document.getElementById("layoutViewport"); 9 | 10 | if (!layoutViewport) { 11 | return; 12 | } 13 | 14 | // @ts-ignore 15 | const viewport = window.visualViewport; 16 | var offsetTop = 17 | viewport.height - 18 | layoutViewport.getBoundingClientRect().height + 19 | viewport.offsetTop; 20 | 21 | setTopOffset(offsetTop); 22 | }; 23 | 24 | useEffect(() => { 25 | // @ts-ignore 26 | if (window.visualViewport !== undefined) { 27 | // @ts-ignore 28 | window.visualViewport.addEventListener("scroll", handleViewport); 29 | // @ts-ignore 30 | window.visualViewport.addEventListener("resize", handleViewport); 31 | 32 | return () => { 33 | // @ts-ignore 34 | window.visualViewport.removeEventListener("scroll", handleViewport); 35 | // @ts-ignore 36 | window.visualViewport.removeEventListener("resize", handleViewport); 37 | }; 38 | } 39 | }, []); 40 | 41 | return ( 42 | 43 |
47 |
55 | {children} 56 |
57 | 58 | ); 59 | }; 60 | -------------------------------------------------------------------------------- /packages/viewer/src/Viewer/ItemNode.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { useSelector } from "react-redux"; 3 | import { getLastItemInArray } from "./array-util"; 4 | import { getPathFromNodeId, State } from "./duck"; 5 | import { Node } from "./Node"; 6 | 7 | interface ItemNodeProps { 8 | nodeId: string; 9 | readonly: boolean; 10 | } 11 | 12 | export const ItemNode = ({ nodeId, readonly }: ItemNodeProps) => { 13 | const path = getPathFromNodeId(nodeId); 14 | const itemId = getLastItemInArray(path); 15 | 16 | const item = useSelector((state: State) => state.item[itemId]); 17 | 18 | return ( 19 | 26 | ); 27 | }; 28 | -------------------------------------------------------------------------------- /packages/viewer/src/Viewer/Node.tsx: -------------------------------------------------------------------------------- 1 | /** @jsx jsx */ 2 | import { jsx, Styled } from "theme-ui"; 3 | import React, { useEffect } from "react"; 4 | import { useDispatch, useSelector } from "react-redux"; 5 | import { 6 | editItem, 7 | selectItem, 8 | State, 9 | collapse, 10 | expand, 11 | getPathFromNodeId, 12 | getNodeIdFromPath, 13 | ROOT_ID, 14 | } from "./duck"; 15 | import { getLastItemInArray } from "./array-util"; 16 | import { isHref, possiblyPrependBaseUrl, isImageSrc } from "./isHref"; 17 | import { TimelineNode } from "./TimelineNode"; 18 | import { ItemNode } from "./ItemNode"; 19 | 20 | export interface NodeProps { 21 | nodeId: string; 22 | content: string; 23 | children: Array; 24 | expanded: boolean; 25 | readonly: boolean; 26 | } 27 | 28 | export const Node = ({ 29 | nodeId, 30 | content, 31 | children, 32 | expanded: expandedProp, 33 | readonly, 34 | }: NodeProps) => { 35 | const path = getPathFromNodeId(nodeId); 36 | const itemId = getLastItemInArray(path); 37 | 38 | const isRoot = itemId === ROOT_ID; 39 | 40 | const baseUrl = useSelector((state: State) => state.baseUrl); 41 | 42 | const selectedNodeId = useSelector((state: State) => state.nodeId); 43 | const expanded = useSelector((state: State) => 44 | state.expanded.includes(nodeId) 45 | ); 46 | const selected = selectedNodeId === nodeId; 47 | 48 | const dispatch = useDispatch(); 49 | 50 | useEffect(() => { 51 | if (expandedProp) { 52 | dispatch(expand({ path })); 53 | } 54 | }, [expandedProp]); 55 | 56 | const handleChange = (evt: React.ChangeEvent) => { 57 | dispatch(editItem({ id: itemId, content: evt.target.value })); 58 | }; 59 | 60 | const handleClick = () => { 61 | if (readonly) { 62 | handleExpandCollpase(); 63 | } else { 64 | dispatch(selectItem({ nodeId })); 65 | } 66 | }; 67 | 68 | const handleExpandCollpase = () => { 69 | if (!children.length && !isImageSrc(content)) { 70 | return; 71 | } 72 | if (expanded) { 73 | dispatch(collapse({ path })); 74 | } else { 75 | dispatch(expand({ path })); 76 | } 77 | }; 78 | 79 | return ( 80 |
  • 81 | {!isRoot && ( 82 |
    89 | 107 |
    114 | 120 | {isHref(content) ? ( 121 | 126 | {decodeURI(content)} 127 | 128 | ) : ( 129 | content 130 | )} 131 |    132 | 133 | 134 | {selected && ( 135 | 150 | )} 151 |
    152 |
    153 | )} 154 | {expanded && isImageSrc(content) && ( 155 |
    156 | 165 |
    166 | )} 167 | {children && expanded && ( 168 |
      169 | {children.map(child => 170 | child === "timeline" ? ( 171 | 175 | ) : typeof child === "string" ? ( 176 | 181 | ) : ( 182 | 190 | ) 191 | )} 192 |
    193 | )} 194 |
  • 195 | ); 196 | }; 197 | -------------------------------------------------------------------------------- /packages/viewer/src/Viewer/TimelineNode.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { useSelector } from "react-redux"; 3 | import { parse, formatDistance } from "date-fns"; 4 | import { 5 | DATE_FORMAT, 6 | getGroupedTimeline, 7 | getNodeIdFromPath, 8 | getPathFromNodeId, 9 | ItemNode, 10 | State, 11 | } from "./duck"; 12 | import { Node } from "./Node"; 13 | 14 | export interface TimelineNodeProps { 15 | nodeId: string; 16 | } 17 | 18 | export const TimelineNode = ({ nodeId }: TimelineNodeProps) => { 19 | const path = getPathFromNodeId(nodeId); 20 | 21 | const state = useSelector((state: State) => state); 22 | 23 | const groupedTimeline = getGroupedTimeline(state); 24 | 25 | return ( 26 | ({ 30 | nodeId: getNodeIdFromPath([...path, timelineGroup.id]), 31 | content: timelineGroup.content, 32 | children: timelineGroup.children, 33 | readonly: false, 34 | expanded: index === 0, // expand the first timeline entry to start with 35 | }))} 36 | readonly 37 | expanded 38 | /> 39 | ); 40 | }; 41 | -------------------------------------------------------------------------------- /packages/viewer/src/Viewer/ToolbarButton.tsx: -------------------------------------------------------------------------------- 1 | /** @jsx jsx */ 2 | import { jsx } from "theme-ui"; 3 | 4 | export type ToolbarButtonProps = { 5 | onClick?: (event: React.MouseEvent) => void; 6 | title?: string; 7 | children: React.ReactNode; 8 | }; 9 | 10 | export const toolbarButtonStyles = { 11 | py: 2, 12 | px: 3, 13 | border: "none", 14 | background: "none", 15 | }; 16 | 17 | export const ToolbarButton = ({ 18 | onClick, 19 | title, 20 | children, 21 | ...props 22 | }: ToolbarButtonProps) => ( 23 | 26 | ); 27 | -------------------------------------------------------------------------------- /packages/viewer/src/Viewer/ToolbarUploadButton.tsx: -------------------------------------------------------------------------------- 1 | /** @jsx jsx */ 2 | import { jsx, Spinner } from "theme-ui"; 3 | import { toolbarButtonStyles } from "./ToolbarButton"; 4 | import { Fragment, useRef, useState, useEffect } from "react"; 5 | import { usePromise } from "@cadbox1/use-promise"; 6 | 7 | export type ToolbarUploadButtonProps = { 8 | onUpload: (fileWithName: FileWithName) => Promise; 9 | onUploadComplete: (uri: string) => void; 10 | title: string; 11 | children: React.ReactNode; 12 | }; 13 | 14 | export type FileWithName = { 15 | name?: string; 16 | base64: string; 17 | }; 18 | 19 | export const ToolbarUploadButton = ({ 20 | onUpload, 21 | onUploadComplete, 22 | title, 23 | children, 24 | }: ToolbarUploadButtonProps) => { 25 | const fileInput = useRef(null); 26 | 27 | const [fileName, setFileName] = useState(); 28 | const [base64File, setBase64File] = useState(); 29 | 30 | const uploadRequest = usePromise({ 31 | promiseFunction: async () => { 32 | if (!base64File) { 33 | return; 34 | } 35 | const uploadResponse = await onUpload({ 36 | name: fileName, 37 | base64: base64File, 38 | }); 39 | onUploadComplete(uploadResponse); 40 | return uploadResponse; 41 | }, 42 | }); 43 | 44 | useEffect(() => { 45 | uploadRequest.call(); 46 | }, [base64File]); 47 | 48 | const handleChange = () => { 49 | const files = fileInput.current?.files; 50 | if (!files || files.length < 1) { 51 | return; 52 | } 53 | const file = files[0]; 54 | 55 | setFileName(""); 56 | setBase64File(""); 57 | 58 | const reader = new FileReader(); 59 | reader.addEventListener("load", () => { 60 | if (!reader.result || typeof reader.result !== "string") { 61 | return; 62 | } 63 | // https://stackoverflow.com/a/52311051/728602 64 | let encoded = reader.result.toString().replace(/^data:(.*,)?/, ""); 65 | if (encoded.length % 4 > 0) { 66 | encoded += "=".repeat(4 - (encoded.length % 4)); 67 | } 68 | setFileName(file.name || new Date().toUTCString()); 69 | setBase64File(encoded); 70 | if (fileInput.current) { 71 | fileInput.current.value = ""; 72 | } 73 | }); 74 | reader.readAsDataURL(file); 75 | }; 76 | 77 | const handleClick = () => { 78 | fileInput.current?.click(); 79 | }; 80 | 81 | return ( 82 | 83 | 89 | 92 | 93 | ); 94 | }; 95 | -------------------------------------------------------------------------------- /packages/viewer/src/Viewer/Viewer.stories.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from "react"; 2 | import { Provider, useDispatch } from "react-redux"; 3 | import { Button, ThemeProvider } from "theme-ui"; 4 | import { configureStore } from "@reduxjs/toolkit"; 5 | 6 | import theme from "../WebViewer/theme"; 7 | import { load, reducer } from "./duck"; 8 | import { Viewer } from "../Viewer"; 9 | 10 | import cookingExample from "./examples/cookingExample.json"; 11 | import timelineExample from "./examples/timelineExample.json"; 12 | import youtubeExample from "./examples/youtube.json"; 13 | import fileExample from "./examples/file-example.json"; 14 | import { FileWithName } from "./ToolbarUploadButton"; 15 | 16 | const store = configureStore({ 17 | reducer, 18 | }); 19 | 20 | // @ts-ignore 21 | window.store = store; 22 | 23 | const providerDecorator = (StoryFn: any) => ( 24 | 25 | 26 | 27 | 28 | 29 | ); 30 | 31 | export default { 32 | title: "Viewer", 33 | component: Viewer, 34 | decorators: [providerDecorator], 35 | }; 36 | 37 | export const VeryNestedCooking = () => { 38 | const dispatch = useDispatch(); 39 | 40 | useEffect(() => { 41 | dispatch(load({ data: cookingExample, force: true })); 42 | }, []); 43 | 44 | return ; 45 | }; 46 | 47 | export const VeryNestedTimeline = () => { 48 | const dispatch = useDispatch(); 49 | 50 | useEffect(() => { 51 | dispatch(load({ data: timelineExample, force: true })); 52 | }, []); 53 | 54 | return ; 55 | }; 56 | 57 | export const VeryNestedCookingReadonly = () => { 58 | const dispatch = useDispatch(); 59 | 60 | useEffect(() => { 61 | dispatch(load({ data: cookingExample, force: true })); 62 | }, []); 63 | 64 | return ; 65 | }; 66 | 67 | export const VeryNestedYoutube = () => { 68 | const dispatch = useDispatch(); 69 | 70 | useEffect(() => { 71 | dispatch(load({ data: youtubeExample, force: true })); 72 | }, []); 73 | 74 | return ; 75 | }; 76 | 77 | function timeout(delay: number) { 78 | return new Promise(resolve => setTimeout(resolve, delay)); 79 | } 80 | 81 | export const VeryNestedFilesAndUploader = () => { 82 | const dispatch = useDispatch(); 83 | 84 | useEffect(() => { 85 | dispatch(load({ data: fileExample, force: true })); 86 | }, []); 87 | 88 | const handleUpload = async ({ name, base64 }: FileWithName) => { 89 | console.log("name: " + name); 90 | console.log("base64: "); 91 | console.log(base64); 92 | await timeout(2000); 93 | return "./files/Screen Shot 2020-07-11 at 9.42.39 am.png"; 94 | }; 95 | 96 | return ; 97 | }; 98 | 99 | export const VeryNestedRerenderFocusTest = () => { 100 | const [counter, setCounter] = useState(0); 101 | 102 | const handleClick = () => { 103 | setCounter(counter + 1); 104 | }; 105 | 106 | const baseUrl = "baseUrl"; 107 | 108 | return ( 109 |
    110 |

    Counter: {counter}

    111 | 112 |

    clicking increment should make the selected item's input lose focus

    113 | 114 |
    115 | ); 116 | }; 117 | -------------------------------------------------------------------------------- /packages/viewer/src/Viewer/Viewer.test.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import { render, fireEvent, cleanup } from "@testing-library/react"; 3 | import "@testing-library/jest-dom"; 4 | import { Viewer } from "../Viewer"; 5 | 6 | afterEach(cleanup); 7 | 8 | test("displays text and can be clicked", () => { 9 | const onClick = jest.fn(); 10 | 11 | const { getByText } = render(); 12 | }); 13 | -------------------------------------------------------------------------------- /packages/viewer/src/Viewer/array-util.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Get items from an array by it's index with negative indexes working from the end of the array. 3 | * @param input Input array. 4 | * @param index Index to get. Negative indexes work from the end of the array. 5 | */ 6 | export function getItemInArrayByIndex(input: T[], index: number): T { 7 | if (index > 0) { 8 | return input[index]; 9 | } else { 10 | return input[input.length + index]; 11 | } 12 | } 13 | 14 | export function getIndexFromItem( 15 | input: T[], 16 | item: T, 17 | index: number 18 | ): T { 19 | const itemIndex = input.indexOf(item); 20 | return input[itemIndex + index]; 21 | } 22 | 23 | export function insertItemInArrayAfter( 24 | input: T[], 25 | afterItem: T, 26 | item: T 27 | ) { 28 | const insertIndex = input.indexOf(afterItem) + 1; 29 | input.splice(insertIndex, 0, item); 30 | } 31 | 32 | export function getLastItemInArray(input: T[]): T { 33 | return getItemInArrayByIndex(input, -1); 34 | } 35 | 36 | export function removeItemFromArray(input: T[], item: T) { 37 | const targetIndex = input.indexOf(item); 38 | input.splice(targetIndex, 1); 39 | } 40 | 41 | export function objectMap( 42 | obj: {}, 43 | fn: ({ key, value, index }: { key: {}; value: any; index: number }) => T 44 | ) { 45 | return Object.fromEntries( 46 | Object.entries(obj).map(([key, value], index) => [ 47 | key, 48 | fn({ key, value, index }), 49 | ]) 50 | ); 51 | } 52 | -------------------------------------------------------------------------------- /packages/viewer/src/Viewer/duck.ts: -------------------------------------------------------------------------------- 1 | import shortid from "shortid"; 2 | import { format, parse, isToday, formatDistance, isValid } from "date-fns"; 3 | import { createAction, createReducer, PayloadAction } from "@reduxjs/toolkit"; 4 | import enGB from "date-fns/locale/en-GB"; 5 | 6 | import emptyState from "./emptyState.json"; 7 | import { 8 | getItemInArrayByIndex, 9 | insertItemInArrayAfter, 10 | getIndexFromItem, 11 | removeItemFromArray, 12 | } from "./array-util"; 13 | 14 | // I sure do regret not calling this root from the start but I can't be bothered updating the template right now 15 | export const ROOT_ID = "vLlFS3csq"; 16 | 17 | export const DATE_FORMAT = "yyyy-MM-dd"; 18 | 19 | // Load 20 | 21 | type LoadArguments = { 22 | data: ItemStore; 23 | force?: Boolean; 24 | }; 25 | export const load = createAction("LOAD"); 26 | 27 | // Set BaseURL 28 | 29 | type SetBaseUrlArguments = { 30 | baseUrl: string; 31 | }; 32 | export const setBaseUrl = createAction("SET_BASE_URL"); 33 | 34 | // Select Item 35 | 36 | type SelectItemArguments = { 37 | nodeId: string; 38 | }; 39 | export const selectItem = createAction("SELECT_ITEM"); 40 | 41 | // Edit Item 42 | 43 | type EditItemArguments = { 44 | id: string; 45 | content: string; 46 | }; 47 | export const editItem = createAction("EDIT_ITEM"); 48 | 49 | // Add Item 50 | 51 | type AddItemAction = { 52 | afterNodeId: string; 53 | id: string; 54 | content: string; 55 | children: string[]; 56 | }; 57 | export const addItem = createAction("ADD", () => ({ 58 | payload: { 59 | id: shortid.generate(), 60 | content: "", 61 | children: [], 62 | }, 63 | })); 64 | 65 | // Remove Item 66 | 67 | export const removeItem = createAction("REMOVE_ITEM"); 68 | 69 | // Indent Item 70 | 71 | type IndentItemArguments = { 72 | path: string[]; 73 | }; 74 | export const indentItem = createAction("INDENT_ITEM"); 75 | 76 | // Undent Item 77 | 78 | type UndentItemArguments = { 79 | path: string[]; 80 | }; 81 | export const undentItem = createAction("UNDENT_ITEM"); 82 | 83 | // Move up 84 | 85 | type MoveUpArguments = { 86 | path: string[]; 87 | }; 88 | export const moveUp = createAction("MOVE_UP"); 89 | 90 | // Move down 91 | 92 | type MoveDownArguments = { 93 | path: string[]; 94 | }; 95 | export const moveDown = createAction("MOVE_DOWN"); 96 | 97 | // Up 98 | 99 | type UpArguments = { 100 | path: string[]; 101 | }; 102 | export const up = createAction("UP"); 103 | 104 | // Down 105 | 106 | type DownArguments = { 107 | path: string[]; 108 | }; 109 | export const down = createAction("DOWN"); 110 | 111 | // Expand 112 | 113 | type ExpandArguments = { 114 | path: string[]; 115 | }; 116 | export const expand = createAction("EXPAND"); 117 | 118 | // Collapse 119 | 120 | type CollapseArguments = { 121 | path: string[]; 122 | }; 123 | export const collapse = createAction("COLLAPSE"); 124 | 125 | // Store 126 | 127 | export type Item = { 128 | id: string; 129 | content: string; 130 | error?: string; 131 | children: string[]; 132 | }; 133 | 134 | export type ItemStore = { 135 | [key: string]: Item; 136 | }; 137 | 138 | export type State = { 139 | baseUrl?: string; 140 | nodeId?: string; 141 | item: ItemStore; 142 | expanded: string[]; 143 | }; 144 | 145 | // Reducer 146 | 147 | export const reducer = createReducer(emptyState, { 148 | // Load 149 | 150 | [load.type]: (state: State, action: PayloadAction) => { 151 | if (action.payload.force) { 152 | state.expanded = emptyState.expanded; 153 | } 154 | 155 | state.nodeId = undefined; 156 | state.item = action.payload.data; 157 | 158 | if (state.expanded.length === 0) { 159 | // expand the first two levels to start with 160 | state.expanded = [ 161 | ROOT_ID, 162 | ...state.item[ROOT_ID].children.map(childId => 163 | getNodeIdFromPath([ROOT_ID, childId]) 164 | ), 165 | ]; 166 | } 167 | }, 168 | 169 | // Set BaseURL 170 | 171 | [setBaseUrl.type]: ( 172 | state: State, 173 | action: PayloadAction 174 | ) => { 175 | state.baseUrl = action.payload.baseUrl; 176 | }, 177 | 178 | // Select Item 179 | 180 | [selectItem.type]: ( 181 | state: State, 182 | action: PayloadAction 183 | ) => { 184 | state.nodeId = action.payload.nodeId; 185 | }, 186 | 187 | // Edit Item 188 | 189 | [editItem.type]: (state: State, action: PayloadAction) => { 190 | const { id, content } = action.payload; 191 | 192 | // let's not worry about linking for now 193 | 194 | // if (Object.keys(state.item).includes(content)) { 195 | // // content is an id, replace it with a reference to the existing item. 196 | // const referencedItemId = content; 197 | // replaceAllReferencesToId(id, referencedItemId, state); 198 | // deleteItem(id, state); 199 | // } 200 | 201 | if (!state.nodeId) { 202 | return; 203 | } 204 | 205 | const node = new ItemNode({ 206 | nodeId: state.nodeId, 207 | state, 208 | }); 209 | 210 | node.item.content = content; 211 | 212 | potentiallyReselectNode(node.nodeId, state); 213 | 214 | // now handle the timeline 215 | 216 | // the data structure for the timeline is a flat list of dates of the topmost parent 217 | // the view aggregates those dates into chunks 218 | 219 | if (node.path.includes("timeline")) { 220 | // don't handle the timeline for timeline edits 221 | return; 222 | } 223 | 224 | const timelineNode = ItemNode.getByNodeId({ 225 | nodeId: getNodeIdFromPath([ROOT_ID, "timeline"]), 226 | state, 227 | }); 228 | 229 | if (!timelineNode) { 230 | return; 231 | } 232 | 233 | // update the timeline entry string if it exists 234 | const existingTimelineNode = findTodayTimelineEntryForItemId(id, state); 235 | if (existingTimelineNode) { 236 | existingTimelineNode.item.content = getTimelineString(node); 237 | return; 238 | } 239 | 240 | // if there's a timeline entry in another day then there's nothing more to do - don't capture edits 241 | const olderNodes = getOlderTimelineEntries(state); 242 | if (olderNodes.some(olderNode => olderNode.childNodes[0]?.item.id === id)) { 243 | return; 244 | } 245 | 246 | // if a parent has a timeline entry then there's nothing more to do 247 | const todaysNodes = getTodaysTimelineEntries(state); 248 | if ( 249 | todaysNodes.some(todayNode => 250 | node.parentNode.path.includes(todayNode.childNodes[0].item.id) 251 | ) 252 | ) { 253 | return; 254 | } 255 | 256 | // add to timeline 257 | const timelineId = shortid.generate(); 258 | 259 | const timelineDateId = shortid.generate(); 260 | const timelineDateString = format(new Date(), DATE_FORMAT); 261 | 262 | state.item[timelineDateId] = { 263 | id: timelineDateId, 264 | content: timelineDateString, 265 | children: [], 266 | }; 267 | 268 | state.item[timelineId] = { 269 | id: timelineId, 270 | content: getTimelineString(node), 271 | children: [node.item.id, node.parentNode.item.id, timelineDateId], 272 | }; 273 | 274 | // add a timeline if the document doesn't have one already 275 | if (!state.item["timeline"]) { 276 | state.item["timeline"] = { 277 | id: "timeline", 278 | content: "Timeline", 279 | children: [], 280 | }; 281 | state.item[ROOT_ID].children.push("timeline"); 282 | } 283 | 284 | state.item["timeline"].children.unshift(timelineId); 285 | 286 | // @todo unlink any previous references and freeze their contents to x number of levels 287 | 288 | // const oldReferencedNodes = olderNodes.filter(olderNode => 289 | // node.path.includes(olderNode.childNodes[0].item.id) 290 | // ); 291 | }, 292 | 293 | // Add Item 294 | 295 | [addItem.type]: (state: State, action: PayloadAction) => { 296 | const { id, content, children } = action.payload; 297 | 298 | if (!state.nodeId) { 299 | return; 300 | } 301 | 302 | const node = new ItemNode({ nodeId: state.nodeId, state }); 303 | node.insertItemAfterThisNode({ id, content, children }); 304 | }, 305 | 306 | // Remove Item 307 | 308 | [removeItem.type]: (state: State) => { 309 | if (!state.nodeId) { 310 | return; 311 | } 312 | 313 | const path = getPathFromNodeId(state.nodeId); 314 | const id = getItemInArrayByIndex(path, -1); 315 | 316 | const node = new ItemNode({ nodeId: state.nodeId, state }); 317 | node.selectPreviousNode(); 318 | node.delete(); 319 | }, 320 | 321 | // Indent Item 322 | 323 | [indentItem.type]: (state: State, action: IndentItemArguments) => { 324 | const { id, collection } = getItemFromPath( 325 | state.item, 326 | getPathFromNodeId(state.nodeId) 327 | ); 328 | 329 | const newParentId = getIndexFromItem(collection, id, -1); 330 | if (!newParentId) { 331 | return; 332 | } 333 | 334 | const newParent = state.item[newParentId]; 335 | newParent.children.push(id); 336 | 337 | const path = getPathFromNodeId(state.nodeId); 338 | path.pop(); 339 | path.push(newParentId, id); 340 | state.nodeId = getNodeIdFromPath(path); 341 | 342 | const parentPath = path.slice(0, -1); 343 | const pathId = getNodeIdFromPath(parentPath); 344 | const expandedSet = new Set(state.expanded); 345 | expandedSet.add(pathId); 346 | state.expanded = Array.from(expandedSet); 347 | 348 | removeItemFromArray(collection, id); 349 | }, 350 | 351 | // Undent Item 352 | 353 | [undentItem.type]: (state: State, action: UndentItemArguments) => { 354 | const { id, parentId, parentsParentId, collection } = getItemFromPath( 355 | state.item, 356 | getPathFromNodeId(state.nodeId) 357 | ); 358 | 359 | if (!parentId || !parentsParentId) { 360 | return; 361 | } 362 | 363 | const parentsCollection = getCollection(state.item, parentsParentId); 364 | insertItemInArrayAfter(parentsCollection, parentId, id); 365 | 366 | const path = getPathFromNodeId(state.nodeId); 367 | path.splice(-2); 368 | path.push(id); 369 | state.nodeId = getNodeIdFromPath(path); 370 | 371 | removeItemFromArray(collection, id); 372 | }, 373 | 374 | // Move Up 375 | 376 | [moveUp.type]: (state: State, action: MoveUpArguments) => { 377 | const { id, index, collection } = getItemFromPath( 378 | state.item, 379 | getPathFromNodeId(state.nodeId) 380 | ); 381 | 382 | const aboveItemId = getIndexFromItem(collection, id, -1); 383 | 384 | if (!aboveItemId) { 385 | return; 386 | } 387 | 388 | collection[index - 1] = id; 389 | collection[index] = aboveItemId; 390 | }, 391 | 392 | // Move Down 393 | 394 | [moveDown.type]: (state: State, action: MoveDownArguments) => { 395 | const { id, index, collection } = getItemFromPath( 396 | state.item, 397 | getPathFromNodeId(state.nodeId) 398 | ); 399 | 400 | const belowItemId = getIndexFromItem(collection, id, 1); 401 | 402 | if (!belowItemId) { 403 | return; 404 | } 405 | 406 | collection[index + 1] = id; 407 | collection[index] = belowItemId; 408 | }, 409 | 410 | // Up 411 | 412 | [up.type]: (state: State, action: UpArguments) => { 413 | if (!state.nodeId) { 414 | return state; 415 | } 416 | 417 | const node = new ItemNode({ nodeId: state.nodeId, state }); 418 | node.selectPreviousNode(); 419 | }, 420 | 421 | // Down 422 | 423 | [down.type]: (state: State, action: DownArguments) => { 424 | if (!state.nodeId) { 425 | return state; 426 | } 427 | 428 | const node = new ItemNode({ nodeId: state.nodeId, state }); 429 | node.selectNextNode(); 430 | }, 431 | 432 | // Expand 433 | 434 | [expand.type]: (state: State, action: PayloadAction) => { 435 | const pathId = getNodeIdFromPath(action.payload.path); 436 | const expandedSet = new Set(state.expanded); 437 | expandedSet.add(pathId); 438 | state.expanded = Array.from(expandedSet); 439 | }, 440 | 441 | // Collapse 442 | 443 | [collapse.type]: (state: State, action: PayloadAction) => { 444 | const pathId = getNodeIdFromPath(action.payload.path); 445 | const expandedSet = new Set(state.expanded); 446 | expandedSet.delete(pathId); 447 | state.expanded = Array.from(expandedSet); 448 | }, 449 | }); 450 | 451 | function getItemFromPath( 452 | itemStore: ItemStore, 453 | path: string[] 454 | ): { 455 | id: string; 456 | index: number; 457 | parentId: string; 458 | parentsParentId: string; 459 | collection: string[]; 460 | children: string[]; 461 | } { 462 | const id = getItemInArrayByIndex(path, -1); 463 | const parentId = getItemInArrayByIndex(path, -2); 464 | const parentsParentId = getItemInArrayByIndex(path, -3); 465 | 466 | const collection = parentId ? getCollection(itemStore, parentId) : []; 467 | const index = collection ? collection.indexOf(id) : -1; 468 | 469 | const children = itemStore[id].children; 470 | 471 | return { id, index, parentId, parentsParentId, collection, children }; 472 | } 473 | 474 | function getCollection(itemStore: ItemStore, parentId: string): string[] { 475 | return itemStore[parentId].children; 476 | } 477 | 478 | // previously used for linking 479 | 480 | // const replaceAllReferencesToId = ( 481 | // oldId: string, 482 | // newId: string, 483 | // state: State 484 | // ) => { 485 | // getAllItemsWithIdInChildren(oldId, state, item => { 486 | // item.children = item.children.map(childId => 487 | // childId === oldId ? newId : childId 488 | // ); 489 | // }); 490 | // }; 491 | 492 | export function getNodeIdFromPath(path: string[]): string { 493 | return path.join(","); 494 | } 495 | 496 | export function getPathFromNodeId(nodeId?: string): string[] { 497 | if (!nodeId) { 498 | return []; 499 | } 500 | return nodeId.split(","); 501 | } 502 | 503 | export class ItemNode { 504 | nodeId: string; 505 | path: string[]; 506 | item: Item; 507 | state: State; 508 | 509 | static getByNodeId({ nodeId, state }: { nodeId: string; state: State }) { 510 | const path = getPathFromNodeId(nodeId); 511 | const item = state.item[getItemInArrayByIndex(path, -1)]; 512 | 513 | if (!item) { 514 | return null; 515 | } 516 | 517 | return new ItemNode({ nodeId, state }); 518 | } 519 | 520 | constructor({ nodeId, state }: { nodeId: string; state: State }) { 521 | this.nodeId = nodeId; 522 | this.state = state; 523 | 524 | this.path = getPathFromNodeId(nodeId); 525 | this.item = this.state.item[getItemInArrayByIndex(this.path, -1)]; 526 | } 527 | 528 | get parentNode() { 529 | return new ItemNode({ 530 | nodeId: getNodeIdFromPath(this.path.slice(0, -1)), 531 | state: this.state, 532 | }); 533 | } 534 | 535 | get childNodes() { 536 | return this.item.children.map( 537 | childId => 538 | new ItemNode({ 539 | nodeId: getNodeIdFromPath([...this.path, childId]), 540 | state: this.state, 541 | }) 542 | ); 543 | } 544 | 545 | get expanded() { 546 | return this.state.expanded.includes(this.nodeId); 547 | } 548 | 549 | get index() { 550 | return this.parentNode.item.children.indexOf(this.item.id); 551 | } 552 | 553 | get previousSibling(): ItemNode | null { 554 | if (this.index === 0) { 555 | return null; 556 | } 557 | const siblingId = this.parentNode.childNodes[this.index - 1].item.id; 558 | const newPath = [...this.parentNode.path, siblingId]; 559 | return new ItemNode({ 560 | nodeId: getNodeIdFromPath(newPath), 561 | state: this.state, 562 | }); 563 | } 564 | 565 | get nextSibling(): ItemNode | null { 566 | if (this.index === this.parentNode.childNodes.length - 1) { 567 | return null; 568 | } 569 | const siblingId = this.parentNode.childNodes[this.index + 1].item.id; 570 | const newPath = [...this.parentNode.path, siblingId]; 571 | return new ItemNode({ 572 | nodeId: getNodeIdFromPath(newPath), 573 | state: this.state, 574 | }); 575 | } 576 | 577 | select() { 578 | this.state.nodeId = this.nodeId; 579 | } 580 | 581 | selectNextNode() { 582 | if (this.expanded) { 583 | this.childNodes[0].select(); 584 | } else { 585 | let node: ItemNode = this; 586 | while (!node.nextSibling) { 587 | node = node.parentNode; 588 | } 589 | node.nextSibling.select(); 590 | } 591 | } 592 | 593 | selectPreviousNode() { 594 | if (!this.previousSibling) { 595 | this.parentNode.select(); 596 | return; 597 | } 598 | 599 | let node = this.previousSibling; 600 | while (node.expanded) { 601 | node = getItemInArrayByIndex(node.childNodes, -1); 602 | } 603 | node.select(); 604 | } 605 | 606 | insertItemAfterThisNode(newItem: Item) { 607 | this.state.item[newItem.id] = newItem; 608 | 609 | // if expanded then add as a new child otherwise add as a new sibling 610 | if (this.expanded) { 611 | this.item.children.unshift(newItem.id); 612 | } else { 613 | insertItemInArrayAfter( 614 | this.parentNode.item.children, 615 | this.item.id, 616 | newItem.id 617 | ); 618 | } 619 | this.selectNextNode(); 620 | } 621 | 622 | delete() { 623 | const id = this.item.id; 624 | 625 | const timelineEntry = findTodayTimelineEntryForItemId(id, this.state); 626 | if (timelineEntry) { 627 | timelineEntry.delete(); 628 | } 629 | 630 | const allParents = Object.keys(this.state.item) 631 | .filter(itemId => { 632 | const item = this.state.item[itemId]; 633 | return item.children.includes(id); 634 | }) 635 | .map(parentId => this.state.item[parentId]); 636 | 637 | allParents.forEach(parent => { 638 | parent.children = parent.children.filter(childId => childId !== id); 639 | }); 640 | 641 | delete this.state.item[id]; 642 | } 643 | } 644 | 645 | function getTimelineString(node: ItemNode) { 646 | return `added ${node.item.content} to ${node.parentNode.item.content}`; 647 | } 648 | 649 | const locale: Locale = { 650 | ...enGB, 651 | formatDistance: (...args) => { 652 | const [arg1, ...otherArgs] = args; 653 | 654 | const todayKeys = ["lessThanXMinutes", "xMinutes", "aboutXHours"]; 655 | 656 | if (todayKeys.includes(arg1)) { 657 | return "Today"; 658 | } 659 | // @ts-ignore 660 | return enGB.formatDistance(...args); 661 | }, 662 | }; 663 | 664 | export function getGroupedTimeline(state: State) { 665 | const timelineNode = ItemNode.getByNodeId({ 666 | nodeId: getNodeIdFromPath([ROOT_ID, "timeline"]), 667 | state, 668 | }); 669 | 670 | if (!timelineNode) { 671 | return []; 672 | } 673 | 674 | const sortedTimelineNodes = timelineNode.childNodes 675 | .map(childNode => { 676 | const inputDateString = 677 | childNode.childNodes[2]?.item.content || 678 | childNode.item.content.split(" - ")[0]; // this is the briefly used, legacy date format 679 | 680 | const parsedDate = parse(inputDateString, DATE_FORMAT, new Date()); 681 | 682 | const dateString = isValid(parsedDate) ? inputDateString : "Invalid Date"; 683 | 684 | return { 685 | childNode, 686 | dateString, 687 | }; 688 | }) 689 | .sort((a, b) => a.dateString.localeCompare(b.dateString)) 690 | .reverse(); 691 | 692 | const groupedMap = sortedTimelineNodes.reduce((entryMap, timelineNode) => { 693 | const parsedDate = parse(timelineNode.dateString, DATE_FORMAT, new Date()); 694 | 695 | const dateGroupString = isValid(parsedDate) 696 | ? formatDistance(parsedDate, new Date(), { 697 | addSuffix: true, 698 | locale, 699 | }) 700 | : timelineNode.dateString; 701 | 702 | return entryMap.set(dateGroupString, [ 703 | ...(entryMap.get(dateGroupString) || []), 704 | timelineNode.childNode, 705 | ]); 706 | }, new Map()); 707 | 708 | return Array.from(groupedMap).map(([dateGroupString, timelineItemNodes]) => ({ 709 | id: dateGroupString, 710 | content: dateGroupString, 711 | children: timelineItemNodes.map( 712 | timelineItemNode => timelineItemNode.item.id 713 | ), 714 | })); 715 | } 716 | 717 | function getTodaysTimelineEntries(state: State) { 718 | const timelineNode = ItemNode.getByNodeId({ 719 | nodeId: getNodeIdFromPath([ROOT_ID, "timeline"]), 720 | state, 721 | }); 722 | 723 | if (!timelineNode) { 724 | return []; 725 | } 726 | 727 | return timelineNode.childNodes.filter(childNode => { 728 | const childNodesDate = parse( 729 | childNode.childNodes[2]?.item.content, 730 | DATE_FORMAT, 731 | new Date() 732 | ); 733 | return isToday(childNodesDate); 734 | }); 735 | } 736 | 737 | function getOlderTimelineEntries(state: State) { 738 | const timelineNode = ItemNode.getByNodeId({ 739 | nodeId: getNodeIdFromPath([ROOT_ID, "timeline"]), 740 | state, 741 | }); 742 | 743 | if (!timelineNode) { 744 | return []; 745 | } 746 | 747 | return timelineNode.childNodes.filter(childNode => { 748 | const childNodesDate = parse( 749 | childNode.childNodes[2]?.item.content, 750 | DATE_FORMAT, 751 | new Date() 752 | ); 753 | return !isToday(childNodesDate); 754 | }); 755 | } 756 | 757 | function findTodayTimelineEntryForItemId( 758 | itemId: string, 759 | state: State 760 | ): ItemNode | undefined { 761 | const todaysNodes = getTodaysTimelineEntries(state); 762 | 763 | return todaysNodes.find( 764 | todayNode => todayNode.childNodes[0]?.item.id === itemId 765 | ); 766 | } 767 | 768 | function potentiallyReselectNode(inputNodeId: string, state: State) { 769 | const closestNodeId = findClosestNodeId(inputNodeId, state); 770 | if (inputNodeId !== closestNodeId) { 771 | state.nodeId = closestNodeId; 772 | 773 | const path = getPathFromNodeId(closestNodeId); 774 | 775 | const expandedSet = new Set(state.expanded); 776 | 777 | for (let i = 1; i <= path.length; i++) { 778 | expandedSet.add(getNodeIdFromPath(path.slice(0, i))); 779 | } 780 | state.expanded = Array.from(expandedSet); 781 | } 782 | } 783 | 784 | function findClosestNodeId(inputNodeId: string, state: State): string { 785 | const inputPath = getPathFromNodeId(inputNodeId); 786 | const id = getItemInArrayByIndex(inputPath, -1); 787 | 788 | const inputNode = new ItemNode({ nodeId: inputNodeId, state }); 789 | 790 | let node = inputNode; 791 | let endPath = [id]; // This isn't quite correct because we might be missing the item we're requesting but let's come back to this later 792 | 793 | while (node.parentNode.item) { 794 | node = node.parentNode; 795 | endPath.unshift(node.item.id); 796 | } 797 | const nodeWithoutParentItem = node; 798 | const pathBelowMissingParent = endPath; 799 | 800 | // let's look inside our grouped timeline 801 | const groupedTimeline = getGroupedTimeline(state); 802 | const timelineGroupWithMissingNode = groupedTimeline.find(timelineGroup => 803 | timelineGroup.children.includes(nodeWithoutParentItem.item.id) 804 | ); 805 | 806 | if (timelineGroupWithMissingNode) { 807 | const path = [ 808 | ROOT_ID, 809 | "timeline", 810 | timelineGroupWithMissingNode.id, 811 | ...pathBelowMissingParent, 812 | ]; 813 | return getNodeIdFromPath(path); 814 | } else { 815 | // look through the rest of the document. We can do this later. 816 | return inputNodeId; 817 | } 818 | } 819 | -------------------------------------------------------------------------------- /packages/viewer/src/Viewer/emptyState.json: -------------------------------------------------------------------------------- 1 | { 2 | "item": { 3 | "vLlFS3csq": { 4 | "id": "vLlFS3csq", 5 | "content": "Home", 6 | "children": [ 7 | "r2_QCE3iV" 8 | ] 9 | }, 10 | "r2_QCE3iV": { 11 | "id": "vLlFS3csq", 12 | "content": "first note", 13 | "children": [] 14 | } 15 | }, 16 | "expanded": [] 17 | } -------------------------------------------------------------------------------- /packages/viewer/src/Viewer/examples/cookingExample.json: -------------------------------------------------------------------------------- 1 | { 2 | "vLlFS3csq": { 3 | "id": "vLlFS3csq", 4 | "content": "Home", 5 | "children": ["r2_QCE3iV"] 6 | }, 7 | "r2_QCE3iV": { 8 | "id": "r2_QCE3iV", 9 | "content": "Recipes", 10 | "children": ["0rwUXExHw", "PMOYaGpEw"] 11 | }, 12 | "0rwUXExHw": { 13 | "id": "0rwUXExHw", 14 | "content": "All", 15 | "children": [ 16 | "OEOewbVWh", 17 | "bIsT1lv4L", 18 | "HEdzn1RZS", 19 | "28YDiptbl", 20 | "lgG5lgOg9", 21 | "vKZ5SL0bU" 22 | ] 23 | }, 24 | "OEOewbVWh": { 25 | "id": "OEOewbVWh", 26 | "content": "Thai Green Curry", 27 | "children": [] 28 | }, 29 | "bIsT1lv4L": { 30 | "id": "bIsT1lv4L", 31 | "content": "Greek Salad", 32 | "children": [] 33 | }, 34 | "HEdzn1RZS": { 35 | "id": "HEdzn1RZS", 36 | "content": "Toby's Chicken", 37 | "children": [] 38 | }, 39 | "28YDiptbl": { 40 | "id": "28YDiptbl", 41 | "content": "Beef Stir Fry", 42 | "children": [] 43 | }, 44 | "lgG5lgOg9": { 45 | "id": "lgG5lgOg9", 46 | "content": "Red Pasta", 47 | "children": [] 48 | }, 49 | "PMOYaGpEw": { 50 | "id": "PMOYaGpEw", 51 | "content": "Healthy", 52 | "children": ["bIsT1lv4L", "HEdzn1RZS", "28YDiptbl"] 53 | }, 54 | "vKZ5SL0bU": { 55 | "id": "vKZ5SL0bU", 56 | "content": "Carbonara", 57 | "children": [] 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /packages/viewer/src/Viewer/examples/file-example.json: -------------------------------------------------------------------------------- 1 | { 2 | "vLlFS3csq": { 3 | "id": "vLlFS3csq", 4 | "content": "file example", 5 | "children": ["bEsr1kjQy", "fCjbzSDxQ"] 6 | }, 7 | "bEsr1kjQy": { 8 | "id": "bEsr1kjQy", 9 | "content": "this has an image in it", 10 | "children": ["Zw9Rx253e", "RUZp57w5r"] 11 | }, 12 | "Zw9Rx253e": { 13 | "id": "Zw9Rx253e", 14 | "content": "./files/Screen Shot 2020-07-11 at 9.42.39 am.png", 15 | "children": [] 16 | }, 17 | "fCjbzSDxQ": { 18 | "id": "fCjbzSDxQ", 19 | "content": "this has a file in it", 20 | "children": ["RUfMRy58L", "JbZBQ1ZAb"] 21 | }, 22 | "RUZp57w5r": { 23 | "id": "RUZp57w5r", 24 | "content": "as you can see, the above image is cool", 25 | "children": [] 26 | }, 27 | "RUfMRy58L": { 28 | "id": "RUfMRy58L", 29 | "content": "./files/example.md", 30 | "children": [] 31 | }, 32 | "JbZBQ1ZAb": { 33 | "id": "JbZBQ1ZAb", 34 | "content": "the above file is also cool", 35 | "children": [] 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /packages/viewer/src/Viewer/examples/timelineExample.json: -------------------------------------------------------------------------------- 1 | { 2 | "vLlFS3csq": { 3 | "id": "vLlFS3csq", 4 | "content": "Home", 5 | "children": [ 6 | "EbvcZS6ay", 7 | "timeline" 8 | ] 9 | }, 10 | "UqXkkU1Tw": { 11 | "id": "UqXkkU1Tw", 12 | "content": "", 13 | "children": [] 14 | }, 15 | "8m0ui3nDQ": { 16 | "id": "8m0ui3nDQ", 17 | "content": "", 18 | "children": [] 19 | }, 20 | "du1jYME4n": { 21 | "id": "du1jYME4n", 22 | "content": "2022-07-25 - created document", 23 | "children": [] 24 | }, 25 | "timeline": { 26 | "id": "timeline", 27 | "content": "Timeline", 28 | "children": [ 29 | "AHSVWPkJ1", 30 | "qawT5LuNz", 31 | "QKGTeBTQH", 32 | "hApuoe7qE", 33 | "LW3mHHa7A", 34 | "Q7XCz-lRt", 35 | "H5xY8el37", 36 | "7ZKXkPqVK", 37 | "fLM3h5GBp", 38 | "RyTyhNq3F", 39 | "YlJlgCeGX", 40 | "sHMsGu1Ix", 41 | "4NaDjWGzA", 42 | "_NTfRgsEgi", 43 | "d1NpzUXWT", 44 | "asA6Xek3m", 45 | "QNTwhKeOt", 46 | "qr8360Ej9", 47 | "TcdtzwVP6", 48 | "xdhuA8CG_x", 49 | "yKjL8W42a", 50 | "Dgyu0WIwY", 51 | "VYkBJpDzH", 52 | "rcp7m7bNZ", 53 | "2Mf0dC86b7", 54 | "iRM09KRJZc", 55 | "XYDBLd_77I", 56 | "c3uL4OYw1l", 57 | "MvomVrI3d", 58 | "5LPgmQ9AB", 59 | "mx3YFEr_-", 60 | "eYPTF8Zx9", 61 | "du1jYME4n" 62 | ] 63 | }, 64 | "x4sZcTgAb": { 65 | "id": "x4sZcTgAb", 66 | "content": "TV", 67 | "children": [ 68 | "V-4YTMxrJ" 69 | ] 70 | }, 71 | "V-4YTMxrJ": { 72 | "id": "V-4YTMxrJ", 73 | "content": "Watchlist", 74 | "children": [] 75 | }, 76 | "xPTuqV8IX": { 77 | "id": "xPTuqV8IX", 78 | "content": "", 79 | "children": [] 80 | }, 81 | "EbvcZS6ay": { 82 | "id": "EbvcZS6ay", 83 | "content": "Notes", 84 | "children": [ 85 | "toYeo0WAh" 86 | ] 87 | }, 88 | "eYPTF8Zx9": { 89 | "id": "eYPTF8Zx9", 90 | "content": "2022-07-25 - added Notes to Home", 91 | "children": [ 92 | "EbvcZS6ay" 93 | ] 94 | }, 95 | "toYeo0WAh": { 96 | "id": "toYeo0WAh", 97 | "content": "TV and Movies", 98 | "children": [ 99 | "i8PDYHzJv", 100 | "5ASUHXjun", 101 | "LVSjVUr7s", 102 | "YF3bFODc_" 103 | ] 104 | }, 105 | "mx3YFEr_-": { 106 | "id": "mx3YFEr_-", 107 | "content": "2022-07-25 - added TV and Movies to Notes", 108 | "children": [ 109 | "toYeo0WAh" 110 | ] 111 | }, 112 | "i8PDYHzJv": { 113 | "id": "i8PDYHzJv", 114 | "content": "Inbox", 115 | "children": [ 116 | "hrQhq8qIQ", 117 | "clkv759yR", 118 | "I8eHzPDaA", 119 | "dmEYnsF8S", 120 | "GFyq4SsOS", 121 | "zbxJ8_cKq", 122 | "viZ7w1vjv", 123 | "_Tb46IJou", 124 | "fZeiKMIJr", 125 | "9SXQB56xQ", 126 | "nyxlcXzOJ" 127 | ] 128 | }, 129 | "5LPgmQ9AB": { 130 | "id": "5LPgmQ9AB", 131 | "content": "2022-07-25 - added Inbox to TV and Movies", 132 | "children": [ 133 | "i8PDYHzJv" 134 | ] 135 | }, 136 | "clkv759yR": { 137 | "id": "clkv759yR", 138 | "content": "watch Armageddon on Disney", 139 | "children": [] 140 | }, 141 | "MvomVrI3d": { 142 | "id": "MvomVrI3d", 143 | "content": "2022-07-25 - added watch Armageddon on Disney to Inbox", 144 | "children": [ 145 | "clkv759yR" 146 | ] 147 | }, 148 | "I8eHzPDaA": { 149 | "id": "I8eHzPDaA", 150 | "content": "watch Inside Out on Disney", 151 | "children": [] 152 | }, 153 | "c3uL4OYw1l": { 154 | "id": "c3uL4OYw1l", 155 | "content": "2022-07-25 - added watch Inside Out on Disney to Inbox", 156 | "children": [ 157 | "I8eHzPDaA" 158 | ] 159 | }, 160 | "dmEYnsF8S": { 161 | "id": "dmEYnsF8S", 162 | "content": "watch Breath on Foxtel or Prime", 163 | "children": [] 164 | }, 165 | "XYDBLd_77I": { 166 | "id": "XYDBLd_77I", 167 | "content": "2022-07-25 - added watch Breath on Foxtel or Prime to Inbox", 168 | "children": [ 169 | "dmEYnsF8S" 170 | ] 171 | }, 172 | "GFyq4SsOS": { 173 | "id": "GFyq4SsOS", 174 | "content": "watch Bullet Train at the movies", 175 | "children": [] 176 | }, 177 | "iRM09KRJZc": { 178 | "id": "iRM09KRJZc", 179 | "content": "2022-07-25 - added watch Bullet Train at the movies to Inbox", 180 | "children": [ 181 | "GFyq4SsOS" 182 | ] 183 | }, 184 | "zbxJ8_cKq": { 185 | "id": "zbxJ8_cKq", 186 | "content": "watch Top Gun at the Movies", 187 | "children": [] 188 | }, 189 | "2Mf0dC86b7": { 190 | "id": "2Mf0dC86b7", 191 | "content": "2022-07-25 - added watch Top Gun at the Movies to Inbox", 192 | "children": [ 193 | "zbxJ8_cKq" 194 | ] 195 | }, 196 | "viZ7w1vjv": { 197 | "id": "viZ7w1vjv", 198 | "content": "watch The Grand Budapest Hotel on Disney or Foxtel", 199 | "children": [] 200 | }, 201 | "rcp7m7bNZ": { 202 | "id": "rcp7m7bNZ", 203 | "content": "2022-07-25 - added watch The Grand Budapest Hotel on Disney or Foxtel to Inbox", 204 | "children": [ 205 | "viZ7w1vjv" 206 | ] 207 | }, 208 | "_Tb46IJou": { 209 | "id": "_Tb46IJou", 210 | "content": "watch Fantastic Mr. Fox on Disney", 211 | "children": [] 212 | }, 213 | "VYkBJpDzH": { 214 | "id": "VYkBJpDzH", 215 | "content": "2022-07-25 - added watch Fantastic Mr. Fox on Disney to Inbox", 216 | "children": [ 217 | "_Tb46IJou" 218 | ] 219 | }, 220 | "fZeiKMIJr": { 221 | "id": "fZeiKMIJr", 222 | "content": "watch The French Dispatch on Disney or Foxtel", 223 | "children": [] 224 | }, 225 | "Dgyu0WIwY": { 226 | "id": "Dgyu0WIwY", 227 | "content": "2022-07-25 - added watch The French Dispatch on Disney or Foxtel to Inbox", 228 | "children": [ 229 | "fZeiKMIJr" 230 | ] 231 | }, 232 | "9SXQB56xQ": { 233 | "id": "9SXQB56xQ", 234 | "content": "watch Corpse Bridge on Foxtel", 235 | "children": [] 236 | }, 237 | "yKjL8W42a": { 238 | "id": "yKjL8W42a", 239 | "content": "2022-07-25 - added watch Corpse Bridge on Foxtel to Inbox", 240 | "children": [ 241 | "9SXQB56xQ" 242 | ] 243 | }, 244 | "nyxlcXzOJ": { 245 | "id": "nyxlcXzOJ", 246 | "content": "watch Blueback when it's out", 247 | "children": [] 248 | }, 249 | "xdhuA8CG_x": { 250 | "id": "xdhuA8CG_x", 251 | "content": "2022-07-25 - added watch Blueback when it's out to Inbox", 252 | "children": [ 253 | "nyxlcXzOJ" 254 | ] 255 | }, 256 | "5ASUHXjun": { 257 | "id": "5ASUHXjun", 258 | "content": "Movies", 259 | "children": [ 260 | "Tnu5dLqfn", 261 | "5FhLcDZ7t", 262 | "1NHqZGq4F", 263 | "DPBGYDiOq" 264 | ] 265 | }, 266 | "TcdtzwVP6": { 267 | "id": "TcdtzwVP6", 268 | "content": "2022-07-25 - added Movies to TV and Movies", 269 | "children": [ 270 | "5ASUHXjun" 271 | ] 272 | }, 273 | "LVSjVUr7s": { 274 | "id": "LVSjVUr7s", 275 | "content": "TV Series", 276 | "children": [ 277 | "wcrkG2K4E", 278 | "-UgaC2Rdo", 279 | "iXxuc64R6" 280 | ] 281 | }, 282 | "qr8360Ej9": { 283 | "id": "qr8360Ej9", 284 | "content": "2022-07-25 - added TV Series to TV and Movies", 285 | "children": [ 286 | "LVSjVUr7s" 287 | ] 288 | }, 289 | "Tnu5dLqfn": { 290 | "id": "Tnu5dLqfn", 291 | "content": "Django Unchained", 292 | "children": [] 293 | }, 294 | "QNTwhKeOt": { 295 | "id": "QNTwhKeOt", 296 | "content": "2022-07-25 - added Django Unchained to Movies", 297 | "children": [ 298 | "Tnu5dLqfn" 299 | ] 300 | }, 301 | "5FhLcDZ7t": { 302 | "id": "5FhLcDZ7t", 303 | "content": "Isle of Dogs", 304 | "children": [] 305 | }, 306 | "asA6Xek3m": { 307 | "id": "asA6Xek3m", 308 | "content": "2022-07-25 - added Isle of Dogs to Movies", 309 | "children": [ 310 | "5FhLcDZ7t" 311 | ] 312 | }, 313 | "1NHqZGq4F": { 314 | "id": "1NHqZGq4F", 315 | "content": "Game Night", 316 | "children": [] 317 | }, 318 | "d1NpzUXWT": { 319 | "id": "d1NpzUXWT", 320 | "content": "2022-07-25 - added Game Night to Movies", 321 | "children": [ 322 | "1NHqZGq4F" 323 | ] 324 | }, 325 | "DPBGYDiOq": { 326 | "id": "DPBGYDiOq", 327 | "content": "Forgetting Sarah Marshall", 328 | "children": [] 329 | }, 330 | "_NTfRgsEgi": { 331 | "id": "_NTfRgsEgi", 332 | "content": "2022-07-25 - added Forgetting Sarah Marshall to Movies", 333 | "children": [ 334 | "DPBGYDiOq" 335 | ] 336 | }, 337 | "hrQhq8qIQ": { 338 | "id": "hrQhq8qIQ", 339 | "content": "watch Jojo Rabbit on Disney", 340 | "children": [] 341 | }, 342 | "4NaDjWGzA": { 343 | "id": "4NaDjWGzA", 344 | "content": "2022-07-25 - added watch Jojo Rabbit on Disney to Inbox", 345 | "children": [ 346 | "hrQhq8qIQ" 347 | ] 348 | }, 349 | "wcrkG2K4E": { 350 | "id": "wcrkG2K4E", 351 | "content": "Blue Planet", 352 | "children": [] 353 | }, 354 | "sHMsGu1Ix": { 355 | "id": "sHMsGu1Ix", 356 | "content": "2022-07-25 - added Blue Planet to TV Series", 357 | "children": [ 358 | "wcrkG2K4E" 359 | ] 360 | }, 361 | "-UgaC2Rdo": { 362 | "id": "-UgaC2Rdo", 363 | "content": "Stranger Things, Season 1", 364 | "children": [] 365 | }, 366 | "YlJlgCeGX": { 367 | "id": "YlJlgCeGX", 368 | "content": "2022-07-25 - added Stranger Things, Season 1 to TV Series", 369 | "children": [ 370 | "-UgaC2Rdo" 371 | ] 372 | }, 373 | "iXxuc64R6": { 374 | "id": "iXxuc64R6", 375 | "content": "Black Mirror, Seasons 1-3", 376 | "children": [] 377 | }, 378 | "RyTyhNq3F": { 379 | "id": "RyTyhNq3F", 380 | "content": "2022-07-25 - added Black Mirror, Seasons 1-3 to TV Series", 381 | "children": [ 382 | "iXxuc64R6" 383 | ] 384 | }, 385 | "YF3bFODc_": { 386 | "id": "YF3bFODc_", 387 | "content": "YouTube", 388 | "children": [ 389 | "ZLGbMiopc", 390 | "Kfpptj_yG6", 391 | "dRmeLuGaP", 392 | "XdHmz1UU_" 393 | ] 394 | }, 395 | "fLM3h5GBp": { 396 | "id": "fLM3h5GBp", 397 | "content": "2022-07-25 - added YouTube to TV and Movies", 398 | "children": [ 399 | "YF3bFODc_" 400 | ] 401 | }, 402 | "ZLGbMiopc": { 403 | "id": "ZLGbMiopc", 404 | "content": "Tame Impala Live from Wave House", 405 | "children": [ 406 | "c_EnG150H" 407 | ] 408 | }, 409 | "7ZKXkPqVK": { 410 | "id": "7ZKXkPqVK", 411 | "content": "2022-07-25 - added Tame Impala Live from Wave House to YouTube", 412 | "children": [ 413 | "ZLGbMiopc" 414 | ] 415 | }, 416 | "c_EnG150H": { 417 | "id": "c_EnG150H", 418 | "content": "https://www.youtube.com/watch?v=d33C8IE7WnQ", 419 | "children": [] 420 | }, 421 | "H5xY8el37": { 422 | "id": "H5xY8el37", 423 | "content": "2022-07-25 - added https://www.youtube.com/watch?v=d33C8IE7WnQ to Tame Impala Live from Wave House", 424 | "children": [ 425 | "c_EnG150H" 426 | ] 427 | }, 428 | "Kfpptj_yG6": { 429 | "id": "Kfpptj_yG6", 430 | "content": "RÜFÜS DU SOL - Live from Joshua Tree", 431 | "children": [ 432 | "AkRAqi0PK" 433 | ] 434 | }, 435 | "Q7XCz-lRt": { 436 | "id": "Q7XCz-lRt", 437 | "content": "2022-07-25 - added RÜFÜS DU SOL - Live from Joshua Tree to YouTube", 438 | "children": [ 439 | "Kfpptj_yG6" 440 | ] 441 | }, 442 | "AkRAqi0PK": { 443 | "id": "AkRAqi0PK", 444 | "content": "https://www.youtube.com/watch?v=Zy4KtD98S2c", 445 | "children": [] 446 | }, 447 | "LW3mHHa7A": { 448 | "id": "LW3mHHa7A", 449 | "content": "2022-07-25 - added https://www.youtube.com/watch?v=Zy4KtD98S2c to Rufus", 450 | "children": [ 451 | "AkRAqi0PK" 452 | ] 453 | }, 454 | "dRmeLuGaP": { 455 | "id": "dRmeLuGaP", 456 | "content": "Red Hot Chili Peppers Documentary", 457 | "children": [ 458 | "5ZndkPu_X" 459 | ] 460 | }, 461 | "hApuoe7qE": { 462 | "id": "hApuoe7qE", 463 | "content": "2022-07-25 - added Red Hot Chili Peppers Documentary to YouTube", 464 | "children": [ 465 | "dRmeLuGaP" 466 | ] 467 | }, 468 | "5ZndkPu_X": { 469 | "id": "5ZndkPu_X", 470 | "content": "https://www.youtube.com/watch?v=7c8PR2ctiZ0", 471 | "children": [] 472 | }, 473 | "QKGTeBTQH": { 474 | "id": "QKGTeBTQH", 475 | "content": "2022-07-25 - added https://www.youtube.com/watch?v=7c8PR2ctiZ0 to Red Hot Chili Peppers Documentary", 476 | "children": [ 477 | "5ZndkPu_X" 478 | ] 479 | }, 480 | "XdHmz1UU_": { 481 | "id": "XdHmz1UU_", 482 | "content": "Alan Watts Lecture", 483 | "children": [ 484 | "0zYT_KZno" 485 | ] 486 | }, 487 | "qawT5LuNz": { 488 | "id": "qawT5LuNz", 489 | "content": "2022-07-25 - added Alan Watts Lecture to YouTube", 490 | "children": [ 491 | "XdHmz1UU_" 492 | ] 493 | }, 494 | "0zYT_KZno": { 495 | "id": "0zYT_KZno", 496 | "content": "https://www.youtube.com/watch?v=dYSQ1NF1hvw", 497 | "children": [] 498 | }, 499 | "AHSVWPkJ1": { 500 | "id": "AHSVWPkJ1", 501 | "content": "2022-07-25 - added https://www.youtube.com/watch?v=dYSQ1NF1hvw to Alan Watts Lecture", 502 | "children": [ 503 | "0zYT_KZno" 504 | ] 505 | } 506 | } -------------------------------------------------------------------------------- /packages/viewer/src/Viewer/examples/youtube.json: -------------------------------------------------------------------------------- 1 | { 2 | "vLlFS3csq": { 3 | "id": "vLlFS3csq", 4 | "content": "YouTube", 5 | "children": [ 6 | "r2_QCE3iV", 7 | "oCNyqY2fW", 8 | "ike9y2a84", 9 | "rxvATLeIe" 10 | ] 11 | }, 12 | "r2_QCE3iV": { 13 | "id": "r2_QCE3iV", 14 | "content": "Recent", 15 | "children": [ 16 | "_Mf5KW0Yc", 17 | "oFAYCtTA0" 18 | ] 19 | }, 20 | "_Mf5KW0Yc": { 21 | "id": "_Mf5KW0Yc", 22 | "content": "Matt Corby - Miracle Love (Live At Manchester Cathedral)", 23 | "children": [ 24 | "5Bjpmj_6D" 25 | ] 26 | }, 27 | "rxvATLeIe": { 28 | "id": "rxvATLeIe", 29 | "content": "All", 30 | "children": [ 31 | "_Mf5KW0Yc", 32 | "oFAYCtTA0", 33 | "w8V8LNKPO", 34 | "NbYhHhFVz" 35 | ] 36 | }, 37 | "5Bjpmj_6D": { 38 | "id": "5Bjpmj_6D", 39 | "content": "https://youtu.be/wHBcO4bjBXs", 40 | "children": [] 41 | }, 42 | "ike9y2a84": { 43 | "id": "ike9y2a84", 44 | "content": "Music", 45 | "children": [ 46 | "_Mf5KW0Yc", 47 | "w8V8LNKPO" 48 | ] 49 | }, 50 | "oCNyqY2fW": { 51 | "id": "oCNyqY2fW", 52 | "content": "Cooking", 53 | "children": [ 54 | "oFAYCtTA0", 55 | "NbYhHhFVz" 56 | ] 57 | }, 58 | "NbYhHhFVz": { 59 | "id": "NbYhHhFVz", 60 | "content": "Binging with Babish: Huevos Rancheros from Breaking Bad", 61 | "children": [ 62 | "krSktDi7Y" 63 | ] 64 | }, 65 | "w8V8LNKPO": { 66 | "id": "w8V8LNKPO", 67 | "content": "Ed Sheeran - Take Me Back To London (Sir Spyro Remix) [feat. Stormzy, Jaykae & Aitch]", 68 | "children": [ 69 | "Du1zDI_lh" 70 | ] 71 | }, 72 | "Du1zDI_lh": { 73 | "id": "Du1zDI_lh", 74 | "content": "https://youtu.be/XJQy_R9CYR4", 75 | "children": [] 76 | }, 77 | "krSktDi7Y": { 78 | "id": "krSktDi7Y", 79 | "content": "https://youtu.be/pdNm4ug9PpE", 80 | "children": [] 81 | }, 82 | "oFAYCtTA0": { 83 | "id": "oFAYCtTA0", 84 | "content": "Spicy garlic fried chicken (Kkanpunggi: 깐풍기)", 85 | "children": [ 86 | "bOoXzLrLW" 87 | ] 88 | }, 89 | "bOoXzLrLW": { 90 | "id": "bOoXzLrLW", 91 | "content": "https://youtu.be/VjneaJ0hmgs", 92 | "children": [] 93 | } 94 | } -------------------------------------------------------------------------------- /packages/viewer/src/Viewer/index.tsx: -------------------------------------------------------------------------------- 1 | /** @jsx jsx */ 2 | import { jsx } from "theme-ui"; 3 | import { useEffect } from "react"; 4 | import { useDispatch, useSelector } from "react-redux"; 5 | import { HotKeys } from "react-hotkeys"; 6 | import { 7 | IoIosArrowRoundBack, 8 | IoIosArrowRoundForward, 9 | IoIosArrowRoundUp, 10 | IoIosArrowRoundDown, 11 | IoIosArrowUp, 12 | IoIosArrowDown, 13 | IoIosTrash, 14 | IoIosCloudUpload, 15 | } from "react-icons/io"; 16 | import { ItemNode } from "./ItemNode"; 17 | import { 18 | up, 19 | down, 20 | indentItem, 21 | undentItem, 22 | addItem, 23 | removeItem, 24 | moveUp, 25 | moveDown, 26 | editItem, 27 | setBaseUrl, 28 | ROOT_ID, 29 | State, 30 | getPathFromNodeId, 31 | } from "./duck"; 32 | import { ToolbarButton } from "./ToolbarButton"; 33 | import { getLastItemInArray, objectMap } from "./array-util"; 34 | import { FixedToolbar } from "./FixedToolbar"; 35 | import { ToolbarUploadButton, FileWithName } from "./ToolbarUploadButton"; 36 | 37 | export interface ViewerProps { 38 | readonly?: boolean; 39 | onUpload?: (fileWithName: FileWithName) => Promise; 40 | baseUrl?: string; 41 | } 42 | 43 | export const Viewer = ({ 44 | readonly = false, 45 | baseUrl = "", 46 | onUpload, 47 | }: ViewerProps) => { 48 | const dispatch = useDispatch(); 49 | const selectedNodeId = useSelector((state: State) => state.nodeId); 50 | const id = getLastItemInArray(getPathFromNodeId(selectedNodeId)); 51 | const selectedItem = useSelector((state: State) => state.item[id]); 52 | 53 | useEffect(() => { 54 | dispatch(setBaseUrl({ baseUrl })); 55 | }, [dispatch, baseUrl]); 56 | 57 | const actions = { 58 | up, 59 | down, 60 | indent: indentItem, 61 | undent: undentItem, 62 | moveUp, 63 | moveDown, 64 | enter: () => addItem(), 65 | }; 66 | 67 | const preparedHandlers = objectMap<(evt?: KeyboardEvent) => void>( 68 | actions, 69 | ({ value: handler }) => (evt?: KeyboardEvent) => { 70 | if (evt) { 71 | evt.preventDefault(); 72 | } 73 | dispatch(handler()); 74 | } 75 | ); 76 | 77 | const handleRemove = () => { 78 | dispatch(removeItem()); 79 | }; 80 | 81 | const handlers = { 82 | ...preparedHandlers, 83 | backspace: (evt?: KeyboardEvent) => { 84 | if (selectedItem.content === "") { 85 | if (evt) { 86 | evt.preventDefault(); 87 | } 88 | handleRemove(); 89 | } 90 | }, 91 | }; 92 | 93 | const handleUploadComplete = (uri: string) => { 94 | dispatch(editItem({ id, content: uri })); 95 | }; 96 | 97 | return ( 98 |
    99 | 112 | 113 |
    120 |
      127 | 128 |
    129 |
    130 | {selectedItem && ( 131 | 132 |
    141 | { 143 | preparedHandlers.undent(); 144 | }} 145 | title="undent (shift + tab)" 146 | > 147 | 148 | 149 | { 151 | preparedHandlers.indent(); 152 | }} 153 | title="indent (tab)" 154 | > 155 | 156 | 157 | { 159 | preparedHandlers.moveUp(); 160 | }} 161 | title="move up (alt + up)" 162 | > 163 | 164 | 165 | { 167 | preparedHandlers.moveDown(); 168 | }} 169 | title="move down (alt + down)" 170 | > 171 | 172 | 173 | { 175 | preparedHandlers.up(); 176 | }} 177 | title="previous item (up)" 178 | > 179 | 180 | 181 | { 183 | preparedHandlers.down(); 184 | }} 185 | title="next item (down)" 186 | > 187 | 188 | 189 | 190 | 191 | 192 | {onUpload && ( 193 | 198 | 199 | 200 | )} 201 |
    202 |
    203 | )} 204 |
    205 |
    206 |
    207 | ); 208 | }; 209 | -------------------------------------------------------------------------------- /packages/viewer/src/Viewer/isHref.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Checks if a string can be used as a href for an anchor. 3 | * 4 | * Internally, it just checks if there are two strings seprated by a dot. Bit naive but oh well. 5 | * 6 | * @param input input string to check 7 | */ 8 | export function isHref(input: string): boolean { 9 | if (!input) { 10 | return false; 11 | } 12 | return /[a-zA-Z]+\.[a-zA-Z]/.test(input) || input.startsWith("./"); 13 | } 14 | 15 | export function isImageSrc(input: string): boolean { 16 | return ( 17 | isHref(input) && 18 | (input.endsWith(".jpg") || 19 | input.endsWith(".jpeg") || 20 | input.endsWith(".png") || 21 | input.endsWith(".gif")) 22 | ); 23 | } 24 | 25 | export function possiblyPrependBaseUrl( 26 | input: string, 27 | baseUrl?: string 28 | ): string { 29 | if (baseUrl && input.startsWith("./")) { 30 | return baseUrl + input.substr(1); 31 | } 32 | return input; 33 | } 34 | -------------------------------------------------------------------------------- /packages/viewer/src/WebViewer/WebViewer.stories.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { WebViewer } from "WebViewer"; 3 | 4 | export default { 5 | title: "WebViewer", 6 | component: WebViewer, 7 | }; 8 | 9 | export const WebViewerBlank = () => { 10 | return ; 11 | }; 12 | 13 | export const WebViewerYoutube = () => { 14 | return ; 15 | }; 16 | -------------------------------------------------------------------------------- /packages/viewer/src/WebViewer/index.tsx: -------------------------------------------------------------------------------- 1 | /** @jsx jsx */ 2 | import { jsx } from "theme-ui"; 3 | import { useEffect } from "react"; 4 | import { Provider, useDispatch } from "react-redux"; 5 | import { configureStore } from "@reduxjs/toolkit"; 6 | import axios from "axios"; 7 | import { Viewer } from "../Viewer"; 8 | import { load, reducer } from "../Viewer/duck"; 9 | import { usePromise } from "@cadbox1/use-promise"; 10 | import { ThemeProvider, Container, Styled } from "theme-ui"; 11 | import theme from "./theme"; 12 | 13 | export interface WebViewerProps { 14 | url?: string; 15 | showBanner?: boolean; 16 | } 17 | 18 | const store = configureStore({ 19 | reducer, 20 | }); 21 | 22 | const WebViewerInside = ({ url, showBanner }: WebViewerProps) => { 23 | const dispatch = useDispatch(); 24 | const request = usePromise({ 25 | promiseFunction: async () => { 26 | if (!url) { 27 | return; 28 | } 29 | const response = await axios.get(url); 30 | dispatch(load({ data: response.data })); 31 | }, 32 | }); 33 | 34 | useEffect(() => { 35 | request.call(); 36 | }, [url]); 37 | 38 | // sneakily load the source sans pro font 39 | useEffect(() => { 40 | const link = document.createElement("link"); 41 | link.setAttribute( 42 | "href", 43 | "https://fonts.googleapis.com/css2?family=Source+Sans+Pro&display=swap" 44 | ); 45 | link.setAttribute("rel", "stylesheet"); 46 | document.body.appendChild(link); 47 | 48 | return () => { 49 | document.body.removeChild(link); 50 | }; 51 | }, []); 52 | 53 | return ( 54 |
    55 | {showBanner && ( 56 |
    57 | Made with{" "} 58 | 63 | Very Nested 64 | 65 |
    66 | )} 67 | {request.pending ? ( 68 | "Loading..." 69 | ) : request.rejected ? ( 70 | "There was an error loading this page. Please refresh to try again." 71 | ) : ( 72 | 73 | )} 74 |
    75 | ); 76 | }; 77 | 78 | export const WebViewer = ({ 79 | url = "./very-nested-data.json", 80 | showBanner = true, 81 | }: WebViewerProps) => { 82 | return ( 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | ); 91 | }; 92 | -------------------------------------------------------------------------------- /packages/viewer/src/WebViewer/theme.js: -------------------------------------------------------------------------------- 1 | export default { 2 | // useColorSchemeMediaQuery: true, 3 | fonts: { 4 | body: 5 | '"source sans pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial', 6 | heading: 7 | '"source sans pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial', 8 | }, 9 | colors: { 10 | text: "#000", 11 | background: "#fff", 12 | primary: "#007bff", 13 | muted: "hsl(0, 0%, 96%)", 14 | heading: "text", 15 | modes: { 16 | dark: { 17 | text: "#fff", 18 | background: "#000", 19 | primary: "#007bff", 20 | muted: "hsl(0, 0%, 10%)", 21 | }, 22 | }, 23 | }, 24 | space: [0, 4, 8, 12, 16, 24, 32, 64, 96, 128], 25 | sizes: { 26 | container: 850, 27 | }, 28 | fontSizes: [16, 17, 20, 24, 32, 36, 44], 29 | lineHeights: { 30 | body: 1.6, 31 | heading: 1.2, 32 | }, 33 | fontWeights: { 34 | body: 400, 35 | heading: 600, 36 | bold: 600, 37 | }, 38 | container: { 39 | p: 2, 40 | }, 41 | viewer: { 42 | item: { 43 | fontSize: 1, 44 | }, 45 | }, 46 | styles: { 47 | root: { 48 | fontFamily: "body", 49 | lineHeight: "body", 50 | fontWeight: "body", 51 | }, 52 | a: { 53 | textDecoration: "none", 54 | ":active, :hover": { 55 | textDecoration: "underline", 56 | }, 57 | }, 58 | p: { 59 | fontSize: 2, 60 | }, 61 | }, 62 | }; 63 | -------------------------------------------------------------------------------- /packages/viewer/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./Viewer/duck"; 2 | export * from "./Viewer"; 3 | export * from "./WebViewer"; 4 | -------------------------------------------------------------------------------- /packages/viewer/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /packages/viewer/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "baseUrl": "src", 5 | "noEmit": false, 6 | "outDir": "./dist/", 7 | "target": "es5" 8 | }, 9 | "include": ["src"] 10 | } 11 | -------------------------------------------------------------------------------- /packages/viewer/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | 3 | module.exports = { 4 | mode: "development", 5 | entry: "./src/index.ts", 6 | devtool: "source-map", 7 | module: { 8 | rules: [ 9 | { 10 | test: /\.(tsx|ts|js|jsx)?$/, 11 | use: "ts-loader", 12 | exclude: /node_modules/, 13 | }, 14 | ], 15 | }, 16 | resolve: { 17 | extensions: [".tsx", ".ts", ".js"], 18 | }, 19 | output: { 20 | path: path.resolve(__dirname, "dist"), 21 | filename: "index.umd.js", 22 | library: "VeryNestedViewer", 23 | libraryTarget: "umd", 24 | }, 25 | externals: { 26 | react: "React", 27 | "react-dom": "ReactDOM", 28 | }, 29 | }; 30 | -------------------------------------------------------------------------------- /packages/website/.eslintrc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cadbox1/very-nested/8b5d4ac64f35a78d551a61a8207265c21959cf1a/packages/website/.eslintrc -------------------------------------------------------------------------------- /packages/website/.gitignore: -------------------------------------------------------------------------------- 1 | public 2 | .cache -------------------------------------------------------------------------------- /packages/website/.nvmrc: -------------------------------------------------------------------------------- 1 | 12.16.1 2 | -------------------------------------------------------------------------------- /packages/website/README.md: -------------------------------------------------------------------------------- 1 | # Very Nested Website 2 | 3 | Made with gatsby and theme-ui. 4 | 5 | Only issue is that Gatsby transpiles local modules and fails with very-nested-viewer because eslint is not happy with the minified production build. The workaround is to increment the very-nested-viewer version while developing so yarn pulls the npm version of very-nested-viewer so Gatsby won't transpile it. 6 | -------------------------------------------------------------------------------- /packages/website/gatsby-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [ 3 | { 4 | resolve: `gatsby-theme-ui-blog`, 5 | options: { 6 | mdx: true, 7 | basePath: `/blog`, 8 | contentPath: "content/posts", 9 | assetPath: "content/assets", 10 | }, 11 | }, 12 | { 13 | resolve: "gatsby-plugin-emoji-favicon", 14 | options: { 15 | emoji: "📝", 16 | }, 17 | }, 18 | "gatsby-plugin-theme-ui", 19 | ], 20 | siteMetadata: { 21 | title: `Very Nested`, 22 | }, 23 | }; 24 | -------------------------------------------------------------------------------- /packages/website/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "cd ../.. && yarn && cd packages/website && yarn build" 3 | publish = "public" -------------------------------------------------------------------------------- /packages/website/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "very-nested-website", 3 | "private": true, 4 | "version": "1.0.39", 5 | "scripts": { 6 | "develop": "gatsby develop", 7 | "start": "gatsby develop", 8 | "build": "gatsby build", 9 | "clean": "gatsby clean" 10 | }, 11 | "dependencies": { 12 | "@theme-ui/color": "^0.3.1", 13 | "gatsby": "^2.13.73", 14 | "gatsby-plugin-emoji-favicon": "^1.4.1", 15 | "gatsby-plugin-theme-ui": "^0.3.0", 16 | "gatsby-theme-ui-blog": "^0.3.1", 17 | "query-string": "^6.12.1", 18 | "react": "^16.12.0", 19 | "react-dom": "^16.12.0", 20 | "theme-ui": "^0.3.1", 21 | "typeface-source-sans-pro": "^0.0.75", 22 | "very-nested-login": "^1.0.39", 23 | "very-nested-viewer": "^1.0.39" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/website/src/components/Header/index.tsx: -------------------------------------------------------------------------------- 1 | /** @jsx jsx */ 2 | import { jsx, useColorMode } from "theme-ui"; 3 | import { Link } from "gatsby"; 4 | // @ts-ignore 5 | import { generateAuthorizeUrl } from "very-nested-login"; 6 | 7 | const navItemMX = 2; 8 | 9 | const navItemStyles = { 10 | mt: 2, 11 | mx: navItemMX, 12 | fontWeight: 600, 13 | fontSize: 1, 14 | textDecoration: "none", 15 | color: "text", 16 | }; 17 | 18 | const navItemActiveStyles = { 19 | textDecoration: "underline", 20 | cursor: "default", 21 | }; 22 | 23 | export interface HeaderProps { 24 | title: string; 25 | } 26 | 27 | export const Header = ({ title }: HeaderProps) => { 28 | const [colorMode, setColorMode] = useColorMode(); 29 | const isDark = colorMode === `dark`; 30 | const toggleColorMode = () => { 31 | setColorMode(isDark ? `light` : `dark`); 32 | }; 33 | 34 | return ( 35 | 80 | ); 81 | }; 82 | -------------------------------------------------------------------------------- /packages/website/src/components/ViewerContainer/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect } from "react"; 2 | import { Provider, useDispatch } from "react-redux"; 3 | import { configureStore } from "@reduxjs/toolkit"; 4 | import { Viewer, load, reducer } from "very-nested-viewer"; 5 | 6 | const store = configureStore({ 7 | reducer, 8 | }); 9 | 10 | const InsideProvider = ({ 11 | data, 12 | readonly, 13 | }: { 14 | data: any; 15 | readonly: boolean; 16 | }) => { 17 | const dispatch = useDispatch(); 18 | 19 | useEffect(() => { 20 | dispatch(load({ data })); 21 | }, []); 22 | 23 | return ; 24 | }; 25 | 26 | export const ViewerContainer = ({ 27 | data, 28 | readonly = true, 29 | }: { 30 | data: any; 31 | readonly?: boolean; 32 | }) => { 33 | return ( 34 | 35 | 36 | 37 | ); 38 | }; 39 | -------------------------------------------------------------------------------- /packages/website/src/gatsby-plugin-theme-ui/index.js: -------------------------------------------------------------------------------- 1 | import baseTheme from "gatsby-theme-ui-blog/src/gatsby-plugin-theme-ui"; 2 | 3 | import "typeface-source-sans-pro"; 4 | 5 | export default { 6 | // useColorSchemeMediaQuery: true, 7 | fonts: { 8 | body: 9 | '"source sans pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial', 10 | heading: 11 | '"source sans pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial', 12 | monospace: `Consolas, Menlo, Monaco, source-code-pro, Courier New, monospace`, 13 | }, 14 | colors: { 15 | text: "#000", 16 | background: "#fff", 17 | primary: "#007bff", 18 | muted: "hsl(0, 0%, 96%)", 19 | heading: "text", 20 | modes: { 21 | dark: { 22 | text: "#fff", 23 | background: "#000", 24 | primary: "#007bff", 25 | muted: "hsl(0, 0%, 10%)", 26 | }, 27 | }, 28 | }, 29 | space: [0, 4, 8, 12, 16, 24, 32, 64, 96, 128], 30 | sizes: { 31 | container: 850, 32 | }, 33 | fontSizes: [16, 18, 20, 24, 32, 36, 44], 34 | lineHeights: { 35 | body: 1.7, 36 | heading: 1.2, 37 | }, 38 | fontWeights: { 39 | body: 400, 40 | heading: 600, 41 | bold: 600, 42 | }, 43 | viewer: { 44 | item: { 45 | fontSize: 2, 46 | }, 47 | }, 48 | styles: { 49 | ...baseTheme.styles, 50 | a: { 51 | ...baseTheme.styles.a, 52 | textDecoration: "none", 53 | ":active, :hover": { 54 | textDecoration: "underline", 55 | }, 56 | }, 57 | p: { 58 | ...baseTheme.styles.p, 59 | fontSize: 2, 60 | }, 61 | pre: { 62 | ...baseTheme.styles.pre, 63 | fontSize: 0, 64 | }, 65 | }, 66 | }; 67 | -------------------------------------------------------------------------------- /packages/website/src/pages/examples/data/youtube.json: -------------------------------------------------------------------------------- 1 | { 2 | "vLlFS3csq": { 3 | "id": "vLlFS3csq", 4 | "content": "YouTube", 5 | "children": [ 6 | "r2_QCE3iV", 7 | "oCNyqY2fW", 8 | "ike9y2a84", 9 | "rxvATLeIe" 10 | ] 11 | }, 12 | "r2_QCE3iV": { 13 | "id": "r2_QCE3iV", 14 | "content": "Recent", 15 | "children": [ 16 | "_Mf5KW0Yc", 17 | "oFAYCtTA0" 18 | ] 19 | }, 20 | "_Mf5KW0Yc": { 21 | "id": "_Mf5KW0Yc", 22 | "content": "Matt Corby - Miracle Love (Live At Manchester Cathedral)", 23 | "children": [ 24 | "5Bjpmj_6D" 25 | ] 26 | }, 27 | "rxvATLeIe": { 28 | "id": "rxvATLeIe", 29 | "content": "All", 30 | "children": [ 31 | "_Mf5KW0Yc", 32 | "oFAYCtTA0", 33 | "w8V8LNKPO", 34 | "NbYhHhFVz" 35 | ] 36 | }, 37 | "5Bjpmj_6D": { 38 | "id": "5Bjpmj_6D", 39 | "content": "https://youtu.be/wHBcO4bjBXs", 40 | "children": [] 41 | }, 42 | "ike9y2a84": { 43 | "id": "ike9y2a84", 44 | "content": "Music", 45 | "children": [ 46 | "_Mf5KW0Yc", 47 | "w8V8LNKPO" 48 | ] 49 | }, 50 | "oCNyqY2fW": { 51 | "id": "oCNyqY2fW", 52 | "content": "Cooking", 53 | "children": [ 54 | "oFAYCtTA0", 55 | "NbYhHhFVz" 56 | ] 57 | }, 58 | "NbYhHhFVz": { 59 | "id": "NbYhHhFVz", 60 | "content": "Binging with Babish: Huevos Rancheros from Breaking Bad", 61 | "children": [ 62 | "krSktDi7Y" 63 | ] 64 | }, 65 | "w8V8LNKPO": { 66 | "id": "w8V8LNKPO", 67 | "content": "Ed Sheeran - Take Me Back To London (Sir Spyro Remix) [feat. Stormzy, Jaykae & Aitch]", 68 | "children": [ 69 | "Du1zDI_lh" 70 | ] 71 | }, 72 | "Du1zDI_lh": { 73 | "id": "Du1zDI_lh", 74 | "content": "https://youtu.be/XJQy_R9CYR4", 75 | "children": [] 76 | }, 77 | "krSktDi7Y": { 78 | "id": "krSktDi7Y", 79 | "content": "https://youtu.be/pdNm4ug9PpE", 80 | "children": [] 81 | }, 82 | "oFAYCtTA0": { 83 | "id": "oFAYCtTA0", 84 | "content": "Spicy garlic fried chicken (Kkanpunggi: 깐풍기)", 85 | "children": [ 86 | "bOoXzLrLW" 87 | ] 88 | }, 89 | "bOoXzLrLW": { 90 | "id": "bOoXzLrLW", 91 | "content": "https://youtu.be/VjneaJ0hmgs", 92 | "children": [] 93 | } 94 | } -------------------------------------------------------------------------------- /packages/website/src/pages/examples/youtube.tsx: -------------------------------------------------------------------------------- 1 | /** @jsx jsx */ 2 | import { jsx, Styled } from "theme-ui"; 3 | import { graphql } from "gatsby"; 4 | // @ts-ignore 5 | import Layout from "gatsby-theme-ui-blog/src/layout"; 6 | // @ts-ignore 7 | import { Header } from "../../components/Header"; 8 | import { ViewerContainer } from "../../components/ViewerContainer"; 9 | import youtubeExample from "./data/youtube.json"; 10 | 11 | export default ({ data }: { data: any }) => { 12 | return ( 13 | 14 |
    15 |
    23 | Youtube Example 24 | Update a nested item 25 | 26 | Expand the 'Recent' and Matt Corby - Miracle Love items, 27 | click to the right of the YouTube link, hit enter, then add a 28 | description and see it show up in the 'Music' and 'All' lists. 29 | 30 | Nest an existing item in a new list 31 | 32 | Click on Babish's Huevos Rancheros inside 'Cooking', copy the 33 | id next to the edit box. Expand 'Recent', click on{" "} 34 | Spicy garlic fried chicken, hit enter then paste the id in 35 | the empty edit box. 36 | 37 | 38 | Check out the{" "} 39 | 44 | published page 45 | {" "} 46 | if you like this list. 47 | 48 | 49 |
    50 | 51 | ); 52 | }; 53 | 54 | export const query = graphql` 55 | query YoutubeExampleQuery { 56 | site { 57 | siteMetadata { 58 | title 59 | social { 60 | name 61 | url 62 | } 63 | } 64 | } 65 | } 66 | `; 67 | -------------------------------------------------------------------------------- /packages/website/src/pages/get-started.js: -------------------------------------------------------------------------------- 1 | /** @jsx jsx */ 2 | import { jsx, Styled } from "theme-ui"; 3 | import { graphql } from "gatsby"; 4 | import Layout from "gatsby-theme-ui-blog/src/layout"; 5 | // @ts-ignore 6 | import { generateAuthorizeUrl } from "very-nested-login"; 7 | import { Header } from "../components/Header"; 8 | 9 | export default ({ data }) => { 10 | return ( 11 | 12 |
    13 |
    21 | Get Started! 22 | 1. GitHub Account 23 | 24 | 25 | Sign in 26 | {" "} 27 | to GitHub or{" "} 28 | 29 | Signup 30 | {" "} 31 | if you don't already have an account. 32 | 33 | 2. Allow access 34 | 35 | Allow the Very Nested app to access your GitHub account so we can save 36 | your lists. 37 | 38 | 3. Setup a new repo 39 | 40 | Very Nested will setup a new GitHub repository for your list. 41 | 42 | 4. Create 43 | 44 | Create a list and click save. 45 | 46 | 5. Publish 47 | 48 | Share your list with a Github.com address. You also have the option to 49 | setup a custom domain. 50 | 51 |
    52 | 53 | ); 54 | }; 55 | 56 | export const query = graphql` 57 | query GetStartedQuery { 58 | site { 59 | siteMetadata { 60 | title 61 | social { 62 | name 63 | url 64 | } 65 | } 66 | } 67 | } 68 | `; 69 | -------------------------------------------------------------------------------- /packages/website/src/pages/index.js: -------------------------------------------------------------------------------- 1 | /** @jsx jsx */ 2 | import { jsx, Styled } from "theme-ui"; 3 | import { graphql, Link } from "gatsby"; 4 | import Layout from "gatsby-theme-ui-blog/src/layout"; 5 | import { Header } from "../components/Header"; 6 | import { ViewerContainer } from "../components/ViewerContainer"; 7 | import youtubeExample from "./examples/data/youtube.json"; 8 | 9 | export default ({ data }) => { 10 | return ( 11 | 12 |
    13 |
    21 | 22 | Create lists on the internet. 23 | 24 | 25 | Very Nested is a free and{" "} 26 | 31 | open source 32 | {" "} 33 | app to create unique lists on the internet using your GitHub account. 34 | 35 | 49 | Get Started 50 | 51 | 52 |
    53 | Example - YouTube videos I like 54 | 55 | Click on the plus icon to expand an item and see more details about 56 | it. Each item can be in multiple lists, which means adding a 57 | description to Matt Corby's Miracle Love in the 'Recent' 58 | list will add it in the 'Music' and 'All' lists. 59 | 60 | 61 | 62 | Edit this example 63 | {" "} 64 | to see more. You can also check out the{" "} 65 | 70 | published page 71 | {" "} 72 | if you like this list. 73 | 74 | 75 |
    76 | 77 |
    78 | Features 79 | Nesting 80 | 81 | Each item can be in multiple lists, so updating an item in one list 82 | will update it across all lists. Items can also be expanded and 83 | collapsed so you can organise your content in fun and creative ways. 84 | 85 | Photos and Files 86 | 87 | Add photos and files to your lists, even from your mobile. 88 | 89 | No Lock-In 90 | 91 | Very Nested is free,{" "} 92 | 97 | open source 98 | {" "} 99 | and we don't store any of your data. That means your content is safe 100 | and under your control, now and into the future. Even if I stopped 101 | working on Very Nested. You can even host your list on your own 102 | domain like I've done for{" "} 103 | 108 | cooking.cadell.dev 109 | 110 | . 111 | 112 | Published on GitHub 113 | 114 | We use{" "} 115 | 120 | GitHub 121 | {" "} 122 | to store your lists so you have more control over your data. We also 123 | use their{" "} 124 | 129 | hosting features 130 | {" "} 131 | to create websites for your lists and their{" "} 132 | 137 | version control 138 | {" "} 139 | features to keep a history of changes to your content. GitHub is{" "} 140 | 145 | free 146 | {" "} 147 | and the largest version control provider in the world with over 40 148 | million users. 149 | 150 |
    151 |
    152 | 153 | ); 154 | }; 155 | 156 | export const query = graphql` 157 | query HomeQuery { 158 | site { 159 | siteMetadata { 160 | title 161 | social { 162 | name 163 | url 164 | } 165 | } 166 | } 167 | } 168 | `; 169 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "esModuleInterop": true, 8 | "allowSyntheticDefaultImports": true, 9 | "strict": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "module": "esnext", 12 | "moduleResolution": "node", 13 | "resolveJsonModule": true, 14 | "isolatedModules": true, 15 | "noEmit": true, 16 | "jsx": "react" 17 | } 18 | } 19 | --------------------------------------------------------------------------------