diff --git a/Gruntfile.js b/Gruntfile.js index 87d26a3..7b8a556 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -4,12 +4,14 @@ module.exports = function(grunt) { grunt.initConfig({ browserify: { dev: { - files: { - 'build/main.js': ['src/js/**/*', '!src/js/libs/**'] - }, + files: [{ + dest: 'build/main.js', + src: ['src/js/**/*', '!src/js/libs/**'] + }], options: { alias: { - store: './src/js/store.js' + store: './src/js/store.js', + utils: './src/js/utils.js' }, transform: [['babelify', { optional: ['es7.asyncFunctions', 'asyncToGenerator', @@ -38,26 +40,32 @@ module.exports = function(grunt) { src: '**/*.js', expose: 'api', cwd: __dirname + '/src/js/api' + }, + { + src: '**/*.js', + expose: 'libs', + cwd: __dirname + '/src/js/libs' } ] ] ] } + } + }, + mochify: { + options: { + reporter: 'land' }, - prod: { - files: { - 'build/main.js': 'src/js/**/*' - }, - options: { - transform: ['babelify', 'uglifyify'] - } + tests: { + src: 'test/**/*.js', + options: '<%= browserify.dev.options %>' } }, less: { dev: { files: [{ - src: 'less/main.less', - dest: 'style.css' + src: 'src/less/main.less', + dest: 'build/style.css' }] }, prod: { @@ -65,8 +73,8 @@ module.exports = function(grunt) { plugins: require('less-plugin-clean-css')() }, files: [{ - src: 'less/main.less', - dest: 'style.css' + src: 'src/less/main.less', + dest: 'build/style.css' }] } }, @@ -81,6 +89,14 @@ module.exports = function(grunt) { }] } }, + mochaTest: { + tests: { + src: ['tests/**/*.js'], + options: { + reporter: 'landing' + } + } + }, watch: { styles: { files: ['src/less/**/*.less'], @@ -100,4 +116,5 @@ module.exports = function(grunt) { grunt.registerTask('default', ['browserify:dev', 'less:dev', 'copy']); grunt.registerTask('production', ['browserify:prod', 'less:prod', 'copy']); + grunt.registerTask('test', 'mochaTest'); }; diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4d73947 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ +GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + +Copyright (C) 2007 Free Software Foundation, Inc. +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + {one line to give the program's name and a brief idea of what it does.} + Copyright (C) {year} {name of author} + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Hawk Copyright (C) 2015 Mahdi Dibaiee + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/build/img/ Share.svg b/build/img/ Share.svg new file mode 100644 index 0000000..9fbce44 --- /dev/null +++ b/build/img/ Share.svg @@ -0,0 +1,32 @@ + + + + Share + Created with Sketch. + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build/img/Directory.svg b/build/img/Directory.svg new file mode 100644 index 0000000..5ebbbfb --- /dev/null +++ b/build/img/Directory.svg @@ -0,0 +1,14 @@ + + + + Directory + Created with Sketch. + + + + + + + + + \ No newline at end of file diff --git a/build/img/File.svg b/build/img/File.svg new file mode 100644 index 0000000..8c9a256 --- /dev/null +++ b/build/img/File.svg @@ -0,0 +1,14 @@ + + + + File + Created with Sketch. + + + + + + + + + \ No newline at end of file diff --git a/build/img/More.svg b/build/img/More.svg new file mode 100644 index 0000000..c666e77 --- /dev/null +++ b/build/img/More.svg @@ -0,0 +1,27 @@ + + + + More + Created with Sketch. + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build/img/Plus.svg b/build/img/Plus.svg new file mode 100644 index 0000000..ba9d03e --- /dev/null +++ b/build/img/Plus.svg @@ -0,0 +1,16 @@ + + + + Plus + Created with Sketch. + + + + + + + + + + + \ No newline at end of file diff --git a/build/img/Refresh.svg b/build/img/Refresh.svg new file mode 100644 index 0000000..1144b57 --- /dev/null +++ b/build/img/Refresh.svg @@ -0,0 +1,20 @@ + + + + Refresh + Created with Sketch. + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build/img/Share.svg b/build/img/Share.svg new file mode 100644 index 0000000..ea78d4e --- /dev/null +++ b/build/img/Share.svg @@ -0,0 +1,22 @@ + + + + Share + Created with Sketch. + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build/img/View.svg b/build/img/View.svg new file mode 100644 index 0000000..9e48f96 --- /dev/null +++ b/build/img/View.svg @@ -0,0 +1,16 @@ + + + + View + Created with Sketch. + + + + + + + + + + + \ No newline at end of file diff --git a/build/img/trianglified.svg b/build/img/trianglified.svg new file mode 100644 index 0000000..0d755fd --- /dev/null +++ b/build/img/trianglified.svg @@ -0,0 +1 @@ + diff --git a/build/index.html b/build/index.html index f0d774e..cb32db8 100644 --- a/build/index.html +++ b/build/index.html @@ -4,8 +4,11 @@ Hawk + + +
diff --git a/build/main.js b/build/main.js index 4360500..fa953d2 100644 --- a/build/main.js +++ b/build/main.js @@ -20904,6 +20904,7 @@ exports['default'] = changedir; var _actionsTypes = require('actions/types'); function changedir(dir) { + if (dir === 'sdcard') dir = ''; return { type: _actionsTypes.CHANGE_DIRECTORY, dir: dir @@ -20912,7 +20913,145 @@ function changedir(dir) { module.exports = exports['default']; -},{"actions/types":177}],176:[function(require,module,exports){ +},{"actions/types":182}],176:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); +exports.show = show; +exports.hide = hide; +exports.toggle = toggle; +exports.hideAll = hideAll; + +var _actionsTypes = require('actions/types'); + +function show(id) { + return { + type: _actionsTypes.DIALOG, + active: true, + id: id + }; +} + +function hide(id) { + return { + type: _actionsTypes.DIALOG, + active: false, + id: id + }; +} + +function toggle(id) { + return { + type: _actionsTypes.DIALOG, + active: 'toggle', + id: id + }; +} + +function hideAll() { + return { + type: _actionsTypes.DIALOG, + active: false + }; +} + +},{"actions/types":182}],177:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); +exports.create = create; +exports.share = share; +exports.rename = rename; +exports.active = active; +exports.deleteFile = deleteFile; + +var _actionsTypes = require('actions/types'); + +function create(path, name) { + return { + type: _actionsTypes.CREATE_FILE, + path: path, name: name + }; +} + +function share() { + return { + type: _actionsTypes.SHARE_FILE + }; +} + +function rename(file, name) { + return { + type: _actionsTypes.RENAME_FILE, + file: file, name: name + }; +} + +function active(file) { + return { + type: _actionsTypes.ACTIVE_FILE, + file: file + }; +} + +function deleteFile(file) { + return { + type: _actionsTypes.DELETE_FILE, + file: file + }; +} + +},{"actions/types":182}],178:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); +exports.refresh = refresh; +exports.toggle = toggle; +exports.details = details; +exports.list = list; + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +var _actionsTypes = require('actions/types'); + +var _store = require('store'); + +var _store2 = _interopRequireDefault(_store); + +function refresh() { + return { + type: _actionsTypes.REFRESH + }; +} + +function toggle(state) { + return { + type: _actionsTypes.FILES_VIEW, + view: 'toggle' + }; +} + +function details(state) { + return { + type: _actionsTypes.FILES_VIEW, + view: 'details' + }; +} + +function list(state) { + return { + type: _actionsTypes.FILES_VIEW, + view: 'list' + }; +} + +},{"actions/types":182,"store":"store"}],179:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { @@ -20931,53 +21070,528 @@ function listFiles(files) { module.exports = exports['default']; -},{"actions/types":177}],177:[function(require,module,exports){ -"use strict"; +},{"actions/types":182}],180:[function(require,module,exports){ +'use strict'; -Object.defineProperty(exports, "__esModule", { +Object.defineProperty(exports, '__esModule', { + value: true +}); +exports.show = show; +exports.hide = hide; +exports.toggle = toggle; +exports.hideAll = hideAll; + +var _actionsTypes = require('actions/types'); + +function show(id, x, y) { + return { + type: _actionsTypes.MENU, + active: true, + id: id, x: x, y: y + }; +} + +function hide(id) { + return { + type: _actionsTypes.MENU, + active: false, + id: id + }; +} + +function toggle(id, x, y) { + return { + type: _actionsTypes.MENU, + active: 'toggle', + id: id, x: x, y: y + }; +} + +function hideAll() { + return { + type: _actionsTypes.MENU, + active: false + }; +} + +},{"actions/types":182}],181:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); +exports.show = show; +exports.hide = hide; +exports.toggle = toggle; + +var _actionsTypes = require('actions/types'); + +function show() { + return { + type: _actionsTypes.NAVIGATION, + active: true + }; +} + +function hide() { + return { + type: _actionsTypes.NAVIGATION, + active: false + }; +} + +function toggle() { + return { + type: _actionsTypes.NAVIGATION, + active: _actionsTypes.TOGGLE + }; +} + +},{"actions/types":182}],182:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); var TYPES = { - CHANGE_DIRECTORY: Symbol(), - LIST_FILES: Symbol(), - SORT: Symbol(), - SEARCH: Symbol(), - REFRESH: Symbol() + CHANGE_DIRECTORY: Symbol('CHANGE_DIRECTORY'), + + LIST_FILES: Symbol('LIST_FILES'), + FILES_VIEW: Symbol('FILES_VIEW'), + + NAVIGATION: Symbol('NAVIGATION'), + TOGGLE: Symbol('TOGGLE'), + REFRESH: Symbol('REFRESH'), + SORT: Symbol('SORT'), + + NEW_FILE: Symbol('NEW_FILE'), + CREATE_FILE: Symbol('CREATE_FILE'), + SHARE_FILE: Symbol('SHARE_FILE'), + RENAME_FILE: Symbol('RENAME_FILE'), + ACTIVE_FILE: Symbol('ACTIVE_FILE'), + DELETE_FILE: Symbol('DELETE_FILE'), + + MENU: Symbol('MENU'), + + DIALOG: Symbol('DEBUG'), + + SEARCH: Symbol('SEARCH') }; -exports["default"] = TYPES; -module.exports = exports["default"]; +exports['default'] = TYPES; +module.exports = exports['default']; -},{}],178:[function(require,module,exports){ +},{}],183:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); +exports.sdcard = sdcard; + +var root = _asyncToGenerator(function* () { + if (ROOT_CACHE) return ROOT_CACHE; + + ROOT_CACHE = yield sdcard().getRoot(); + return ROOT_CACHE; +}); + +exports.root = root; + +var getFile = _asyncToGenerator(function* () { + var dir = arguments.length <= 0 || arguments[0] === undefined ? '/' : arguments[0]; + + var parent = yield root(); + + if (dir === '/' || !dir) return root(); + + return yield parent.get(dir); +}); + +exports.getFile = getFile; + +var children = _asyncToGenerator(function* (dir) { + var parent = yield getFile(dir); + return yield parent.getFilesAndDirectories(); +}); + +exports.children = children; + +var readFile = _asyncToGenerator(function* (path) { + var file = yield getFile(path); + + return new Promise(function (resolve, reject) { + var reader = new FileReader(); + + reader.onload = function () { + resolve(reader.result); + }; + reader.onerror = reject; + reader.onabort = reject; + reader.readAsArrayBuffer(file); + }); +}); + +exports.readFile = readFile; + +var createFile = _asyncToGenerator(function* () { + var parent = yield root(); + + return yield parent.createFile.apply(parent, arguments); +}); + +exports.createFile = createFile; + +var createDirectory = _asyncToGenerator(function* () { + var parent = yield root(); + + return yield parent.createDirectory.apply(parent, arguments); +}); + +exports.createDirectory = createDirectory; + +var rename = _asyncToGenerator(function* (file, newName) { + console.log(file); + var path = (file.path || '').slice(1); // remove starting slash + var oldPath = path + file.name; + var newPath = path + newName; + + var target = yield getFile(oldPath); + + if ((0, _utils.type)(target) === 'Directory') { + yield createDirectory(newPath); + var childs = yield target.getFilesAndDirectories(); + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = childs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var child = _step.value; + + yield rename(child, newPath + '/' + child.name); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator['return']) { + _iterator['return'](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + target['delete'](); + return; + } else { + var content = yield readFile(fullpath); + + var blob = new Blob([content], { type: target.type }); + + sdcard()['delete'](fullpath); + + sdcard().addNamed(blob, path + newName); + } +}); + +exports.rename = rename; + +function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { var callNext = step.bind(null, 'next'); var callThrow = step.bind(null, 'throw'); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(callNext, callThrow); } } callNext(); }); }; } + +var _utils = require('utils'); + +var SD_CACHE = undefined; + +function sdcard() { + if (SD_CACHE) return SD_CACHE; + + SD_CACHE = navigator.getDeviceStorage('sdcard'); + return SD_CACHE; +} + +var ROOT_CACHE = undefined; + +},{"utils":"utils"}],184:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); -var directory = _asyncToGenerator(function* () { - var dir = arguments.length <= 0 || arguments[0] === undefined ? '/' : arguments[0]; +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - var storage = navigator.getDeviceStorage('sdcard'); - var root = yield storage.getRoot(); +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; - if (dir === '/' || !dir) return root; +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - return yield root.get(dir); +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var _react = require('react'); + +var _react2 = _interopRequireDefault(_react); + +var _reactRedux = require('react-redux'); + +var _actionsChangedir = require('actions/changedir'); + +var _actionsChangedir2 = _interopRequireDefault(_actionsChangedir); + +var _store = require('store'); + +var Breadcrumb = (function (_Component) { + _inherits(Breadcrumb, _Component); + + function Breadcrumb() { + _classCallCheck(this, _Breadcrumb); + + _get(Object.getPrototypeOf(_Breadcrumb.prototype), 'constructor', this).apply(this, arguments); + } + + _createClass(Breadcrumb, [{ + key: 'render', + value: function render() { + var directories = this.props.cwd.split('/'); + directories.unshift('sdcard'); + + var els = directories.map(function (dir, index, arr) { + var path = arr.slice(1, index + 1).join('/'); + var slash = index > 0 ? '/' : ''; + + return _react2['default'].createElement( + 'span', + { key: index, onClick: (0, _store.bind)((0, _actionsChangedir2['default'])(path)) }, + _react2['default'].createElement( + 'i', + null, + slash + ), + dir + ); + }); + + var lastDirectories = this.props.lwd.split('/'); + if (lastDirectories.length > directories.length - 1) { + lastDirectories.splice(0, directories.length - 1); + var _history = lastDirectories.map(function (dir, index, arr) { + var current = directories.slice(1).concat(arr.slice(0, index + 1)); + var path = current.join('/'); + + return _react2['default'].createElement( + 'span', + { key: directories.length + index, className: 'history', onClick: (0, _store.bind)((0, _actionsChangedir2['default'])(path)) }, + _react2['default'].createElement( + 'i', + null, + '/' + ), + dir + ); + }); + + els = els.concat(_history); + } + + return _react2['default'].createElement( + 'div', + { className: 'breadcrumb' }, + els + ); + } + }]); + + var _Breadcrumb = Breadcrumb; + Breadcrumb = (0, _reactRedux.connect)(props)(Breadcrumb) || Breadcrumb; + return Breadcrumb; +})(_react.Component); + +exports['default'] = Breadcrumb; + +function props(state) { + return { + lwd: state.get('lwd'), // last working directory + cwd: state.get('cwd') + }; +} +module.exports = exports['default']; + +},{"actions/changedir":175,"react":165,"react-redux":5,"store":"store"}],185:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true }); -exports.directory = directory; +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); -var children = _asyncToGenerator(function* (dir) { - var parent = yield directory(dir); - return yield parent.getFilesAndDirectories(); +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var _react = require('react'); + +var _react2 = _interopRequireDefault(_react); + +var Dialog = (function (_Component) { + _inherits(Dialog, _Component); + + function Dialog() { + _classCallCheck(this, Dialog); + + _get(Object.getPrototypeOf(Dialog.prototype), 'constructor', this).apply(this, arguments); + } + + _createClass(Dialog, [{ + key: 'render', + value: function render() { + var _this = this; + + var conditionalInput = this.props.input ? _react2['default'].createElement('input', { ref: 'input' }) : ''; + var buttons = this.props.buttons.map(function (button, i) { + return _react2['default'].createElement( + 'button', + { className: button.className + ' btn', key: i, + onClick: button.action.bind(_this) }, + button.text + ); + }); + + var className = this.props.active ? 'dialog active' : 'dialog'; + + return _react2['default'].createElement( + 'div', + { className: className }, + _react2['default'].createElement( + 'p', + { className: 'regular-medium' }, + this.props.title + ), + _react2['default'].createElement( + 'p', + { className: 'light-medium' }, + this.props.description + ), + conditionalInput, + _react2['default'].createElement( + 'div', + { className: 'foot' }, + buttons + ) + ); + } + }]); + + return Dialog; +})(_react.Component); + +exports['default'] = Dialog; +module.exports = exports['default']; + +},{"react":165}],186:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true }); -exports.children = children; +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); -function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { var callNext = step.bind(null, 'next'); var callThrow = step.bind(null, 'throw'); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(callNext, callThrow); } } callNext(); }); }; } +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; -},{}],179:[function(require,module,exports){ +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var _react = require('react'); + +var _react2 = _interopRequireDefault(_react); + +var _actionsChangedir = require('actions/changedir'); + +var _actionsChangedir2 = _interopRequireDefault(_actionsChangedir); + +var _actionsMenu = require('actions/menu'); + +var _actionsFile = require('actions/file'); + +var _menu = require('./menu'); + +var _store = require('store'); + +var _store2 = _interopRequireDefault(_store); + +var MENU_TOP_SPACE = 20; + +var Directory = (function (_Component) { + _inherits(Directory, _Component); + + function Directory() { + _classCallCheck(this, Directory); + + _get(Object.getPrototypeOf(Directory.prototype), 'constructor', this).apply(this, arguments); + } + + _createClass(Directory, [{ + key: 'render', + value: function render() { + return _react2['default'].createElement( + 'div', + { className: 'directory', ref: 'container', + onClick: this.peek.bind(this), + onContextMenu: this.contextMenu.bind(this) }, + _react2['default'].createElement('i', null), + _react2['default'].createElement( + 'p', + null, + this.props.name + ) + ); + } + }, { + key: 'peek', + value: function peek() { + var file = _store2['default'].getState().get('files')[this.props.index]; + + _store2['default'].dispatch((0, _actionsChangedir2['default'])(file.path.slice(1) + file.name)); + } + }, { + key: 'contextMenu', + value: function contextMenu(e) { + e.preventDefault(); + + var rect = _react2['default'].findDOMNode(this.refs.container).getBoundingClientRect(); + var x = rect.x; + var y = rect.y; + var width = rect.width; + var height = rect.height; + + var left = x + width / 2 - _menu.MENU_WIDTH / 2, + top = y + height / 2 + MENU_TOP_SPACE; + _store2['default'].dispatch((0, _actionsMenu.show)('directoryMenu', left, top)); + _store2['default'].dispatch((0, _actionsFile.active)(this.props.index)); + } + }]); + + return Directory; +})(_react.Component); + +exports['default'] = Directory; +module.exports = exports['default']; + +},{"./menu":190,"actions/changedir":175,"actions/file":177,"actions/menu":180,"react":165,"store":"store"}],187:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { @@ -21013,6 +21627,10 @@ var _file = require('./file'); var _file2 = _interopRequireDefault(_file); +var _directory = require('./directory'); + +var _directory2 = _interopRequireDefault(_directory); + var FileList = (function (_Component) { _inherits(FileList, _Component); @@ -21025,23 +21643,19 @@ var FileList = (function (_Component) { _createClass(FileList, [{ key: 'render', value: function render() { - var _props = this.props; - var cwd = _props.cwd; - var files = _props.files; + var files = this.props.files; var els = files.map(function (file, index) { - return _react2['default'].createElement(_file2['default'], { key: index, index: index, name: file.name }); + if (fileType(file) === 'File') { + return _react2['default'].createElement(_file2['default'], { key: index, index: index, name: file.name }); + } else { + return _react2['default'].createElement(_directory2['default'], { key: index, index: index, name: file.name }); + } }); return _react2['default'].createElement( 'div', - null, - _react2['default'].createElement( - 'strong', - null, - 'cwd: ', - cwd - ), + { className: 'file-list' }, els ); } @@ -21056,14 +21670,16 @@ exports['default'] = FileList; function props(state) { return { - cwd: state.get('cwd'), files: state.get('files') }; } +function fileType(file) { + return Object.prototype.toString.call(file).slice(8, -1); +} module.exports = exports['default']; -},{"./file":180,"react":165,"react-redux":5}],180:[function(require,module,exports){ +},{"./directory":186,"./file":188,"react":165,"react-redux":5}],188:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { @@ -21084,13 +21700,17 @@ var _react = require('react'); var _react2 = _interopRequireDefault(_react); +var _actionsMenu = require('actions/menu'); + +var _actionsFile = require('actions/file'); + +var _menu = require('./menu'); + var _store = require('store'); var _store2 = _interopRequireDefault(_store); -var _actionsChangedir = require('actions/changedir'); - -var _actionsChangedir2 = _interopRequireDefault(_actionsChangedir); +var MENU_TOP_SPACE = 20; var File = (function (_Component) { _inherits(File, _Component); @@ -21098,7 +21718,7 @@ var File = (function (_Component) { function File() { _classCallCheck(this, File); - _get(Object.getPrototypeOf(File.prototype), 'constructor', this).apply(this, arguments); + _get(Object.getPrototypeOf(File.prototype), 'constructor', this).call(this); } _createClass(File, [{ @@ -21106,23 +21726,31 @@ var File = (function (_Component) { value: function render() { return _react2['default'].createElement( 'div', - { onClick: this.peekInside.bind(this) }, + { className: 'file', ref: 'container', + onContextMenu: this.contextMenu.bind(this) }, + _react2['default'].createElement('i', null), _react2['default'].createElement( 'p', null, - this.props.index, - '. ', this.props.name ) ); } }, { - key: 'peekInside', - value: function peekInside() { - var file = _store2['default'].getState().get('files')[this.props.index]; + key: 'contextMenu', + value: function contextMenu(e) { + e.preventDefault(); - console.log(file); - _store2['default'].dispatch((0, _actionsChangedir2['default'])(file.path.slice(1) + file.name)); + var rect = _react2['default'].findDOMNode(this.refs.container).getBoundingClientRect(); + var x = rect.x; + var y = rect.y; + var width = rect.width; + var height = rect.height; + + var left = x + width / 2 - _menu.MENU_WIDTH / 2, + top = y + height / 2 + MENU_TOP_SPACE; + _store2['default'].dispatch((0, _actionsMenu.show)('fileMenu', left, top)); + _store2['default'].dispatch((0, _actionsFile.active)(this.props.index)); } }]); @@ -21132,7 +21760,270 @@ var File = (function (_Component) { exports['default'] = File; module.exports = exports['default']; -},{"actions/changedir":175,"react":165,"store":"store"}],181:[function(require,module,exports){ +},{"./menu":190,"actions/file":177,"actions/menu":180,"react":165,"store":"store"}],189:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var _react = require('react'); + +var _react2 = _interopRequireDefault(_react); + +var _actionsNavigation = require('actions/navigation'); + +var _store = require('store'); + +var _store2 = _interopRequireDefault(_store); + +var Header = (function (_Component) { + _inherits(Header, _Component); + + function Header() { + _classCallCheck(this, Header); + + _get(Object.getPrototypeOf(Header.prototype), 'constructor', this).apply(this, arguments); + } + + _createClass(Header, [{ + key: 'render', + value: function render() { + return _react2['default'].createElement( + 'header', + null, + _react2['default'].createElement('button', { className: 'drawer', onClick: this.toggleNavigation.bind(this) }), + _react2['default'].createElement( + 'h1', + { className: 'regular-medium' }, + 'Hawk' + ) + ); + } + }, { + key: 'toggleNavigation', + value: function toggleNavigation() { + _store2['default'].dispatch((0, _actionsNavigation.toggle)()); + } + }]); + + return Header; +})(_react.Component); + +exports['default'] = Header; +module.exports = exports['default']; + +},{"actions/navigation":181,"react":165,"store":"store"}],190:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var _react = require('react'); + +var _react2 = _interopRequireDefault(_react); + +var MENU_WIDTH = 245; + +exports.MENU_WIDTH = MENU_WIDTH; + +var Menu = (function (_Component) { + _inherits(Menu, _Component); + + function Menu() { + _classCallCheck(this, Menu); + + _get(Object.getPrototypeOf(Menu.prototype), 'constructor', this).apply(this, arguments); + } + + _createClass(Menu, [{ + key: 'render', + value: function render() { + var _this = this; + + var _props = this.props; + var items = _props.items; + var active = _props.active; + var style = _props.style; + + items = items || []; + + var els = items.map(function (item, index) { + return _react2['default'].createElement( + 'li', + { key: index, onClick: item.action.bind(_this) }, + item.name + ); + }); + var className = 'menu ' + (active ? 'active' : ''); + + return _react2['default'].createElement( + 'div', + { className: className, style: style }, + _react2['default'].createElement( + 'ul', + null, + els + ) + ); + } + }]); + + return Menu; +})(_react.Component); + +exports['default'] = Menu; + +},{"react":165}],191:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var _react = require('react'); + +var _react2 = _interopRequireDefault(_react); + +var _reactRedux = require('react-redux'); + +var _actionsNavigation = require('actions/navigation'); + +var Navigation = (function (_Component) { + _inherits(Navigation, _Component); + + function Navigation() { + _classCallCheck(this, _Navigation); + + _get(Object.getPrototypeOf(_Navigation.prototype), 'constructor', this).apply(this, arguments); + } + + _createClass(Navigation, [{ + key: 'render', + value: function render() { + return _react2['default'].createElement( + 'nav', + { className: this.props.active ? 'active' : '' }, + _react2['default'].createElement('i', { onClick: this.hide.bind(this) }), + _react2['default'].createElement( + 'p', + null, + 'Filter' + ), + _react2['default'].createElement( + 'ul', + null, + _react2['default'].createElement( + 'li', + null, + 'Picture' + ), + _react2['default'].createElement( + 'li', + null, + 'Video' + ), + _react2['default'].createElement( + 'li', + null, + 'Audio' + ) + ), + _react2['default'].createElement( + 'p', + null, + 'Tools' + ), + _react2['default'].createElement( + 'ul', + null, + _react2['default'].createElement( + 'li', + null, + 'FTP Browser' + ) + ), + _react2['default'].createElement( + 'p', + null, + 'Preferences' + ), + _react2['default'].createElement( + 'ul', + null, + _react2['default'].createElement( + 'li', + null, + 'Show Hidden Files ', + _react2['default'].createElement('input', { type: 'checkbox' }) + ), + _react2['default'].createElement( + 'li', + null, + 'Show Directories First ', + _react2['default'].createElement('input', { type: 'checkbox' }) + ), + _react2['default'].createElement( + 'li', + null, + 'Advanced Preferences' + ) + ) + ); + } + }, { + key: 'hide', + value: function hide() { + this.props.dispatch((0, _actionsNavigation.hide)()); + } + }]); + + var _Navigation = Navigation; + Navigation = (0, _reactRedux.connect)(props)(Navigation) || Navigation; + return Navigation; +})(_react.Component); + +exports['default'] = Navigation; + +function props(store) { + return { + active: store.get('navigation') + }; +} +module.exports = exports['default']; + +},{"actions/navigation":181,"react":165,"react-redux":5}],192:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { @@ -21157,6 +22048,34 @@ var _componentsFileList = require('components/file-list'); var _componentsFileList2 = _interopRequireDefault(_componentsFileList); +var _componentsNavigation = require('components/navigation'); + +var _componentsNavigation2 = _interopRequireDefault(_componentsNavigation); + +var _componentsHeader = require('components/header'); + +var _componentsHeader2 = _interopRequireDefault(_componentsHeader); + +var _componentsBreadcrumb = require('components/breadcrumb'); + +var _componentsBreadcrumb2 = _interopRequireDefault(_componentsBreadcrumb); + +var _componentsToolbar = require('components/toolbar'); + +var _componentsToolbar2 = _interopRequireDefault(_componentsToolbar); + +var _componentsMenu = require('components/menu'); + +var _componentsMenu2 = _interopRequireDefault(_componentsMenu); + +var _componentsDialog = require('components/dialog'); + +var _componentsDialog2 = _interopRequireDefault(_componentsDialog); + +var _reactRedux = require('react-redux'); + +var _actionsMenu = require('actions/menu'); + var _actionsChangedir = require('actions/changedir'); var _actionsChangedir2 = _interopRequireDefault(_actionsChangedir); @@ -21168,6 +22087,17 @@ var _store2 = _interopRequireDefault(_store); window.store = _store2['default']; window.changedir = _actionsChangedir2['default']; +var FileMenu = (0, _reactRedux.connect)(function (state) { + return state.get('fileMenu'); +})(_componentsMenu2['default']); +var DirectoryMenu = (0, _reactRedux.connect)(function (state) { + return state.get('directoryMenu'); +})(_componentsMenu2['default']); + +var RenameDialog = (0, _reactRedux.connect)(function (state) { + return state.get('renameDialog'); +})(_componentsDialog2['default']); + var Root = (function (_Component) { _inherits(Root, _Component); @@ -21182,11 +22112,24 @@ var Root = (function (_Component) { value: function render() { return _react2['default'].createElement( 'div', - null, - 'Hawk!', - _react2['default'].createElement(_componentsFileList2['default'], null) + { onTouchStart: this.touchStart.bind(this) }, + _react2['default'].createElement(_componentsHeader2['default'], null), + _react2['default'].createElement(_componentsBreadcrumb2['default'], null), + _react2['default'].createElement(_componentsNavigation2['default'], null), + _react2['default'].createElement(_componentsFileList2['default'], null), + _react2['default'].createElement(_componentsToolbar2['default'], null), + _react2['default'].createElement(FileMenu, null), + _react2['default'].createElement(DirectoryMenu, null), + _react2['default'].createElement(RenameDialog, null) ); } + }, { + key: 'touchStart', + value: function touchStart(e) { + if (!e.target.closest('.menu')) { + _store2['default'].dispatch((0, _actionsMenu.hideAll)()); + } + } }]); return Root; @@ -21195,7 +22138,130 @@ var Root = (function (_Component) { exports['default'] = Root; module.exports = exports['default']; -},{"actions/changedir":175,"components/file-list":179,"react":165,"store":"store"}],182:[function(require,module,exports){ +},{"actions/changedir":175,"actions/menu":180,"components/breadcrumb":184,"components/dialog":185,"components/file-list":187,"components/header":189,"components/menu":190,"components/navigation":191,"components/toolbar":193,"react":165,"react-redux":5,"store":"store"}],193:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + +var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } + +function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var _react = require('react'); + +var _react2 = _interopRequireDefault(_react); + +var _actionsFile = require('actions/file'); + +var _actionsFilesView = require('actions/files-view'); + +var _store = require('store'); + +var Toolbar = (function (_Component) { + _inherits(Toolbar, _Component); + + function Toolbar() { + _classCallCheck(this, Toolbar); + + _get(Object.getPrototypeOf(Toolbar.prototype), 'constructor', this).apply(this, arguments); + } + + _createClass(Toolbar, [{ + key: 'render', + value: function render() { + return _react2['default'].createElement( + 'div', + { className: 'toolbar' }, + _react2['default'].createElement('button', { className: 'icon-plus', onClick: this.newFile }), + _react2['default'].createElement('button', { className: 'icon-view', onClick: (0, _store.bind)((0, _actionsFilesView.toggle)()) }), + _react2['default'].createElement('button', { className: 'icon-refresh', onClick: (0, _store.bind)((0, _actionsFilesView.refresh)()) }), + _react2['default'].createElement('button', { className: 'icon-share', onClick: (0, _store.bind)((0, _actionsFile.share)()) }), + _react2['default'].createElement('button', { className: 'icon-more', onClick: this.showMore }) + ); + } + }, { + key: 'showMore', + value: function showMore() {} + }, { + key: 'newFile', + value: function newFile() {} + }]); + + return Toolbar; +})(_react.Component); + +exports['default'] = Toolbar; +module.exports = exports['default']; + +},{"actions/file":177,"actions/files-view":178,"react":165,"store":"store"}],194:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +var _react = require('react'); + +var _react2 = _interopRequireDefault(_react); + +var _actionsDialog = require('actions/dialog'); + +var _actionsFile = require('actions/file'); + +var _store = require('store'); + +var _store2 = _interopRequireDefault(_store); + +exports['default'] = { + renameDialog: { + title: 'Rename', + description: 'Enter your desired new name', + input: true, + buttons: [{ + text: 'Cancel', + action: (0, _store.bind)((0, _actionsDialog.hideAll)()) + }, { + text: 'Rename', + action: function action() { + var input = _react2['default'].findDOMNode(this.refs.input); + + var activeFile = _store2['default'].getState().get('activeFile'); + this.props.dispatch((0, _actionsFile.rename)(activeFile, input.value)); + this.props.dispatch((0, _actionsDialog.hideAll)()); + }, + className: 'success' + }] + }, + deleteDialog: { + title: 'Delete', + description: 'Are you sure you want to remove @activeFile.name?', + buttons: [{ + text: 'No', + action: (0, _store.bind)((0, _actionsDialog.hideAll)()) + }, { + text: 'Yes', + action: function action() { + var activeFile = _store2['default'].getState().get('activeFile'); + this.props.dispatch((0, _actionsFile.deleteFile)(activeFile)); + this.props.dispatch((0, _actionsDialog.hideAll)()); + }, + className: 'success' + }] + } +}; +module.exports = exports['default']; + +},{"actions/dialog":176,"actions/file":177,"react":165,"store":"store"}],195:[function(require,module,exports){ 'use strict'; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } @@ -21223,7 +22289,67 @@ _react2['default'].render(_react2['default'].createElement( } ), wrapper); -},{"components/root":181,"react":165,"react-redux":5,"store":"store"}],183:[function(require,module,exports){ +},{"components/root":192,"react":165,"react-redux":5,"store":"store"}],196:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +var _actionsMenu = require('actions/menu'); + +var _actionsDialog = require('actions/dialog'); + +var _store = require('store'); + +var _store2 = _interopRequireDefault(_store); + +var entryMenu = { + items: [{ + name: 'Rename', + action: function action() { + _store2['default'].dispatch((0, _actionsMenu.hideAll)()); + _store2['default'].dispatch((0, _actionsDialog.show)('renameDialog')); + } + }, { + name: 'Delete', + action: function action() { + _store2['default'].dispatch((0, _actionsMenu.hideAll)()); + _store2['default'].dispatch((0, _actionsDialog.show)('deleteDialog')); + } + }] +}; + +exports['default'] = { + fileMenu: Object.assign({}, entryMenu), + directoryMenu: Object.assign({}, entryMenu) +}; +module.exports = exports['default']; + +},{"actions/dialog":176,"actions/menu":180,"store":"store"}],197:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var _actionsTypes = require('actions/types'); + +exports['default'] = function (state, action) { + if (state === undefined) state = -1; + + if (action.type === _actionsTypes.ACTIVE_FILE) { + return action.file; + } + + return state; +}; + +module.exports = exports['default']; + +},{"actions/types":182}],198:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { @@ -21240,22 +22366,50 @@ var _cwd = require('./cwd'); var _cwd2 = _interopRequireDefault(_cwd); +var _lwd = require('./lwd'); + +var _lwd2 = _interopRequireDefault(_lwd); + var _files = require('./files'); var _files2 = _interopRequireDefault(_files); +var _navigation = require('./navigation'); + +var _navigation2 = _interopRequireDefault(_navigation); + +var _activeFile = require('./active-file'); + +var _activeFile2 = _interopRequireDefault(_activeFile); + +var _menu = require('./menu'); + +var _menu2 = _interopRequireDefault(_menu); + +var _dialog = require('./dialog'); + +var _dialog2 = _interopRequireDefault(_dialog); + exports['default'] = function (state, action) { if (state === undefined) state = new _immutable2['default'].Map(); + console.log('action', action); return new _immutable2['default'].Map({ + lwd: (0, _lwd2['default'])(state, action), // last working directory cwd: (0, _cwd2['default'])(state.get('cwd'), action), - files: (0, _files2['default'])(state.get('files'), action) + files: (0, _files2['default'])(state.get('files'), action), + activeFile: (0, _activeFile2['default'])(state.get('activeFile'), action), + navigation: (0, _navigation2['default'])(state.get('navigation'), action), + fileMenu: (0, _menu2['default'])(state, action, 'fileMenu'), + directoryMenu: (0, _menu2['default'])(state, action, 'directoryMenu'), + renameDialog: (0, _dialog2['default'])(state, action, 'renameDialog'), + deleteDialog: (0, _dialog2['default'])(state, action, 'deleteDialog') }); }; module.exports = exports['default']; -},{"./cwd":184,"./files":185,"immutable":186}],184:[function(require,module,exports){ +},{"./active-file":197,"./cwd":199,"./dialog":200,"./files":201,"./lwd":202,"./menu":203,"./navigation":204,"immutable":205}],199:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { @@ -21277,22 +22431,109 @@ var _store = require('store'); var _store2 = _interopRequireDefault(_store); exports['default'] = function (state, action) { - if (state === undefined) state = '/'; + if (state === undefined) state = ''; - switch (action.type) { - case _actionsTypes.CHANGE_DIRECTORY: - (0, _apiFiles.children)(action.dir).then(function (files) { - _store2['default'].dispatch((0, _actionsListFiles2['default'])(files)); - }); - return action.dir; - default: - return state; + if (action.type === _actionsTypes.CHANGE_DIRECTORY) { + (0, _apiFiles.children)(action.dir).then(function (files) { + _store2['default'].dispatch((0, _actionsListFiles2['default'])(files)); + }); + return action.dir; + } + + if (action.type === _actionsTypes.REFRESH) { + (0, _apiFiles.children)(state).then(function (files) { + _store2['default'].dispatch((0, _actionsListFiles2['default'])(files)); + }); + return state; + } + + return state; +}; + +module.exports = exports['default']; + +},{"actions/list-files":179,"actions/types":182,"api/files":183,"store":"store"}],200:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +var _actionsTypes = require('actions/types'); + +var _immutable = require('immutable'); + +var _immutable2 = _interopRequireDefault(_immutable); + +exports['default'] = function (state, action, id) { + if (state === undefined) state = new _immutable2['default'].Map({}); + + if (action.type === _actionsTypes.DIALOG) { + // action applied to all dialogs + if (!action.id) { + return Object.assign({}, state.get(id), { active: action.active }); + } + + if (action.id !== id) return state.get(id); + + var target = state.get(action.id); + var active = action.active === 'toggle' ? !target.get('active') : action.active; + + var style = Object.assign({}, state.style, { left: action.x, top: action.y }); + + return Object.assign({}, target, { style: style, active: active }); + } else { + return state.get(id); } }; module.exports = exports['default']; -},{"actions/list-files":176,"actions/types":177,"api/files":178,"store":"store"}],185:[function(require,module,exports){ +},{"actions/types":182,"immutable":205}],201:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var _actionsTypes = require('actions/types'); + +var _actionsFilesView = require('actions/files-view'); + +var _apiFiles = require('api/files'); + +exports['default'] = function (state, action) { + if (state === undefined) state = []; + + if (action.type === _actionsTypes.LIST_FILES) { + return action.files; + } + + if (action.type === _actionsTypes.RENAME_FILE) { + var file = state[action.file]; + + (0, _apiFiles.rename)(file, action.name).then(_actionsFilesView.refresh); + + return state; + } + + if (action.type === _actionsTypes.DELETE_FILE) { + var file = state[action.file]; + + (0, _apiFiles.sdcard)()['delete']((file.path || '') + '/' + file.name); + var copy = state.slice(0); + copy.splice(action.file, 1); + return copy; + } + + return state; +}; + +module.exports = exports['default']; + +},{"actions/files-view":178,"actions/types":182,"api/files":183}],202:[function(require,module,exports){ 'use strict'; Object.defineProperty(exports, '__esModule', { @@ -21302,19 +22543,77 @@ Object.defineProperty(exports, '__esModule', { var _actionsTypes = require('actions/types'); exports['default'] = function (state, action) { - if (state === undefined) state = []; + if (state === undefined) state = ''; - switch (action.type) { - case _actionsTypes.LIST_FILES: - return action.files; - default: - return state; + if (action.type === _actionsTypes.CHANGE_DIRECTORY) { + return state.get('cwd'); + } + return state.get('lwd'); +}; + +module.exports = exports['default']; + +},{"actions/types":182}],203:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } + +var _actionsTypes = require('actions/types'); + +var _immutable = require('immutable'); + +var _immutable2 = _interopRequireDefault(_immutable); + +exports['default'] = function (state, action, id) { + if (state === undefined) state = new _immutable2['default'].Map({}); + + if (action.type === _actionsTypes.MENU) { + // action applied to all menus + if (!action.id) { + return Object.assign({}, state.get(id), { active: action.active }); + } + + if (action.id !== id) return state.get(id); + + var target = state.get(action.id); + var active = action.active === 'toggle' ? !target.get('active') : action.active; + + var style = Object.assign({}, state.style, { left: action.x, top: action.y }); + + return Object.assign({}, target, { style: style, active: active }); + } else { + return state.get(id); } }; module.exports = exports['default']; -},{"actions/types":177}],186:[function(require,module,exports){ +},{"actions/types":182,"immutable":205}],204:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var _actionsTypes = require('actions/types'); + +exports['default'] = function (state, action) { + if (state === undefined) state = false; + + if (action.type === _actionsTypes.NAVIGATION) { + return action.active === _actionsTypes.TOGGLE ? !state : action.active; + } + + return state; +}; + +module.exports = exports['default']; + +},{"actions/types":182}],205:[function(require,module,exports){ /** * Copyright (c) 2014-2015, Facebook, Inc. * All rights reserved. @@ -26248,6 +27547,7 @@ module.exports = exports['default']; Object.defineProperty(exports, '__esModule', { value: true }); +exports.bind = bind; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } @@ -26265,15 +27565,40 @@ var _immutable = require('immutable'); var _immutable2 = _interopRequireDefault(_immutable); -var DEFAULT = new _immutable2['default'].Map({ - dir: '/', +var _menus = require('./menus'); + +var _menus2 = _interopRequireDefault(_menus); + +var _dialogs = require('./dialogs'); + +var _dialogs2 = _interopRequireDefault(_dialogs); + +var DEFAULT = new _immutable2['default'].Map(Object.assign({ + dir: '', files: [] -}); +}, _dialogs2['default'], _menus2['default'])); var store = (0, _redux.createStore)(_reducersAll2['default'], DEFAULT); -store.dispatch((0, _actionsChangedir2['default'])(DEFAULT.dir)); +store.dispatch((0, _actionsChangedir2['default'])(DEFAULT.get('dir'))); + +function bind(action) { + return function () { + return store.dispatch(action); + }; +} exports['default'] = store; -module.exports = exports['default']; -},{"actions/changedir":175,"immutable":186,"reducers/all":183,"redux":167}]},{},[175,176,177,178,179,180,181,182,183,184,185,"store"]); +},{"./dialogs":194,"./menus":196,"actions/changedir":175,"immutable":205,"reducers/all":198,"redux":167}],"utils":[function(require,module,exports){ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.type = type; + +function type(obj) { + return Object.prototype.toString.call(obj).slice(8, -1); +} + +},{}]},{},[175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,"store","utils"]); diff --git a/build/manifest.webapp b/build/manifest.webapp index 6a6102c..bfa7f4f 100644 --- a/build/manifest.webapp +++ b/build/manifest.webapp @@ -15,10 +15,10 @@ }, "type": "privileged", "permissions": { + "device-storage:sdcard": {"access": "readwrite"}, "device-storage:videos": {"access": "readwrite"}, "device-storage:pictures": {"access": "readwrite"}, "device-storage:music": {"access": "readwrite"}, - "device-storage:sdcard": {"access": "readwrite"}, "device-storage:apps": {"access": "readwrite"}, "webapps-manage": {} }, diff --git a/build/style.css b/build/style.css new file mode 100644 index 0000000..8507af9 --- /dev/null +++ b/build/style.css @@ -0,0 +1,340 @@ +.icon { + display: block; +} +.icon-directory { + display: block; + background: url(/img/Directory.svg) no-repeat; + width: 36px; + height: 32px; +} +.icon-file { + display: block; + background: url(/img/File.svg) no-repeat; + width: 30px; + height: 36px; +} +.icon-plus { + display: block; + background: url(/img/Plus.svg) no-repeat; + width: 24px; + height: 24px; +} +.icon-view { + display: block; + background: url(/img/View.svg) no-repeat; + width: 24px; + height: 24px; +} +.icon-refresh { + display: block; + background: url(/img/Refresh.svg) no-repeat; + width: 26px; + height: 28px; +} +.icon-share { + display: block; + background: url(/img/Share.svg) no-repeat; + width: 25px; + height: 27px; +} +.icon-more { + display: block; + background: url(/img/More.svg) no-repeat; + width: 6px; + height: 24px; +} +.regular-medium { + font-weight: normal; +} +.regular-medium { + font-size: 1.8rem; +} +.light-medium, +.light-big, +.light-small { + font-weight: 200; +} +.light-medium { + font-size: 1.6rem; +} +.light-big { + font-size: 1.8rem; +} +.light-small { + font-size: 1.3rem; +} +.thin-small { + font-weight: 100; +} +.thin-small { + font-size: 1.4rem; +} +.shadow-bottom { + box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); +} +.shadow { + box-shadow: 0 0 4px rgba(0, 0, 0, 0.2); +} +button { + border: none; + background: none; +} +.btn { + padding: 6px 3rem; + border: 1px solid #f0f0f0; + border-radius: 4px; + font-weight: 200; + font-size: 1.6rem; + background: #f8f8f8; + color: #39393a; +} +.btn.success { + background: #b8e986; +} +input { + border: 1px solid #f0f0f0; + background: #f8f8f8; + border-radius: 4px; + height: 32px; + box-sizing: border-box; + padding: 5px 1rem; + font-weight: 200; + font-size: 1.6rem; +} +.file, +.directory { + display: flex; + flex-flow: row; + align-items: center; + padding: 1.4rem; + width: 100%; + font-weight: 200; + font-size: 1.8rem; + box-sizing: border-box; + border-bottom: 1px solid rgba(0, 0, 0, 0.1); +} +.file i, +.directory i { + margin-right: 1.4rem; +} +.directory i { + display: block; + background: url(/img/Directory.svg) no-repeat; + width: 36px; + height: 32px; +} +.file i { + display: block; + background: url(/img/File.svg) no-repeat; + width: 30px; + height: 36px; +} +header { + display: flex; + flex: 1; + flex-flow: row; + align-items: center; + width: 100%; + height: 5rem; + background: #39393a; + color: white; + box-shadow: 0 0 4px rgba(0, 0, 0, 0.2); +} +header h1 { + margin-left: -3rem; +} +header button { + background: none; + border: none; + width: 8rem; + height: 2rem; +} +header button::before { + content: ''; + display: block; + width: 2rem; + height: 4px; + margin-top: -9px; + border-radius: 4px; + background: #9b9b93; + box-shadow: 0 7px 0 #9b9b93, 0 14px 0 #9b9b93; +} +.menu { + width: 24.5rem; + position: fixed; + left: 0; + top: 0; + background: white; + border-radius: 4px; + pointer-events: none; + opacity: 0; + transition: opacity 0.5s ease; + box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); +} +.menu.active { + opacity: 1; + pointer-events: all; +} +.menu ul { + list-style: none; + padding: 0 15px; +} +.menu li { + margin: 0; + padding: 1.3rem 8px; + border-bottom: 1px solid rgba(0, 0, 0, 0.1); +} +.menu li:last-of-type { + border-bottom: none; +} +nav { + display: flex; + flex-flow: column; + position: fixed; + left: -70vw; + top: 0; + width: 70vw; + height: 100vh; + background: #39393a; + color: white; + box-shadow: 1px 0 5px rgba(0, 0, 0, 0.2); + z-index: 6; + transition: left 0.5s ease; +} +nav.active { + left: 0; +} +nav.active i { + pointer-events: all; + opacity: 0.99; +} +nav p { + margin-left: 1.6rem; + font-weight: normal; + font-size: 1.8rem; +} +nav ul { + list-style: none; + padding-left: 0; +} +nav li { + font-weight: 200; + font-size: 1.6rem; + padding: 1rem 0 1rem 3rem; + border-bottom: 1px solid rgba(255, 255, 255, 0.1); +} +nav li:first-of-type { + padding-top: 0; +} +nav li:last-of-type { + padding-bottom: 0; + border-bottom: none; +} +nav i { + display: block; + position: fixed; + left: 0; + top: 0; + pointer-events: none; + width: 100vw; + height: 100vh; + background: rgba(0, 0, 0, 0.55); + opacity: 0; + z-index: -1; + transition: opacity 0.5s ease; +} +.toolbar { + display: flex; + flex-flow: row; + align-items: center; + justify-content: space-around; + align-self: flex-end; + width: 100vw; + height: 5rem; + box-sizing: border-box; + background: #f8f8f8; +} +.breadcrumb { + display: flex; + flex: 1; + align-items: center; + width: 100vw; + height: 3.5rem; + padding: 8px; + box-sizing: border-box; + font-weight: 200; + font-size: 1.6rem; + background: #f8f8f8; + border-bottom: 1px solid rgba(0, 0, 0, 0.2); +} +.breadcrumb i { + margin: 0 2px; +} +.breadcrumb span.history { + color: #9b9b93; +} +.file-list { + height: calc(100vh - 13.5rem); + overflow-x: hidden; + overflow-y: auto; +} +.dialog { + display: flex; + flex-flow: column; + position: fixed; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + width: 335px; + height: auto; + padding: 1.5rem 1.7rem; + background: white; + box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); + z-index: 3; + transition: opacity 0.5s ease; + opacity: 0; + pointer-events: none; +} +.dialog.active { + opacity: 1; + pointer-events: all; +} +.dialog p:first-of-type { + margin: 0 0 2.5rem; +} +.dialog p { + margin: 0 0 2rem; +} +.dialog input { + margin-bottom: 2rem; +} +.dialog .foot { + display: flex; + justify-content: space-between; +} +.dialog .foot button { + flex: 1; + margin: 0 8px; +} +.dialog .foot button:first-of-type { + margin-left: 0; +} +.dialog .foot button:last-of-type { + margin-right: 0; +} +html, +body { + margin: 0; + font-family: Fira Sans; + font-weight: regular; + box-sizing: border-box; +} +html { + font-size: 10px; + min-height: 100vh; +} +body { + font-size: 1.6rem; + display: flex; + flex-flow: column; +} diff --git a/design/assets/Directory.svg b/design/assets/Directory.svg new file mode 100644 index 0000000..5ebbbfb --- /dev/null +++ b/design/assets/Directory.svg @@ -0,0 +1,14 @@ + + + + Directory + Created with Sketch. + + + + + + + + + \ No newline at end of file diff --git a/design/assets/File.svg b/design/assets/File.svg new file mode 100644 index 0000000..8c9a256 --- /dev/null +++ b/design/assets/File.svg @@ -0,0 +1,14 @@ + + + + File + Created with Sketch. + + + + + + + + + \ No newline at end of file diff --git a/design/assets/More.svg b/design/assets/More.svg new file mode 100644 index 0000000..c666e77 --- /dev/null +++ b/design/assets/More.svg @@ -0,0 +1,27 @@ + + + + More + Created with Sketch. + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/design/assets/Plus.svg b/design/assets/Plus.svg new file mode 100644 index 0000000..1b952c1 --- /dev/null +++ b/design/assets/Plus.svg @@ -0,0 +1,27 @@ + + + + Plus + Created with Sketch. + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/design/assets/Refresh.svg b/design/assets/Refresh.svg new file mode 100644 index 0000000..def8478 --- /dev/null +++ b/design/assets/Refresh.svg @@ -0,0 +1,31 @@ + + + + Refresh + Created with Sketch. + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/design/assets/Share.svg b/design/assets/Share.svg new file mode 100644 index 0000000..0d15ca7 --- /dev/null +++ b/design/assets/Share.svg @@ -0,0 +1,40 @@ + + + + Share + Created with Sketch. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/design/assets/View.svg b/design/assets/View.svg new file mode 100644 index 0000000..8763c4a --- /dev/null +++ b/design/assets/View.svg @@ -0,0 +1,27 @@ + + + + View + Created with Sketch. + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/design/assets/trianglified.svg b/design/assets/trianglified.svg new file mode 100644 index 0000000..0d755fd --- /dev/null +++ b/design/assets/trianglified.svg @@ -0,0 +1 @@ + diff --git a/design/userinterface.sketch b/design/userinterface.sketch index 394b651..634ff8d 100644 Binary files a/design/userinterface.sketch and b/design/userinterface.sketch differ diff --git a/package.json b/package.json index 14deaa8..5863980 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,10 @@ "description": "", "main": "index.js", "scripts": { - "test": "grunt test" + "phantom": "mochify --transform babelify", + "wd": "mochify --transform babelify --wd", + "cover": "mochify --transform babelify --cover", + "test": "npm run phantom && npm run wd && npm run cover" }, "repository": { "type": "git", diff --git a/src/img/ Share.svg b/src/img/ Share.svg new file mode 100644 index 0000000..9fbce44 --- /dev/null +++ b/src/img/ Share.svg @@ -0,0 +1,32 @@ + + + + Share + Created with Sketch. + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/img/Directory.svg b/src/img/Directory.svg new file mode 100644 index 0000000..5ebbbfb --- /dev/null +++ b/src/img/Directory.svg @@ -0,0 +1,14 @@ + + + + Directory + Created with Sketch. + + + + + + + + + \ No newline at end of file diff --git a/src/img/File.svg b/src/img/File.svg new file mode 100644 index 0000000..8c9a256 --- /dev/null +++ b/src/img/File.svg @@ -0,0 +1,14 @@ + + + + File + Created with Sketch. + + + + + + + + + \ No newline at end of file diff --git a/src/img/More.svg b/src/img/More.svg new file mode 100644 index 0000000..c666e77 --- /dev/null +++ b/src/img/More.svg @@ -0,0 +1,27 @@ + + + + More + Created with Sketch. + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/img/Plus.svg b/src/img/Plus.svg new file mode 100644 index 0000000..ba9d03e --- /dev/null +++ b/src/img/Plus.svg @@ -0,0 +1,16 @@ + + + + Plus + Created with Sketch. + + + + + + + + + + + \ No newline at end of file diff --git a/src/img/Refresh.svg b/src/img/Refresh.svg new file mode 100644 index 0000000..1144b57 --- /dev/null +++ b/src/img/Refresh.svg @@ -0,0 +1,20 @@ + + + + Refresh + Created with Sketch. + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/img/Share.svg b/src/img/Share.svg new file mode 100644 index 0000000..ea78d4e --- /dev/null +++ b/src/img/Share.svg @@ -0,0 +1,22 @@ + + + + Share + Created with Sketch. + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/img/View.svg b/src/img/View.svg new file mode 100644 index 0000000..9e48f96 --- /dev/null +++ b/src/img/View.svg @@ -0,0 +1,16 @@ + + + + View + Created with Sketch. + + + + + + + + + + + \ No newline at end of file diff --git a/src/index.html b/src/index.html index f0d774e..cb32db8 100644 --- a/src/index.html +++ b/src/index.html @@ -4,8 +4,11 @@ Hawk + + +
diff --git a/src/js/actions/changedir.js b/src/js/actions/changedir.js index d74f764..d4c8935 100644 --- a/src/js/actions/changedir.js +++ b/src/js/actions/changedir.js @@ -1,6 +1,7 @@ import { CHANGE_DIRECTORY } from 'actions/types'; export default function changedir(dir) { + if (dir === 'sdcard') dir = ''; return { type: CHANGE_DIRECTORY, dir diff --git a/src/js/actions/dialog.js b/src/js/actions/dialog.js new file mode 100644 index 0000000..38ed322 --- /dev/null +++ b/src/js/actions/dialog.js @@ -0,0 +1,32 @@ +import { DIALOG } from 'actions/types'; + +export function show(id) { + return { + type: DIALOG, + active: true, + id + } +} + +export function hide(id) { + return { + type: DIALOG, + active: false, + id + } +} + +export function toggle(id) { + return { + type: DIALOG, + active: 'toggle', + id + } +} + +export function hideAll() { + return { + type: DIALOG, + active: false + } +} diff --git a/src/js/actions/file.js b/src/js/actions/file.js new file mode 100644 index 0000000..6c995ea --- /dev/null +++ b/src/js/actions/file.js @@ -0,0 +1,35 @@ +import { CREATE_FILE, SHARE_FILE, RENAME_FILE, ACTIVE_FILE, DELETE_FILE } from 'actions/types'; + +export function create(path, name) { + return { + type: CREATE_FILE, + path, name + } +} + +export function share() { + return { + type: SHARE_FILE + } +} + +export function rename(file, name) { + return { + type: RENAME_FILE, + file, name + } +} + +export function active(file) { + return { + type: ACTIVE_FILE, + file + } +} + +export function deleteFile(file) { + return { + type: DELETE_FILE, + file + } +} diff --git a/src/js/actions/files-view.js b/src/js/actions/files-view.js new file mode 100644 index 0000000..32afacb --- /dev/null +++ b/src/js/actions/files-view.js @@ -0,0 +1,29 @@ +import { LIST_FILES, FILES_VIEW, REFRESH } from 'actions/types'; +import store from 'store'; + +export function refresh() { + return { + type: REFRESH + } +} + +export function toggle(state) { + return { + type: FILES_VIEW, + view: 'toggle' + } +} + +export function details(state) { + return { + type: FILES_VIEW, + view: 'details' + } +} + +export function list(state) { + return { + type: FILES_VIEW, + view: 'list' + } +} diff --git a/src/js/actions/menu.js b/src/js/actions/menu.js new file mode 100644 index 0000000..0add8d3 --- /dev/null +++ b/src/js/actions/menu.js @@ -0,0 +1,32 @@ +import { MENU } from 'actions/types'; + +export function show(id, x, y) { + return { + type: MENU, + active: true, + id, x, y + } +} + +export function hide(id) { + return { + type: MENU, + active: false, + id + } +} + +export function toggle(id, x, y) { + return { + type: MENU, + active: 'toggle', + id, x, y + } +} + +export function hideAll() { + return { + type: MENU, + active: false + } +} diff --git a/src/js/actions/navigation.js b/src/js/actions/navigation.js new file mode 100644 index 0000000..1d912b5 --- /dev/null +++ b/src/js/actions/navigation.js @@ -0,0 +1,22 @@ +import { NAVIGATION, TOGGLE } from 'actions/types'; + +export function show() { + return { + type: NAVIGATION, + active: true + } +} + +export function hide() { + return { + type: NAVIGATION, + active: false + } +} + +export function toggle() { + return { + type: NAVIGATION, + active: TOGGLE + } +} diff --git a/src/js/actions/types.js b/src/js/actions/types.js index 9174cd6..0a23493 100644 --- a/src/js/actions/types.js +++ b/src/js/actions/types.js @@ -1,9 +1,26 @@ const TYPES = { - CHANGE_DIRECTORY: Symbol(), - LIST_FILES: Symbol(), - SORT: Symbol(), - SEARCH: Symbol(), - REFRESH: Symbol() + CHANGE_DIRECTORY: Symbol('CHANGE_DIRECTORY'), + + LIST_FILES: Symbol('LIST_FILES'), + FILES_VIEW: Symbol('FILES_VIEW'), + + NAVIGATION: Symbol('NAVIGATION'), + TOGGLE: Symbol('TOGGLE'), + REFRESH: Symbol('REFRESH'), + SORT: Symbol('SORT'), + + NEW_FILE: Symbol('NEW_FILE'), + CREATE_FILE: Symbol('CREATE_FILE'), + SHARE_FILE: Symbol('SHARE_FILE'), + RENAME_FILE: Symbol('RENAME_FILE'), + ACTIVE_FILE: Symbol('ACTIVE_FILE'), + DELETE_FILE: Symbol('DELETE_FILE'), + + MENU: Symbol('MENU'), + + DIALOG: Symbol('DEBUG'), + + SEARCH: Symbol('SEARCH') }; export default TYPES; diff --git a/src/js/api/files.js b/src/js/api/files.js index baf2aff..b5fbf3c 100644 --- a/src/js/api/files.js +++ b/src/js/api/files.js @@ -1,13 +1,86 @@ -export async function directory(dir = '/') { - let storage = navigator.getDeviceStorage('sdcard'); - let root = await storage.getRoot(); +import { type } from 'utils'; - if (dir === '/' || !dir) return root; +let SD_CACHE; +export function sdcard() { + if (SD_CACHE) return SD_CACHE; - return await root.get(dir); + SD_CACHE = navigator.getDeviceStorage('sdcard'); + return SD_CACHE; +} + +let ROOT_CACHE; +export async function root() { + if (ROOT_CACHE) return ROOT_CACHE; + + ROOT_CACHE = await sdcard().getRoot(); + return ROOT_CACHE; +} + +export async function getFile(dir = '/') { + let parent = await root(); + + if (dir === '/' || !dir) return root(); + + return await parent.get(dir); } export async function children(dir) { - let parent = await directory(dir); + let parent = await getFile(dir); return await parent.getFilesAndDirectories(); } + +export async function readFile(path) { + let file = await getFile(path); + + return new Promise((resolve, reject) => { + let reader = new FileReader(); + + reader.onload = () => { + resolve(reader.result); + }; + reader.onerror = reject; + reader.onabort = reject; + reader.readAsArrayBuffer(file); + }); +} + +export async function createFile(...args) { + let parent = await root(); + + return await parent.createFile(...args); +} + +export async function createDirectory(...args) { + let parent = await root(); + + return await parent.createDirectory(...args); +} + +export async function rename(file, newName) { + console.log(file); + let path = (file.path || '').slice(1); // remove starting slash + let oldPath = (path + file.name); + let newPath = path + newName; + + let target = await getFile(oldPath); + + if (type(target) === 'Directory') { + await createDirectory(newPath); + let childs = await target.getFilesAndDirectories(); + + for (let child of childs) { + await rename(child, newPath + '/' + child.name); + } + + target.delete(); + return; + } else { + let content = await readFile(fullpath); + + let blob = new Blob([content], {type: target.type}); + + sdcard().delete(fullpath); + + sdcard().addNamed(blob, path + newName); + } +} diff --git a/src/js/components/breadcrumb.js b/src/js/components/breadcrumb.js new file mode 100644 index 0000000..4e7683e --- /dev/null +++ b/src/js/components/breadcrumb.js @@ -0,0 +1,53 @@ +import React, { Component } from 'react'; +import { connect } from 'react-redux'; +import changedir from 'actions/changedir'; +import { bind } from 'store'; + +@connect(props) +export default class Breadcrumb extends Component { + render() { + let directories = this.props.cwd.split('/'); + directories.unshift('sdcard'); + + let els = directories.map((dir, index, arr) => { + let path = arr.slice(1, index + 1).join('/'); + let slash = index > 0 ? '/' : ''; + + return ( + + {slash}{dir} + + ); + }); + + let lastDirectories = this.props.lwd.split('/'); + if (lastDirectories.length > directories.length - 1) { + lastDirectories.splice(0, directories.length - 1); + let history = lastDirectories.map((dir, index, arr) => { + let current = directories.slice(1).concat(arr.slice(0, index + 1)); + let path = current.join('/'); + + return ( + + /{dir} + + ) + }); + + els = els.concat(history); + } + + return ( +
+ {els} +
+ ); + } +} + +function props(state) { + return { + lwd: state.get('lwd'), // last working directory + cwd: state.get('cwd') + } +} diff --git a/src/js/components/dialog.js b/src/js/components/dialog.js new file mode 100644 index 0000000..6eb1b21 --- /dev/null +++ b/src/js/components/dialog.js @@ -0,0 +1,28 @@ +import React, { Component } from 'react'; + +export default class Dialog extends Component { + render() { + let conditionalInput = this.props.input ? : ''; + let buttons = this.props.buttons.map((button, i) => { + return ; + }); + + let className = this.props.active ? 'dialog active' : 'dialog'; + + return ( +
+

{this.props.title}

+

{this.props.description}

+ + {conditionalInput} + +
+ {buttons} +
+
+ ) + } +} diff --git a/src/js/components/directory.js b/src/js/components/directory.js new file mode 100644 index 0000000..2a4bd25 --- /dev/null +++ b/src/js/components/directory.js @@ -0,0 +1,39 @@ +import React, { Component } from 'react'; +import changedir from 'actions/changedir'; +import { show } from 'actions/menu'; +import { active } from 'actions/file'; +import { MENU_WIDTH } from './menu'; +import store from 'store'; + +const MENU_TOP_SPACE = 20; + +export default class Directory extends Component { + render() { + return ( +
+ +

{this.props.name}

+
+ ); + } + + peek() { + let file = store.getState().get('files')[this.props.index]; + + store.dispatch(changedir(file.path.slice(1) + file.name)); + } + + contextMenu(e) { + e.preventDefault(); + + let rect = React.findDOMNode(this.refs.container).getBoundingClientRect(); + let {x, y, width, height} = rect; + + let left = x + width / 2 - MENU_WIDTH / 2, + top = y + height / 2 + MENU_TOP_SPACE; + store.dispatch(show('directoryMenu', left, top)); + store.dispatch(active(this.props.index)); + } +} diff --git a/src/js/components/file-list.js b/src/js/components/file-list.js index 8d37044..8bbd64b 100644 --- a/src/js/components/file-list.js +++ b/src/js/components/file-list.js @@ -1,6 +1,7 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; import File from './file'; +import Directory from './directory'; @connect(props) export default class FileList extends Component { @@ -9,14 +10,18 @@ export default class FileList extends Component { } render() { - let { cwd, files } = this.props; + let { files } = this.props; let els = files.map((file, index) => { - return ; + if (fileType(file) === 'File') { + return ; + } else { + return + } }); return ( -
cwd: {cwd} +
{els}
); @@ -25,7 +30,6 @@ export default class FileList extends Component { function props(state) { return { - cwd: state.get('cwd'), files: state.get('files') } } @@ -36,3 +40,7 @@ async function getFiles(dir) { return await root.getFilesAndDirectories(); } + +function fileType(file) { + return Object.prototype.toString.call(file).slice(8, -1); +} diff --git a/src/js/components/file.js b/src/js/components/file.js index 6081c45..96449d6 100644 --- a/src/js/components/file.js +++ b/src/js/components/file.js @@ -1,20 +1,35 @@ import React, { Component } from 'react'; +import { show } from 'actions/menu'; +import { active } from 'actions/file'; +import { MENU_WIDTH } from './menu'; import store from 'store'; -import changedir from 'actions/changedir'; + +const MENU_TOP_SPACE = 20; export default class File extends Component { + constructor() { + super(); + } + render() { return ( -
-

{this.props.index}. {this.props.name}

+
+ +

{this.props.name}

); } - peekInside() { - let file = store.getState().get('files')[this.props.index]; + contextMenu(e) { + e.preventDefault(); - console.log(file); - store.dispatch(changedir(file.path.slice(1) + file.name)); + let rect = React.findDOMNode(this.refs.container).getBoundingClientRect(); + let {x, y, width, height} = rect; + + let left = x + width / 2 - MENU_WIDTH / 2, + top = y + height / 2 + MENU_TOP_SPACE; + store.dispatch(show('fileMenu', left, top)); + store.dispatch(active(this.props.index)); } } diff --git a/src/js/components/header.js b/src/js/components/header.js new file mode 100644 index 0000000..bdc5442 --- /dev/null +++ b/src/js/components/header.js @@ -0,0 +1,18 @@ +import React, { Component } from 'react'; +import { toggle } from 'actions/navigation'; +import store from 'store'; + +export default class Header extends Component { + render() { + return ( +
+ +

Hawk

+
+ ); + } + + toggleNavigation() { + store.dispatch(toggle()); + } +} diff --git a/src/js/components/menu.js b/src/js/components/menu.js new file mode 100644 index 0000000..f5a379b --- /dev/null +++ b/src/js/components/menu.js @@ -0,0 +1,21 @@ +import React, { Component } from 'react'; + +export const MENU_WIDTH = 245; + +export default class Menu extends Component { + render() { + let { items, active, style } = this.props; + items = items || []; + + let els = items.map((item, index) => { + return
  • {item.name}
  • + }); + let className = 'menu ' + (active ? 'active' : ''); + + return ( +
    +
      {els}
    +
    + ); + } +} diff --git a/src/js/components/navigation.js b/src/js/components/navigation.js new file mode 100644 index 0000000..15a8402 --- /dev/null +++ b/src/js/components/navigation.js @@ -0,0 +1,43 @@ +import React, { Component } from 'react'; +import { connect } from 'react-redux'; +import { hide } from 'actions/navigation'; + +@connect(props) +export default class Navigation extends Component { + render() { + return ( + + ); + } + + hide() { + this.props.dispatch(hide()); + } +} + +function props(store) { + return { + active: store.get('navigation') + } +} diff --git a/src/js/components/root.js b/src/js/components/root.js index d5e4c8c..b422a42 100644 --- a/src/js/components/root.js +++ b/src/js/components/root.js @@ -1,18 +1,46 @@ import React, { Component } from 'react' import FileList from 'components/file-list'; +import Navigation from 'components/navigation'; +import Header from 'components/header'; +import Breadcrumb from 'components/breadcrumb'; +import Toolbar from 'components/toolbar'; +import Menu from 'components/menu'; +import Dialog from 'components/dialog'; +import { connect } from 'react-redux'; +import { hideAll } from 'actions/menu'; + import changedir from 'actions/changedir'; import store from 'store'; window.store = store; window.changedir = changedir; +let FileMenu = connect(state => state.get('fileMenu'))(Menu); +let DirectoryMenu = connect(state => state.get('directoryMenu'))(Menu); + +let RenameDialog = connect(state => state.get('renameDialog'))(Dialog); + export default class Root extends Component { render() { return ( -
    - Hawk! +
    +
    + + + + + + + +
    ); } + + touchStart(e) { + if (!e.target.closest('.menu')) { + store.dispatch(hideAll()); + } + } } diff --git a/src/js/components/toolbar.js b/src/js/components/toolbar.js new file mode 100644 index 0000000..97116a9 --- /dev/null +++ b/src/js/components/toolbar.js @@ -0,0 +1,26 @@ +import React, { Component } from 'react'; +import { create, share } from 'actions/file'; +import { toggle as toggleView, refresh } from 'actions/files-view'; +import { bind } from 'store'; + +export default class Toolbar extends Component { + render() { + return ( +
    +
    + ); + } + + showMore() { + + } + + newFile() { + + } +} diff --git a/src/js/dialogs.js b/src/js/dialogs.js new file mode 100644 index 0000000..4e409f7 --- /dev/null +++ b/src/js/dialogs.js @@ -0,0 +1,48 @@ +import React from 'react'; +import { hide, hideAll } from 'actions/dialog'; +import { rename, deleteFile } from 'actions/file'; +import store, { bind } from 'store'; + +export default { + renameDialog: { + title: 'Rename', + description: 'Enter your desired new name', + input: true, + buttons: [ + { + text: 'Cancel', + action: bind(hideAll()) + }, + { + text: 'Rename', + action() { + let input = React.findDOMNode(this.refs.input); + + let activeFile = store.getState().get('activeFile'); + this.props.dispatch(rename(activeFile, input.value)) + this.props.dispatch(hideAll()); + }, + className: 'success' + } + ] + }, + deleteDialog: { + title: 'Delete', + description: 'Are you sure you want to remove @activeFile.name?', + buttons: [ + { + text: 'No', + action: bind(hideAll()) + }, + { + text: 'Yes', + action() { + let activeFile = store.getState().get('activeFile'); + this.props.dispatch(deleteFile(activeFile)); + this.props.dispatch(hideAll()); + }, + className: 'success' + } + ] + } +} diff --git a/src/js/menus.js b/src/js/menus.js new file mode 100644 index 0000000..eb534ff --- /dev/null +++ b/src/js/menus.js @@ -0,0 +1,27 @@ +import { hideAll } from 'actions/menu'; +import { show } from 'actions/dialog'; +import store from 'store'; + +const entryMenu = { + items: [ + { + name: 'Rename', + action() { + store.dispatch(hideAll()); + store.dispatch(show('renameDialog')); + } + }, + { + name: 'Delete', + action() { + store.dispatch(hideAll()); + store.dispatch(show('deleteDialog')) + } + } + ] +}; + +export default { + fileMenu: Object.assign({}, entryMenu), + directoryMenu: Object.assign({}, entryMenu) +} diff --git a/src/js/reducers/active-file.js b/src/js/reducers/active-file.js new file mode 100644 index 0000000..d3a4f4b --- /dev/null +++ b/src/js/reducers/active-file.js @@ -0,0 +1,9 @@ +import { ACTIVE_FILE } from 'actions/types'; + +export default function(state = -1, action) { + if (action.type === ACTIVE_FILE) { + return action.file; + } + + return state; +} diff --git a/src/js/reducers/all.js b/src/js/reducers/all.js index 9c4678b..eb424fa 100644 --- a/src/js/reducers/all.js +++ b/src/js/reducers/all.js @@ -1,10 +1,23 @@ import Immutable from 'immutable'; import cwd from './cwd'; +import lwd from './lwd'; import files from './files'; +import navigation from './navigation'; +import activeFile from './active-file'; +import menu from './menu'; +import dialog from './dialog'; export default function(state = new Immutable.Map(), action) { + console.log('action', action); return new Immutable.Map({ + lwd: lwd(state, action), // last working directory cwd: cwd(state.get('cwd'), action), - files: files(state.get('files'), action) + files: files(state.get('files'), action), + activeFile: activeFile(state.get('activeFile'), action), + navigation: navigation(state.get('navigation'), action), + fileMenu: menu(state, action, 'fileMenu'), + directoryMenu: menu(state, action, 'directoryMenu'), + renameDialog: dialog(state, action, 'renameDialog'), + deleteDialog: dialog(state, action, 'deleteDialog') }); } diff --git a/src/js/reducers/cwd.js b/src/js/reducers/cwd.js index 9e48939..62610d6 100644 --- a/src/js/reducers/cwd.js +++ b/src/js/reducers/cwd.js @@ -1,16 +1,22 @@ -import { CHANGE_DIRECTORY } from 'actions/types'; +import { CHANGE_DIRECTORY, REFRESH } from 'actions/types'; import listFiles from 'actions/list-files'; import { children } from 'api/files'; import store from 'store'; -export default function(state = '/', action) { - switch (action.type) { - case CHANGE_DIRECTORY: - children(action.dir).then(files => { - store.dispatch(listFiles(files)); - }); - return action.dir; - default: - return state; +export default function(state = '', action) { + if (action.type === CHANGE_DIRECTORY) { + children(action.dir).then(files => { + store.dispatch(listFiles(files)); + }); + return action.dir; } + + if (action.type === REFRESH) { + children(state).then(files => { + store.dispatch(listFiles(files)); + }); + return state; + } + + return state; } diff --git a/src/js/reducers/dialog.js b/src/js/reducers/dialog.js new file mode 100644 index 0000000..1527893 --- /dev/null +++ b/src/js/reducers/dialog.js @@ -0,0 +1,22 @@ +import { DIALOG } from 'actions/types'; +import Immutable from 'immutable'; + +export default function(state = new Immutable.Map({}), action, id) { + if (action.type === DIALOG) { + // action applied to all dialogs + if (!action.id) { + return Object.assign({}, state.get(id), {active: action.active}); + } + + if (action.id !== id) return state.get(id); + + let target = state.get(action.id); + let active = action.active === 'toggle' ? !target.get('active') : action.active; + + let style = Object.assign({}, state.style, {left: action.x, top: action.y}); + + return Object.assign({}, target, { style, active }); + } else { + return state.get(id); + } +} diff --git a/src/js/reducers/files.js b/src/js/reducers/files.js index 9e64a41..be1974b 100644 --- a/src/js/reducers/files.js +++ b/src/js/reducers/files.js @@ -1,10 +1,29 @@ -import { LIST_FILES } from 'actions/types'; +import { LIST_FILES, RENAME_FILE, DELETE_FILE } from 'actions/types'; +import { refresh } from 'actions/files-view'; +import { rename, sdcard } from 'api/files'; export default function(state = [], action) { - switch (action.type) { - case LIST_FILES: - return action.files; - default: - return state; + if (action.type === LIST_FILES) { + return action.files; } + + + if (action.type === RENAME_FILE) { + let file = state[action.file]; + + rename(file, action.name).then(refresh); + + return state; + } + + if (action.type === DELETE_FILE) { + let file = state[action.file]; + + sdcard().delete((file.path || '') + '/' + file.name); + let copy = state.slice(0); + copy.splice(action.file, 1); + return copy; + } + + return state; } diff --git a/src/js/reducers/lwd.js b/src/js/reducers/lwd.js new file mode 100644 index 0000000..051bf57 --- /dev/null +++ b/src/js/reducers/lwd.js @@ -0,0 +1,8 @@ +import { CHANGE_DIRECTORY } from 'actions/types'; + +export default function(state = '', action) { + if (action.type === CHANGE_DIRECTORY) { + return state.get('cwd'); + } + return state.get('lwd'); +} diff --git a/src/js/reducers/menu.js b/src/js/reducers/menu.js new file mode 100644 index 0000000..7d693c8 --- /dev/null +++ b/src/js/reducers/menu.js @@ -0,0 +1,22 @@ +import { MENU } from 'actions/types'; +import Immutable from 'immutable'; + +export default function(state = new Immutable.Map({}), action, id) { + if (action.type === MENU) { + // action applied to all menus + if (!action.id) { + return Object.assign({}, state.get(id), {active: action.active}); + } + + if (action.id !== id) return state.get(id); + + let target = state.get(action.id); + let active = action.active === 'toggle' ? !target.get('active') : action.active; + + let style = Object.assign({}, state.style, {left: action.x, top: action.y}); + + return Object.assign({}, target, { style, active }); + } else { + return state.get(id); + } +} diff --git a/src/js/reducers/navigation.js b/src/js/reducers/navigation.js new file mode 100644 index 0000000..ac9e4fe --- /dev/null +++ b/src/js/reducers/navigation.js @@ -0,0 +1,9 @@ +import { NAVIGATION, TOGGLE } from 'actions/types'; + +export default function(state = false, action) { + if (action.type === NAVIGATION) { + return action.active === TOGGLE ? !state : action.active; + } + + return state; +} diff --git a/src/js/store.js b/src/js/store.js index 2f92cbf..cd75e8a 100644 --- a/src/js/store.js +++ b/src/js/store.js @@ -2,13 +2,19 @@ import { createStore } from 'redux'; import reducers from 'reducers/all'; import changedir from 'actions/changedir'; import Immutable from 'immutable'; +import menus from './menus'; +import dialogs from './dialogs'; -const DEFAULT = new Immutable.Map({ - dir: '/', +const DEFAULT = new Immutable.Map(Object.assign({ + dir: '', files: [] -}); +}, dialogs, menus)); let store = createStore(reducers, DEFAULT); -store.dispatch(changedir(DEFAULT.dir)); +store.dispatch(changedir(DEFAULT.get('dir'))); + +export function bind(action) { + return () => store.dispatch(action); +} export default store; diff --git a/src/js/utils.js b/src/js/utils.js new file mode 100644 index 0000000..8338fb8 --- /dev/null +++ b/src/js/utils.js @@ -0,0 +1,3 @@ +export function type(obj) { + return Object.prototype.toString.call(obj).slice(8, -1); +} diff --git a/src/less/components/all.less b/src/less/components/all.less new file mode 100644 index 0000000..cec920f --- /dev/null +++ b/src/less/components/all.less @@ -0,0 +1,8 @@ +@import 'entries'; +@import 'header'; +@import 'menu'; +@import 'navigation'; +@import 'toolbar'; +@import 'breadcrumb'; +@import 'file-list'; +@import 'dialog'; diff --git a/src/less/components/breadcrumb.less b/src/less/components/breadcrumb.less new file mode 100644 index 0000000..b93b56c --- /dev/null +++ b/src/less/components/breadcrumb.less @@ -0,0 +1,26 @@ +.breadcrumb { + display: flex; + flex: 1; + align-items: center; + + width: 100vw; + height: 3.5rem; + + padding: 8px; + + box-sizing: border-box; + + .light-medium; + + background: @light-gray; + + border-bottom: 1px solid @dark-transparent; + + i { + margin: 0 2px; + } + + span.history { + color: @overlay; + } +} diff --git a/src/less/components/dialog.less b/src/less/components/dialog.less new file mode 100644 index 0000000..2c3222f --- /dev/null +++ b/src/less/components/dialog.less @@ -0,0 +1,62 @@ +.dialog { + display: flex; + flex-flow: column; + + position: fixed; + top: 50%; + left: 50%; + + transform: translate(-50%, -50%); + + + width: 335px; + height: auto; + + padding: 1.5rem 1.7rem; + + background: white; + + .shadow-bottom; + + z-index: 3; + + transition: opacity 0.5s ease; + + opacity: 0; + pointer-events: none; + + &.active { + opacity: 1; + pointer-events: all; + } + + p:first-of-type { + margin: 0 0 2.5rem; + } + p { + margin: 0 0 2rem; + } + + input { + margin-bottom: 2rem; + } + + .foot { + display: flex; + + justify-content: space-between; + + button { + flex: 1; + + margin: 0 8px; + + &:first-of-type { + margin-left: 0; + } + &:last-of-type { + margin-right: 0; + } + } + } +} diff --git a/src/less/components/entries.less b/src/less/components/entries.less new file mode 100644 index 0000000..2314bae --- /dev/null +++ b/src/less/components/entries.less @@ -0,0 +1,26 @@ +.file, .directory { + display: flex; + flex-flow: row; + align-items: center; + + padding: 1.4rem; + + width: 100%; + .light-big; + + box-sizing: border-box; + + border-bottom: 1px solid @dark-separator; + + i { + margin-right: 1.4rem; + } +} + +.directory i { + .icon-directory; +} + +.file i { + .icon-file; +} diff --git a/src/less/components/file-list.less b/src/less/components/file-list.less new file mode 100644 index 0000000..5077233 --- /dev/null +++ b/src/less/components/file-list.less @@ -0,0 +1,6 @@ +.file-list { + height: ~'calc(100vh - 13.5rem)'; + + overflow-x: hidden; + overflow-y: auto; +} diff --git a/src/less/components/header.less b/src/less/components/header.less new file mode 100644 index 0000000..c53e601 --- /dev/null +++ b/src/less/components/header.less @@ -0,0 +1,44 @@ +header { + display: flex; + flex: 1; + + flex-flow: row; + align-items: center; + + width: 100%; + height: 5rem; + + background: @dark; + color: white; + + .shadow; + + h1 { + margin-left: -3rem; + } + + button { + background: none; + border: none; + + width: 8rem; + height: 2rem; + + &::before { + content: ''; + display: block; + + width: 2rem; + height: 4px; + + margin-top: -9px; + + border-radius: 4px; + + background: @overlay; + + box-shadow: 0 7px 0 @overlay, + 0 14px 0 @overlay; + } + } +} diff --git a/src/less/components/menu.less b/src/less/components/menu.less new file mode 100644 index 0000000..f8d690c --- /dev/null +++ b/src/less/components/menu.less @@ -0,0 +1,43 @@ +.menu { + width: 24.5rem; + + position: fixed; + + left: 0; + top: 0; + + background: white; + border-radius: @radius; + + pointer-events: none; + + opacity: 0; + + transition: opacity 0.5s ease; + + .shadow-bottom; + + &.active { + opacity: 1; + + pointer-events: all; + } + + ul { + list-style: none; + + padding: 0 15px; + } + + li { + margin: 0; + + padding: 1.3rem 8px; + + border-bottom: 1px solid @dark-separator; + + &:last-of-type { + border-bottom: none; + } + } +} diff --git a/src/less/components/navigation.less b/src/less/components/navigation.less new file mode 100644 index 0000000..e7f484e --- /dev/null +++ b/src/less/components/navigation.less @@ -0,0 +1,77 @@ +nav { + display: flex; + flex-flow: column; + + position: fixed; + left: -70vw; + top: 0; + + width: 70vw; + height: 100vh; + + background: @dark; + color: white; + + box-shadow: 1px 0 5px @dark-transparent; + z-index: 6; + + transition: left 0.5s ease; + + &.active { + left: 0; + + i { + pointer-events: all; + opacity: 0.99; + } + } + + p { + margin-left: 1.6rem; + + .regular-medium; + } + + ul { + list-style: none; + + padding-left: 0; + } + + li { + .light-medium; + + padding: 1rem 0 1rem 3rem; + + border-bottom: 1px solid @bright-separator; + + &:first-of-type { + padding-top: 0; + } + &:last-of-type { + padding-bottom: 0; + border-bottom: none; + } + } + + i { + display: block; + + position: fixed; + left: 0; + top: 0; + + pointer-events: none; + + width: 100vw; + height: 100vh; + + background: rgba(0, 0, 0, 0.55); + + opacity: 0; + + z-index: -1; + + transition: opacity 0.5s ease; + } +} diff --git a/src/less/components/toolbar.less b/src/less/components/toolbar.less new file mode 100644 index 0000000..1b5dba9 --- /dev/null +++ b/src/less/components/toolbar.less @@ -0,0 +1,14 @@ +.toolbar { + display: flex; + flex-flow: row; + align-items: center; + justify-content: space-around; + align-self: flex-end; + + width: 100vw; + height: 5rem; + + box-sizing: border-box; + + background: @light-gray; +} diff --git a/src/less/icons.less b/src/less/icons.less new file mode 100644 index 0000000..2d44909 --- /dev/null +++ b/src/less/icons.less @@ -0,0 +1,52 @@ +.icon { + display: block; +} + +.icon-directory { + .icon; + background: url(/img/Directory.svg) no-repeat; + width: 36px; + height: 32px; +} + +.icon-file { + .icon; + background: url(/img/File.svg) no-repeat; + width: 30px; + height: 36px; +} + +.icon-plus { + .icon; + background: url(/img/Plus.svg) no-repeat; + width: 24px; + height: 24px; +} + +.icon-view { + .icon; + background: url(/img/View.svg) no-repeat; + width: 24px; + height: 24px; +} + +.icon-refresh { + .icon; + background: url(/img/Refresh.svg) no-repeat; + width: 26px; + height: 28px; +} + +.icon-share { + .icon; + background: url(/img/Share.svg) no-repeat; + width: 25px; + height: 27px; +} + +.icon-more { + .icon; + background: url(/img/More.svg) no-repeat; + width: 6px; + height: 24px; +} diff --git a/src/less/main.less b/src/less/main.less index e69de29..8662067 100644 --- a/src/less/main.less +++ b/src/less/main.less @@ -0,0 +1,27 @@ +@import 'variables'; +@import 'icons'; +@import 'styles/all'; +@import 'components/all'; + +html, body { + margin: 0; + + font-family: Fira Sans; + font-weight: regular; + + box-sizing: border-box; +} + +html { + font-size: 10px; + + min-height: 100vh; +} + +body { + font-size: 1.6rem; + + display: flex; + + flex-flow: column; +} diff --git a/src/less/styles/all.less b/src/less/styles/all.less new file mode 100644 index 0000000..d5e7a5e --- /dev/null +++ b/src/less/styles/all.less @@ -0,0 +1,4 @@ +@import 'texts'; +@import 'shadows'; +@import 'buttons'; +@import 'forms'; diff --git a/src/less/styles/buttons.less b/src/less/styles/buttons.less new file mode 100644 index 0000000..e129c7f --- /dev/null +++ b/src/less/styles/buttons.less @@ -0,0 +1,21 @@ +button { + border: none; + background: none; +} + +.btn { + padding: 6px 3rem; + + border: 1px solid @gray; + + border-radius: @radius; + + .light-medium; + + background: @light-gray; + color: @dark; + + &.success { + background: @success; + } +} diff --git a/src/less/styles/forms.less b/src/less/styles/forms.less new file mode 100644 index 0000000..02eadb1 --- /dev/null +++ b/src/less/styles/forms.less @@ -0,0 +1,15 @@ +input { + border: 1px solid @gray; + + background: @light-gray; + + border-radius: 4px; + + height: 32px; + + box-sizing: border-box; + + padding: 5px 1rem; + + .light-medium; +} diff --git a/src/less/styles/shadows.less b/src/less/styles/shadows.less new file mode 100644 index 0000000..94b7f28 --- /dev/null +++ b/src/less/styles/shadows.less @@ -0,0 +1,7 @@ +.shadow-bottom { + box-shadow: 0 1px 2px @dark-transparent; +} + +.shadow { + box-shadow: 0 0 4px @dark-transparent; +} diff --git a/src/less/styles/texts.less b/src/less/styles/texts.less new file mode 100644 index 0000000..399113f --- /dev/null +++ b/src/less/styles/texts.less @@ -0,0 +1,31 @@ +.regular-medium { + font-weight: normal; +} + +.regular-medium { + font-size: 1.8rem; +} + +.light-medium, .light-big, .light-small { + font-weight: @light; +} + +.light-medium { + font-size: 1.6rem; +} + +.light-big { + font-size: 1.8rem; +} + +.light-small { + font-size: 1.3rem; +} + +.thin-small { + font-weight: @thin; +} + +.thin-small { + font-size: 1.4rem; +} diff --git a/src/less/variables.less b/src/less/variables.less index 59c227c..6e53cb4 100644 --- a/src/less/variables.less +++ b/src/less/variables.less @@ -1 +1,23 @@ -@ +@dark: #39393A; +@green: #5EBEC2; +@overlay: #9B9B93; +@light-gray: #F8F8F8; +@gray: #F0F0F0; +@background: #FAFAFA; +@blue: #63B0CD; + +@success: #B8E986; + +@bright-separator: rgba(255, 255, 255, 0.1); +@dark-separator: rgba(0, 0, 0, 0.1); + +@dark-transparent: rgba(0, 0, 0, 0.2); +@bright-transparent: rgba(0, 0, 0, 0.2); + + +// Font Weights +@regular: normal; +@light: 200; +@thin: 100; + +@radius: 4px; diff --git a/src/manifest.webapp b/src/manifest.webapp index 6a6102c..bfa7f4f 100644 --- a/src/manifest.webapp +++ b/src/manifest.webapp @@ -15,10 +15,10 @@ }, "type": "privileged", "permissions": { + "device-storage:sdcard": {"access": "readwrite"}, "device-storage:videos": {"access": "readwrite"}, "device-storage:pictures": {"access": "readwrite"}, "device-storage:music": {"access": "readwrite"}, - "device-storage:sdcard": {"access": "readwrite"}, "device-storage:apps": {"access": "readwrite"}, "webapps-manage": {} }, diff --git a/template/LICENSE b/template/LICENSE deleted file mode 100644 index 53d5a38..0000000 --- a/template/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2014 Mozilla Foundation - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - diff --git a/template/README.md b/template/README.md deleted file mode 100644 index 87b7243..0000000 --- a/template/README.md +++ /dev/null @@ -1,68 +0,0 @@ -# Privileged empty app - -This is a privileged empty app template that provides you with a barebones structure for you to build your app. - -This is part of the [mortar](https://github.com/mozilla/mortar/) template collection for building [Open Web Apps](https://developer.mozilla.org/Apps). - -## Obtaining - -There are a few ways to get this template: - -If you use [Git](http://www.git-scm.com/): - -````bash -git clone https://github.com/mozilla/mortar-privileged-empty-app.git -```` - -Or download the latest version in this [ZIP file](https://github.com/mozilla/mortar-privileged-empty-app/archive/master.zip). - - -## Usage - -Import the app into the [App Manager](https://developer.mozilla.org/Firefox_OS/Using_the_App_Manager). Then you can run it in the simulator, or in a Firefox OS device. - -## Code walkthrough - -The `manifest.webapp` file contains metadata about the app, such as its name, description, icon and required permissions for running under Firefox OS. - -Moving over to `index.html`, this is the starting point for the app when it's launched, and also where the layout is defined and the JavaScript files with the functionality and logic are loaded. - -The appearance is defined in `css/app.css`. There are just some very basic rules. - -We define the app's behaviour in `js/app.js`. Right now we're just basically displaying a "Hello world" message. - -Finally we are also including `js/libs/l10n.js`, which contains [L10n](https://developer.mozilla.org/en-US/docs/Web/API/L10n_API), a library for translating the strings in the app. Using this library, users can run the app in their own language, as long as you provide the translations for those languages. We're currently including a translation to Spanish as an example, but feel free to contribute with more translations in `data/locales.ini`, looking at `data/es.properties` and `data/en-US.properties` to see the syntax in action. The way it works, it will automatically translate the HTML elements that contain a `data-l10n-id` attribute with the translation identifier. - -For any dynamically shown content, you need to use the `navigator.webL10n.get` function, but since that is slightly tedious to write each time, we're aliasing it to just `translate`: - -```javascript -var translate = navigator.mozL10n.get; -``` - -## Getting help - -If you find something that doesn't quite work as you'd expect, we'd appreciate if you [filed a bug](https://github.com/mozilla/mortar-privileged-empty-app/issues)! - -We need your help in order to help you. Therefore: - -1. Tell us which version of the template are you using. Where did you get the code from? -* Specify the environment where the bug occurs i.e. which version of the Simulator or Firefox OS device. An example would be `1.2 simulator` or `Boot2Gecko 1.4.0.0`. -* Describe the problem in detail. What were you doing? What happened? What did you expect to happen? -* Probably also provide a test case so we can see what is happening and try to reproduce the error. - -Ultimately it all boils down to the fact that if we can't reproduce it, we can't help you or fix it either. - -## Contributing - -Contributions are always welcome! If you want to collaborate, whether that is with a new feature or fixing a bug, we recommend you... - -1. Have a look at the [issue tracker](https://github.com/mozilla/mortar-privileged-empty-app/issues) first--to make sure there isn't anyone working on that already. -* If it's a new issue/feature, or no one is working on it already, fork the project in GitHub (you'll need an account if you don't have it yet). -* Create the bug to let us know you want to work on this. That way we are aware of and can keep an eye on it, or maybe tell you that it is not a bug but an intended feature, and save you the hassle of working on something that is not needed. -* Clone your fork to your computer (i.e. get the code onto your computer) -* Make a new branch, and switch to that new branch -* Do the changes you deem necessary -* Push the branch to GitHub -* Send a pull request - -To make your changes as easy to merge back onto the project as possible, you should only work on one feature per branch. That makes code review simpler and faster! diff --git a/template/css/app.css b/template/css/app.css deleted file mode 100644 index 2d611ca..0000000 --- a/template/css/app.css +++ /dev/null @@ -1,18 +0,0 @@ -html, body { - margin: 0; - padding: 0.5rem; -} - -body { - font-size: 1rem; - background: #fff; -} - -h1 { - margin: 0 0 1rem 0; -} - -p { - font-size: inherit; -} - diff --git a/template/img/icons/icon.svg b/template/img/icons/icon.svg deleted file mode 100644 index 834968c..0000000 --- a/template/img/icons/icon.svg +++ /dev/null @@ -1,106 +0,0 @@ - - - - - - image/svg+xml - - - - - - - empty - Created with Sketch. - - - - - - - - - - - - diff --git a/template/img/icons/icon128x128.png b/template/img/icons/icon128x128.png deleted file mode 100644 index 7c672c5..0000000 Binary files a/template/img/icons/icon128x128.png and /dev/null differ diff --git a/template/img/icons/icon16x16.png b/template/img/icons/icon16x16.png deleted file mode 100644 index abf254e..0000000 Binary files a/template/img/icons/icon16x16.png and /dev/null differ diff --git a/template/img/icons/icon48x48.png b/template/img/icons/icon48x48.png deleted file mode 100644 index 451655b..0000000 Binary files a/template/img/icons/icon48x48.png and /dev/null differ diff --git a/template/img/icons/icon60x60.png b/template/img/icons/icon60x60.png deleted file mode 100644 index c7d4115..0000000 Binary files a/template/img/icons/icon60x60.png and /dev/null differ diff --git a/template/index.html b/template/index.html deleted file mode 100644 index 7813f36..0000000 --- a/template/index.html +++ /dev/null @@ -1,48 +0,0 @@ - - - - - Privileged app - - - - - - - - - - - - - - -
    -

    Privileged empty app

    -

    This app is empty. Fill it with your own stuff!

    -

    -
    - - diff --git a/template/js/app.js b/template/js/app.js deleted file mode 100644 index b159de7..0000000 --- a/template/js/app.js +++ /dev/null @@ -1,29 +0,0 @@ -// DOMContentLoaded is fired once the document has been loaded and parsed, -// but without waiting for other external resources to load (css/images/etc) -// That makes the app more responsive and perceived as faster. -// https://developer.mozilla.org/Web/Reference/Events/DOMContentLoaded -window.addEventListener('DOMContentLoaded', function() { - - // We'll ask the browser to use strict code to help us catch errors earlier. - // https://developer.mozilla.org/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode - 'use strict'; - - var translate = navigator.mozL10n.get; - - // We want to wait until the localisations library has loaded all the strings. - // So we'll tell it to let us know once it's ready. - navigator.mozL10n.once(start); - - // --- - - function start() { - - var message = document.getElementById('message'); - - // We're using textContent because inserting content from external sources into your page using innerHTML can be dangerous. - // https://developer.mozilla.org/Web/API/Element.innerHTML#Security_considerations - message.textContent = translate('message'); - - } - -}); diff --git a/template/js/libs/l10n.js b/template/js/libs/l10n.js deleted file mode 100644 index cfc5c51..0000000 --- a/template/js/libs/l10n.js +++ /dev/null @@ -1,1571 +0,0 @@ -// This is the Gaia version of l20n: https://github.com/l20n/l20n.js -// l20n is Apache 2.0 licensed: https://github.com/l20n/l20n.js/blob/master/LICENSE -// You can find the latest build for Gaia here: https://github.com/mozilla-b2g/gaia/blob/master/shared/js/l10n.js -(function(window, undefined) { - 'use strict'; - - /* jshint validthis:true */ - function L10nError(message, id, loc) { - this.name = 'L10nError'; - this.message = message; - this.id = id; - this.loc = loc; - } - L10nError.prototype = Object.create(Error.prototype); - L10nError.prototype.constructor = L10nError; - - - /* jshint browser:true */ - - var io = { - load: function load(url, callback, sync) { - var xhr = new XMLHttpRequest(); - - if (xhr.overrideMimeType) { - xhr.overrideMimeType('text/plain'); - } - - xhr.open('GET', url, !sync); - - xhr.addEventListener('load', function io_load(e) { - if (e.target.status === 200 || e.target.status === 0) { - callback(null, e.target.responseText); - } else { - callback(new L10nError('Not found: ' + url)); - } - }); - xhr.addEventListener('error', callback); - xhr.addEventListener('timeout', callback); - - // the app: protocol throws on 404, see https://bugzil.la/827243 - try { - xhr.send(null); - } catch (e) { - callback(new L10nError('Not found: ' + url)); - } - }, - - loadJSON: function loadJSON(url, callback) { - var xhr = new XMLHttpRequest(); - - if (xhr.overrideMimeType) { - xhr.overrideMimeType('application/json'); - } - - xhr.open('GET', url); - - xhr.responseType = 'json'; - xhr.addEventListener('load', function io_loadjson(e) { - if (e.target.status === 200 || e.target.status === 0) { - callback(null, e.target.response); - } else { - callback(new L10nError('Not found: ' + url)); - } - }); - xhr.addEventListener('error', callback); - xhr.addEventListener('timeout', callback); - - // the app: protocol throws on 404, see https://bugzil.la/827243 - try { - xhr.send(null); - } catch (e) { - callback(new L10nError('Not found: ' + url)); - } - } - }; - - function EventEmitter() {} - - EventEmitter.prototype.emit = function ee_emit() { - if (!this._listeners) { - return; - } - - var args = Array.prototype.slice.call(arguments); - var type = args.shift(); - if (!this._listeners[type]) { - return; - } - - var typeListeners = this._listeners[type].slice(); - for (var i = 0; i < typeListeners.length; i++) { - typeListeners[i].apply(this, args); - } - }; - - EventEmitter.prototype.addEventListener = function ee_add(type, listener) { - if (!this._listeners) { - this._listeners = {}; - } - if (!(type in this._listeners)) { - this._listeners[type] = []; - } - this._listeners[type].push(listener); - }; - - EventEmitter.prototype.removeEventListener = function ee_rm(type, listener) { - if (!this._listeners) { - return; - } - - var typeListeners = this._listeners[type]; - var pos = typeListeners.indexOf(listener); - if (pos === -1) { - return; - } - - typeListeners.splice(pos, 1); - }; - - - function getPluralRule(lang) { - var locales2rules = { - 'af': 3, - 'ak': 4, - 'am': 4, - 'ar': 1, - 'asa': 3, - 'az': 0, - 'be': 11, - 'bem': 3, - 'bez': 3, - 'bg': 3, - 'bh': 4, - 'bm': 0, - 'bn': 3, - 'bo': 0, - 'br': 20, - 'brx': 3, - 'bs': 11, - 'ca': 3, - 'cgg': 3, - 'chr': 3, - 'cs': 12, - 'cy': 17, - 'da': 3, - 'de': 3, - 'dv': 3, - 'dz': 0, - 'ee': 3, - 'el': 3, - 'en': 3, - 'eo': 3, - 'es': 3, - 'et': 3, - 'eu': 3, - 'fa': 0, - 'ff': 5, - 'fi': 3, - 'fil': 4, - 'fo': 3, - 'fr': 5, - 'fur': 3, - 'fy': 3, - 'ga': 8, - 'gd': 24, - 'gl': 3, - 'gsw': 3, - 'gu': 3, - 'guw': 4, - 'gv': 23, - 'ha': 3, - 'haw': 3, - 'he': 2, - 'hi': 4, - 'hr': 11, - 'hu': 0, - 'id': 0, - 'ig': 0, - 'ii': 0, - 'is': 3, - 'it': 3, - 'iu': 7, - 'ja': 0, - 'jmc': 3, - 'jv': 0, - 'ka': 0, - 'kab': 5, - 'kaj': 3, - 'kcg': 3, - 'kde': 0, - 'kea': 0, - 'kk': 3, - 'kl': 3, - 'km': 0, - 'kn': 0, - 'ko': 0, - 'ksb': 3, - 'ksh': 21, - 'ku': 3, - 'kw': 7, - 'lag': 18, - 'lb': 3, - 'lg': 3, - 'ln': 4, - 'lo': 0, - 'lt': 10, - 'lv': 6, - 'mas': 3, - 'mg': 4, - 'mk': 16, - 'ml': 3, - 'mn': 3, - 'mo': 9, - 'mr': 3, - 'ms': 0, - 'mt': 15, - 'my': 0, - 'nah': 3, - 'naq': 7, - 'nb': 3, - 'nd': 3, - 'ne': 3, - 'nl': 3, - 'nn': 3, - 'no': 3, - 'nr': 3, - 'nso': 4, - 'ny': 3, - 'nyn': 3, - 'om': 3, - 'or': 3, - 'pa': 3, - 'pap': 3, - 'pl': 13, - 'ps': 3, - 'pt': 3, - 'rm': 3, - 'ro': 9, - 'rof': 3, - 'ru': 11, - 'rwk': 3, - 'sah': 0, - 'saq': 3, - 'se': 7, - 'seh': 3, - 'ses': 0, - 'sg': 0, - 'sh': 11, - 'shi': 19, - 'sk': 12, - 'sl': 14, - 'sma': 7, - 'smi': 7, - 'smj': 7, - 'smn': 7, - 'sms': 7, - 'sn': 3, - 'so': 3, - 'sq': 3, - 'sr': 11, - 'ss': 3, - 'ssy': 3, - 'st': 3, - 'sv': 3, - 'sw': 3, - 'syr': 3, - 'ta': 3, - 'te': 3, - 'teo': 3, - 'th': 0, - 'ti': 4, - 'tig': 3, - 'tk': 3, - 'tl': 4, - 'tn': 3, - 'to': 0, - 'tr': 0, - 'ts': 3, - 'tzm': 22, - 'uk': 11, - 'ur': 3, - 've': 3, - 'vi': 0, - 'vun': 3, - 'wa': 4, - 'wae': 3, - 'wo': 0, - 'xh': 3, - 'xog': 3, - 'yo': 0, - 'zh': 0, - 'zu': 3 - }; - - // utility functions for plural rules methods - function isIn(n, list) { - return list.indexOf(n) !== -1; - } - function isBetween(n, start, end) { - return start <= n && n <= end; - } - - // list of all plural rules methods: - // map an integer to the plural form name to use - var pluralRules = { - '0': function() { - return 'other'; - }, - '1': function(n) { - if ((isBetween((n % 100), 3, 10))) { - return 'few'; - } - if (n === 0) { - return 'zero'; - } - if ((isBetween((n % 100), 11, 99))) { - return 'many'; - } - if (n === 2) { - return 'two'; - } - if (n === 1) { - return 'one'; - } - return 'other'; - }, - '2': function(n) { - if (n !== 0 && (n % 10) === 0) { - return 'many'; - } - if (n === 2) { - return 'two'; - } - if (n === 1) { - return 'one'; - } - return 'other'; - }, - '3': function(n) { - if (n === 1) { - return 'one'; - } - return 'other'; - }, - '4': function(n) { - if ((isBetween(n, 0, 1))) { - return 'one'; - } - return 'other'; - }, - '5': function(n) { - if ((isBetween(n, 0, 2)) && n !== 2) { - return 'one'; - } - return 'other'; - }, - '6': function(n) { - if (n === 0) { - return 'zero'; - } - if ((n % 10) === 1 && (n % 100) !== 11) { - return 'one'; - } - return 'other'; - }, - '7': function(n) { - if (n === 2) { - return 'two'; - } - if (n === 1) { - return 'one'; - } - return 'other'; - }, - '8': function(n) { - if ((isBetween(n, 3, 6))) { - return 'few'; - } - if ((isBetween(n, 7, 10))) { - return 'many'; - } - if (n === 2) { - return 'two'; - } - if (n === 1) { - return 'one'; - } - return 'other'; - }, - '9': function(n) { - if (n === 0 || n !== 1 && (isBetween((n % 100), 1, 19))) { - return 'few'; - } - if (n === 1) { - return 'one'; - } - return 'other'; - }, - '10': function(n) { - if ((isBetween((n % 10), 2, 9)) && !(isBetween((n % 100), 11, 19))) { - return 'few'; - } - if ((n % 10) === 1 && !(isBetween((n % 100), 11, 19))) { - return 'one'; - } - return 'other'; - }, - '11': function(n) { - if ((isBetween((n % 10), 2, 4)) && !(isBetween((n % 100), 12, 14))) { - return 'few'; - } - if ((n % 10) === 0 || - (isBetween((n % 10), 5, 9)) || - (isBetween((n % 100), 11, 14))) { - return 'many'; - } - if ((n % 10) === 1 && (n % 100) !== 11) { - return 'one'; - } - return 'other'; - }, - '12': function(n) { - if ((isBetween(n, 2, 4))) { - return 'few'; - } - if (n === 1) { - return 'one'; - } - return 'other'; - }, - '13': function(n) { - if ((isBetween((n % 10), 2, 4)) && !(isBetween((n % 100), 12, 14))) { - return 'few'; - } - if (n !== 1 && (isBetween((n % 10), 0, 1)) || - (isBetween((n % 10), 5, 9)) || - (isBetween((n % 100), 12, 14))) { - return 'many'; - } - if (n === 1) { - return 'one'; - } - return 'other'; - }, - '14': function(n) { - if ((isBetween((n % 100), 3, 4))) { - return 'few'; - } - if ((n % 100) === 2) { - return 'two'; - } - if ((n % 100) === 1) { - return 'one'; - } - return 'other'; - }, - '15': function(n) { - if (n === 0 || (isBetween((n % 100), 2, 10))) { - return 'few'; - } - if ((isBetween((n % 100), 11, 19))) { - return 'many'; - } - if (n === 1) { - return 'one'; - } - return 'other'; - }, - '16': function(n) { - if ((n % 10) === 1 && n !== 11) { - return 'one'; - } - return 'other'; - }, - '17': function(n) { - if (n === 3) { - return 'few'; - } - if (n === 0) { - return 'zero'; - } - if (n === 6) { - return 'many'; - } - if (n === 2) { - return 'two'; - } - if (n === 1) { - return 'one'; - } - return 'other'; - }, - '18': function(n) { - if (n === 0) { - return 'zero'; - } - if ((isBetween(n, 0, 2)) && n !== 0 && n !== 2) { - return 'one'; - } - return 'other'; - }, - '19': function(n) { - if ((isBetween(n, 2, 10))) { - return 'few'; - } - if ((isBetween(n, 0, 1))) { - return 'one'; - } - return 'other'; - }, - '20': function(n) { - if ((isBetween((n % 10), 3, 4) || ((n % 10) === 9)) && !( - isBetween((n % 100), 10, 19) || - isBetween((n % 100), 70, 79) || - isBetween((n % 100), 90, 99) - )) { - return 'few'; - } - if ((n % 1000000) === 0 && n !== 0) { - return 'many'; - } - if ((n % 10) === 2 && !isIn((n % 100), [12, 72, 92])) { - return 'two'; - } - if ((n % 10) === 1 && !isIn((n % 100), [11, 71, 91])) { - return 'one'; - } - return 'other'; - }, - '21': function(n) { - if (n === 0) { - return 'zero'; - } - if (n === 1) { - return 'one'; - } - return 'other'; - }, - '22': function(n) { - if ((isBetween(n, 0, 1)) || (isBetween(n, 11, 99))) { - return 'one'; - } - return 'other'; - }, - '23': function(n) { - if ((isBetween((n % 10), 1, 2)) || (n % 20) === 0) { - return 'one'; - } - return 'other'; - }, - '24': function(n) { - if ((isBetween(n, 3, 10) || isBetween(n, 13, 19))) { - return 'few'; - } - if (isIn(n, [2, 12])) { - return 'two'; - } - if (isIn(n, [1, 11])) { - return 'one'; - } - return 'other'; - } - }; - - // return a function that gives the plural form name for a given integer - var index = locales2rules[lang.replace(/-.*$/, '')]; - if (!(index in pluralRules)) { - return function() { return 'other'; }; - } - return pluralRules[index]; - } - - - - - var nestedProps = ['style', 'dataset']; - - var parsePatterns; - - function parse(ctx, source) { - var ast = {}; - - if (!parsePatterns) { - parsePatterns = { - comment: /^\s*#|^\s*$/, - entity: /^([^=\s]+)\s*=\s*(.+)$/, - multiline: /[^\\]\\$/, - macro: /\{\[\s*(\w+)\(([^\)]*)\)\s*\]\}/i, - unicode: /\\u([0-9a-fA-F]{1,4})/g, - entries: /[\r\n]+/, - controlChars: /\\([\\\n\r\t\b\f\{\}\"\'])/g - }; - } - - var entries = source.split(parsePatterns.entries); - for (var i = 0; i < entries.length; i++) { - var line = entries[i]; - - if (parsePatterns.comment.test(line)) { - continue; - } - - while (parsePatterns.multiline.test(line) && i < entries.length) { - line = line.slice(0, -1) + entries[++i].trim(); - } - - var entityMatch = line.match(parsePatterns.entity); - if (entityMatch) { - try { - parseEntity(entityMatch[1], entityMatch[2], ast); - } catch (e) { - if (ctx) { - ctx._emitter.emit('error', e); - } else { - throw e; - } - } - } - } - return ast; - } - - function setEntityValue(id, attr, key, value, ast) { - var obj = ast; - var prop = id; - - if (attr) { - if (!(id in obj)) { - obj[id] = {}; - } - if (typeof(obj[id]) === 'string') { - obj[id] = {'_': obj[id]}; - } - obj = obj[id]; - prop = attr; - } - - if (!key) { - obj[prop] = value; - return; - } - - if (!(prop in obj)) { - obj[prop] = {'_': {}}; - } else if (typeof(obj[prop]) === 'string') { - obj[prop] = {'_index': parseMacro(obj[prop]), '_': {}}; - } - obj[prop]._[key] = value; - } - - function parseEntity(id, value, ast) { - var name, key; - - var pos = id.indexOf('['); - if (pos !== -1) { - name = id.substr(0, pos); - key = id.substring(pos + 1, id.length - 1); - } else { - name = id; - key = null; - } - - var nameElements = name.split('.'); - - var attr; - if (nameElements.length > 1) { - var attrElements = []; - attrElements.push(nameElements.pop()); - if (nameElements.length > 1) { - // Usually the last dot separates an attribute from an id - // - // In case when there are more than one dot in the id - // and the second to last item is "style" or "dataset" then the last two - // items are becoming the attribute. - // - // ex. - // id.style.color = foo => - // - // id: - // style.color: foo - // - // id.other.color = foo => - // - // id.other: - // color: foo - if (nestedProps.indexOf(nameElements[nameElements.length - 1]) !== -1) { - attrElements.push(nameElements.pop()); - } - } - name = nameElements.join('.'); - attr = attrElements.reverse().join('.'); - } else { - attr = null; - } - - setEntityValue(name, attr, key, unescapeString(value), ast); - } - - function unescapeControlCharacters(str) { - return str.replace(parsePatterns.controlChars, '$1'); - } - - function unescapeUnicode(str) { - return str.replace(parsePatterns.unicode, function(match, token) { - return unescape('%u' + '0000'.slice(token.length) + token); - }); - } - - function unescapeString(str) { - if (str.lastIndexOf('\\') !== -1) { - str = unescapeControlCharacters(str); - } - return unescapeUnicode(str); - } - - function parseMacro(str) { - var match = str.match(parsePatterns.macro); - if (!match) { - throw new L10nError('Malformed macro'); - } - return [match[1], match[2]]; - } - - - - var MAX_PLACEABLE_LENGTH = 2500; - var MAX_PLACEABLES = 100; - var rePlaceables = /\{\{\s*(.+?)\s*\}\}/g; - - function Entity(id, node, env) { - this.id = id; - this.env = env; - // the dirty guard prevents cyclic or recursive references from other - // Entities; see Entity.prototype.resolve - this.dirty = false; - if (typeof node === 'string') { - this.value = node; - } else { - // it's either a hash or it has attrs, or both - for (var key in node) { - if (node.hasOwnProperty(key) && key[0] !== '_') { - if (!this.attributes) { - this.attributes = {}; - } - this.attributes[key] = new Entity(this.id + '.' + key, node[key], - env); - } - } - this.value = node._ || null; - this.index = node._index; - } - } - - Entity.prototype.resolve = function E_resolve(ctxdata) { - if (this.dirty) { - return undefined; - } - - this.dirty = true; - var val; - // if resolve fails, we want the exception to bubble up and stop the whole - // resolving process; however, we still need to clean up the dirty flag - try { - val = resolve(ctxdata, this.env, this.value, this.index); - } finally { - this.dirty = false; - } - return val; - }; - - Entity.prototype.toString = function E_toString(ctxdata) { - try { - return this.resolve(ctxdata); - } catch (e) { - return undefined; - } - }; - - Entity.prototype.valueOf = function E_valueOf(ctxdata) { - if (!this.attributes) { - return this.toString(ctxdata); - } - - var entity = { - value: this.toString(ctxdata), - attributes: {} - }; - - for (var key in this.attributes) { - if (this.attributes.hasOwnProperty(key)) { - entity.attributes[key] = this.attributes[key].toString(ctxdata); - } - } - - return entity; - }; - - function subPlaceable(ctxdata, env, match, id) { - if (ctxdata && ctxdata.hasOwnProperty(id) && - (typeof ctxdata[id] === 'string' || - (typeof ctxdata[id] === 'number' && !isNaN(ctxdata[id])))) { - return ctxdata[id]; - } - - if (env.hasOwnProperty(id)) { - if (!(env[id] instanceof Entity)) { - env[id] = new Entity(id, env[id], env); - } - var value = env[id].resolve(ctxdata); - if (typeof value === 'string') { - // prevent Billion Laughs attacks - if (value.length >= MAX_PLACEABLE_LENGTH) { - throw new L10nError('Too many characters in placeable (' + - value.length + ', max allowed is ' + - MAX_PLACEABLE_LENGTH + ')'); - } - return value; - } - } - return match; - } - - function interpolate(ctxdata, env, str) { - var placeablesCount = 0; - var value = str.replace(rePlaceables, function(match, id) { - // prevent Quadratic Blowup attacks - if (placeablesCount++ >= MAX_PLACEABLES) { - throw new L10nError('Too many placeables (' + placeablesCount + - ', max allowed is ' + MAX_PLACEABLES + ')'); - } - return subPlaceable(ctxdata, env, match, id); - }); - placeablesCount = 0; - return value; - } - - function resolve(ctxdata, env, expr, index) { - if (typeof expr === 'string') { - return interpolate(ctxdata, env, expr); - } - - if (typeof expr === 'boolean' || - typeof expr === 'number' || - !expr) { - return expr; - } - - // otherwise, it's a dict - - if (index && ctxdata && ctxdata.hasOwnProperty(index[1])) { - var argValue = ctxdata[index[1]]; - - // special cases for zero, one, two if they are defined on the hash - if (argValue === 0 && 'zero' in expr) { - return resolve(ctxdata, env, expr.zero); - } - if (argValue === 1 && 'one' in expr) { - return resolve(ctxdata, env, expr.one); - } - if (argValue === 2 && 'two' in expr) { - return resolve(ctxdata, env, expr.two); - } - - var selector = env.__plural(argValue); - if (expr.hasOwnProperty(selector)) { - return resolve(ctxdata, env, expr[selector]); - } - } - - // if there was no index or no selector was found, try 'other' - if ('other' in expr) { - return resolve(ctxdata, env, expr.other); - } - - return undefined; - } - - function compile(env, ast) { - env = env || {}; - for (var id in ast) { - if (ast.hasOwnProperty(id)) { - env[id] = new Entity(id, ast[id], env); - } - } - return env; - } - - - - function Locale(id, ctx) { - this.id = id; - this.ctx = ctx; - this.isReady = false; - this.entries = { - __plural: getPluralRule(id) - }; - } - - Locale.prototype.getEntry = function L_getEntry(id) { - /* jshint -W093 */ - - var entries = this.entries; - - if (!entries.hasOwnProperty(id)) { - return undefined; - } - - if (entries[id] instanceof Entity) { - return entries[id]; - } - - return entries[id] = new Entity(id, entries[id], entries); - }; - - Locale.prototype.build = function L_build(callback) { - var sync = !callback; - var ctx = this.ctx; - var self = this; - - var l10nLoads = ctx.resLinks.length; - - function onL10nLoaded(err) { - if (err) { - ctx._emitter.emit('error', err); - } - if (--l10nLoads <= 0) { - self.isReady = true; - if (callback) { - callback(); - } - } - } - - if (l10nLoads === 0) { - onL10nLoaded(); - return; - } - - function onJSONLoaded(err, json) { - if (!err && json) { - self.addAST(json); - } - onL10nLoaded(err); - } - - function onPropLoaded(err, source) { - if (!err && source) { - var ast = parse(ctx, source); - self.addAST(ast); - } - onL10nLoaded(err); - } - - - for (var i = 0; i < ctx.resLinks.length; i++) { - var path = ctx.resLinks[i].replace('{{locale}}', this.id); - var type = path.substr(path.lastIndexOf('.') + 1); - - switch (type) { - case 'json': - io.loadJSON(path, onJSONLoaded, sync); - break; - case 'properties': - io.load(path, onPropLoaded, sync); - break; - } - } - }; - - Locale.prototype.addAST = function(ast) { - for (var id in ast) { - if (ast.hasOwnProperty(id)) { - this.entries[id] = ast[id]; - } - } - }; - - Locale.prototype.getEntity = function(id, ctxdata) { - var entry = this.getEntry(id); - - if (!entry) { - return null; - } - return entry.valueOf(ctxdata); - }; - - - - function Context(id) { - - this.id = id; - this.isReady = false; - this.isLoading = false; - - this.supportedLocales = []; - this.resLinks = []; - this.locales = {}; - - this._emitter = new EventEmitter(); - - - // Getting translations - - function getWithFallback(id) { - /* jshint -W084 */ - - if (!this.isReady) { - throw new L10nError('Context not ready'); - } - - var cur = 0; - var loc; - var locale; - while (loc = this.supportedLocales[cur]) { - locale = this.getLocale(loc); - if (!locale.isReady) { - // build without callback, synchronously - locale.build(null); - } - var entry = locale.getEntry(id); - if (entry === undefined) { - cur++; - warning.call(this, new L10nError(id + ' not found in ' + loc, id, - loc)); - continue; - } - return entry; - } - - error.call(this, new L10nError(id + ' not found', id)); - return null; - } - - this.get = function get(id, ctxdata) { - var entry = getWithFallback.call(this, id); - if (entry === null) { - return ''; - } - - return entry.toString(ctxdata) || ''; - }; - - this.getEntity = function getEntity(id, ctxdata) { - var entry = getWithFallback.call(this, id); - if (entry === null) { - return null; - } - - return entry.valueOf(ctxdata); - }; - - - // Helpers - - this.getLocale = function getLocale(code) { - /* jshint -W093 */ - - var locales = this.locales; - if (locales[code]) { - return locales[code]; - } - - return locales[code] = new Locale(code, this); - }; - - - // Getting ready - - function negotiate(available, requested, defaultLocale) { - if (available.indexOf(requested[0]) === -1 || - requested[0] === defaultLocale) { - return [defaultLocale]; - } else { - return [requested[0], defaultLocale]; - } - } - - function freeze(supported) { - var locale = this.getLocale(supported[0]); - if (locale.isReady) { - setReady.call(this, supported); - } else { - locale.build(setReady.bind(this, supported)); - } - } - - function setReady(supported) { - this.supportedLocales = supported; - this.isReady = true; - this._emitter.emit('ready'); - } - - this.requestLocales = function requestLocales() { - if (this.isLoading && !this.isReady) { - throw new L10nError('Context not ready'); - } - - this.isLoading = true; - var requested = Array.prototype.slice.call(arguments); - - var supported = negotiate(requested.concat('en-US'), requested, 'en-US'); - freeze.call(this, supported); - }; - - - // Events - - this.addEventListener = function addEventListener(type, listener) { - this._emitter.addEventListener(type, listener); - }; - - this.removeEventListener = function removeEventListener(type, listener) { - this._emitter.removeEventListener(type, listener); - }; - - this.ready = function ready(callback) { - if (this.isReady) { - setTimeout(callback); - } - this.addEventListener('ready', callback); - }; - - this.once = function once(callback) { - /* jshint -W068 */ - if (this.isReady) { - setTimeout(callback); - return; - } - - var callAndRemove = (function() { - this.removeEventListener('ready', callAndRemove); - callback(); - }).bind(this); - this.addEventListener('ready', callAndRemove); - }; - - - // Errors - - function warning(e) { - this._emitter.emit('warning', e); - return e; - } - - function error(e) { - this._emitter.emit('error', e); - return e; - } - } - - - /* jshint -W104 */ - - var DEBUG = false; - var isPretranslated = false; - var rtlList = ['ar', 'he', 'fa', 'ps', 'qps-plocm', 'ur']; - - // Public API - - navigator.mozL10n = { - ctx: new Context(), - get: function get(id, ctxdata) { - return navigator.mozL10n.ctx.get(id, ctxdata); - }, - localize: function localize(element, id, args) { - return localizeElement.call(navigator.mozL10n, element, id, args); - }, - translate: function translate(element) { - return translateFragment.call(navigator.mozL10n, element); - }, - ready: function ready(callback) { - return navigator.mozL10n.ctx.ready(callback); - }, - once: function once(callback) { - return navigator.mozL10n.ctx.once(callback); - }, - get readyState() { - return navigator.mozL10n.ctx.isReady ? 'complete' : 'loading'; - }, - language: { - set code(lang) { - navigator.mozL10n.ctx.requestLocales(lang); - }, - get code() { - return navigator.mozL10n.ctx.supportedLocales[0]; - }, - get direction() { - return getDirection(navigator.mozL10n.ctx.supportedLocales[0]); - } - }, - _getInternalAPI: function() { - return { - Error: L10nError, - Context: Context, - Locale: Locale, - Entity: Entity, - getPluralRule: getPluralRule, - rePlaceables: rePlaceables, - getTranslatableChildren: getTranslatableChildren, - getL10nAttributes: getL10nAttributes, - loadINI: loadINI, - fireLocalizedEvent: fireLocalizedEvent, - parse: parse, - compile: compile - }; - } - }; - - navigator.mozL10n.ctx.ready(onReady.bind(navigator.mozL10n)); - - if (DEBUG) { - navigator.mozL10n.ctx.addEventListener('error', console.error); - navigator.mozL10n.ctx.addEventListener('warning', console.warn); - } - - function getDirection(lang) { - return (rtlList.indexOf(lang) >= 0) ? 'rtl' : 'ltr'; - } - - var readyStates = { - 'loading': 0, - 'interactive': 1, - 'complete': 2 - }; - - function waitFor(state, callback) { - state = readyStates[state]; - if (readyStates[document.readyState] >= state) { - callback(); - return; - } - - document.addEventListener('readystatechange', function l10n_onrsc() { - if (readyStates[document.readyState] >= state) { - document.removeEventListener('readystatechange', l10n_onrsc); - callback(); - } - }); - } - - if (window.document) { - isPretranslated = (document.documentElement.lang === navigator.language); - - // this is a special case for netError bug; see https://bugzil.la/444165 - if (document.documentElement.dataset.noCompleteBug) { - pretranslate.call(navigator.mozL10n); - return; - } - - - if (isPretranslated) { - waitFor('interactive', function() { - window.setTimeout(initResources.bind(navigator.mozL10n)); - }); - } else { - if (document.readyState === 'complete') { - window.setTimeout(initResources.bind(navigator.mozL10n)); - } else { - waitFor('interactive', pretranslate.bind(navigator.mozL10n)); - } - } - - } - - function pretranslate() { - /* jshint -W068 */ - if (inlineLocalization.call(this)) { - waitFor('interactive', (function() { - window.setTimeout(initResources.bind(this)); - }).bind(this)); - } else { - initResources.call(this); - } - } - - function inlineLocalization() { - var script = document.documentElement - .querySelector('script[type="application/l10n"]' + - '[lang="' + navigator.language + '"]'); - if (!script) { - return false; - } - - var locale = this.ctx.getLocale(navigator.language); - // the inline localization is happenning very early, when the ctx is not - // yet ready and when the resources haven't been downloaded yet; add the - // inlined JSON directly to the current locale - locale.addAST(JSON.parse(script.innerHTML)); - // localize the visible DOM - var l10n = { - ctx: locale, - language: { - code: locale.id, - direction: getDirection(locale.id) - } - }; - translateFragment.call(l10n); - // the visible DOM is now pretranslated - isPretranslated = true; - return true; - } - - function initResources() { - var resLinks = document.head - .querySelectorAll('link[type="application/l10n"]'); - var iniLinks = []; - var i; - - for (i = 0; i < resLinks.length; i++) { - var link = resLinks[i]; - var url = link.getAttribute('href'); - var type = url.substr(url.lastIndexOf('.') + 1); - if (type === 'ini') { - iniLinks.push(url); - } - this.ctx.resLinks.push(url); - } - - var iniLoads = iniLinks.length; - if (iniLoads === 0) { - initLocale.call(this); - return; - } - - function onIniLoaded(err) { - if (err) { - this.ctx._emitter.emit('error', err); - } - if (--iniLoads === 0) { - initLocale.call(this); - } - } - - for (i = 0; i < iniLinks.length; i++) { - loadINI.call(this, iniLinks[i], onIniLoaded.bind(this)); - } - } - - function initLocale() { - this.ctx.requestLocales(navigator.language); - window.addEventListener('languagechange', function l10n_langchange() { - navigator.mozL10n.language.code = navigator.language; - }); - } - - function onReady() { - if (!isPretranslated) { - this.translate(); - } - isPretranslated = false; - - fireLocalizedEvent.call(this); - } - - function fireLocalizedEvent() { - var event = new CustomEvent('localized', { - 'bubbles': false, - 'cancelable': false, - 'detail': { - 'language': this.ctx.supportedLocales[0] - } - }); - window.dispatchEvent(event); - } - - /* jshint -W104 */ - - function loadINI(url, callback) { - var ctx = this.ctx; - io.load(url, function(err, source) { - var pos = ctx.resLinks.indexOf(url); - - if (err) { - // remove the ini link from resLinks - ctx.resLinks.splice(pos, 1); - return callback(err); - } - - if (!source) { - ctx.resLinks.splice(pos, 1); - return callback(new Error('Empty file: ' + url)); - } - - var patterns = parseINI(source, url).resources.map(function(x) { - return x.replace('en-US', '{{locale}}'); - }); - ctx.resLinks.splice.apply(ctx.resLinks, [pos, 1].concat(patterns)); - callback(); - }); - } - - function relativePath(baseUrl, url) { - if (url[0] === '/') { - return url; - } - - var dirs = baseUrl.split('/') - .slice(0, -1) - .concat(url.split('/')) - .filter(function(path) { - return path !== '.'; - }); - - return dirs.join('/'); - } - - var iniPatterns = { - 'section': /^\s*\[(.*)\]\s*$/, - 'import': /^\s*@import\s+url\((.*)\)\s*$/i, - 'entry': /[\r\n]+/ - }; - - function parseINI(source, iniPath) { - var entries = source.split(iniPatterns.entry); - var locales = ['en-US']; - var genericSection = true; - var uris = []; - var match; - - for (var i = 0; i < entries.length; i++) { - var line = entries[i]; - // we only care about en-US resources - if (genericSection && iniPatterns['import'].test(line)) { - match = iniPatterns['import'].exec(line); - var uri = relativePath(iniPath, match[1]); - uris.push(uri); - continue; - } - - // but we need the list of all locales in the ini, too - if (iniPatterns.section.test(line)) { - genericSection = false; - match = iniPatterns.section.exec(line); - locales.push(match[1]); - } - } - return { - locales: locales, - resources: uris - }; - } - - /* jshint -W104 */ - - function translateFragment(element) { - if (!element) { - element = document.documentElement; - document.documentElement.lang = this.language.code; - document.documentElement.dir = this.language.direction; - } - translateElement.call(this, element); - - var nodes = getTranslatableChildren(element); - for (var i = 0; i < nodes.length; i++ ) { - translateElement.call(this, nodes[i]); - } - } - - function getTranslatableChildren(element) { - return element ? element.querySelectorAll('*[data-l10n-id]') : []; - } - - function localizeElement(element, id, args) { - if (!element) { - return; - } - - if (!id) { - element.removeAttribute('data-l10n-id'); - element.removeAttribute('data-l10n-args'); - setTextContent(element, ''); - return; - } - - element.setAttribute('data-l10n-id', id); - if (args && typeof args === 'object') { - element.setAttribute('data-l10n-args', JSON.stringify(args)); - } else { - element.removeAttribute('data-l10n-args'); - } - - if (this.ctx.isReady) { - translateElement.call(this, element); - } - } - - function getL10nAttributes(element) { - if (!element) { - return {}; - } - - var l10nId = element.getAttribute('data-l10n-id'); - var l10nArgs = element.getAttribute('data-l10n-args'); - - var args = l10nArgs ? JSON.parse(l10nArgs) : null; - - return {id: l10nId, args: args}; - } - - - - function translateElement(element) { - var l10n = getL10nAttributes(element); - - if (!l10n.id) { - return; - } - - var entity = this.ctx.getEntity(l10n.id, l10n.args); - - if (!entity) { - return; - } - - if (typeof entity === 'string') { - setTextContent(element, entity); - return true; - } - - if (entity.value) { - setTextContent(element, entity.value); - } - - for (var key in entity.attributes) { - if (entity.attributes.hasOwnProperty(key)) { - var attr = entity.attributes[key]; - var pos = key.indexOf('.'); - if (pos !== -1) { - element[key.substr(0, pos)][key.substr(pos + 1)] = attr; - } else if (key === 'ariaLabel') { - element.setAttribute('aria-label', attr); - } else { - element[key] = attr; - } - } - } - - return true; - } - - function setTextContent(element, text) { - // standard case: no element children - if (!element.firstElementChild) { - element.textContent = text; - return; - } - - // this element has element children: replace the content of the first - // (non-blank) child textNode and clear other child textNodes - var found = false; - var reNotBlank = /\S/; - for (var child = element.firstChild; child; child = child.nextSibling) { - if (child.nodeType === Node.TEXT_NODE && - reNotBlank.test(child.nodeValue)) { - if (found) { - child.nodeValue = ''; - } else { - child.nodeValue = text; - found = true; - } - } - } - // if no (non-empty) textNode is found, insert a textNode before the - // element's first child. - if (!found) { - element.insertBefore(document.createTextNode(text), element.firstChild); - } - } - -})(this); - diff --git a/template/manifest.webapp b/template/manifest.webapp deleted file mode 100644 index 032e3bc..0000000 --- a/template/manifest.webapp +++ /dev/null @@ -1,29 +0,0 @@ -{ - "version": "0.1.0", - "name": "Hawk", - "description": "A template with the bare minimum structure", - "launch_path": "/index.html", - "icons": { - "16": "/img/icons/icon16x16.png", - "48": "/img/icons/icon48x48.png", - "60": "/img/icons/icon60x60.png", - "128": "/img/icons/icon128x128.png" - }, - "developer": { - "name": "Your name", - "url": "http://example.com" - }, - "type": "privileged", - "permissions": {}, - "installs_allowed_from": [ - "*" - ], - "locales": { - "es": { - "name": "Aplicación vacía privilegiada", - "description": "Una plantilla con la mínima estructura", - "permissions": {} - } - }, - "default_locale": "en" -} \ No newline at end of file