diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..8162560 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,54 @@ +module.exports = { + root: true, + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/eslint-recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:vue/vue3-recommended', + 'prettier', + ], + parserOptions: { + parser: '@typescript-eslint/parser', + }, + plugins: ['@typescript-eslint', 'prettier'], + rules: { + semi: ['error', 'never'], + '@typescript-eslint/no-unused-vars': 'off', + '@typescript-eslint/no-explicit-any': 'off', + 'no-useless-escape': 'warn', + '@typescript-eslint/no-import-type-side-effects': 'error', + '@typescript-eslint/consistent-type-imports': [ + 'error', + { fixStyle: 'inline-type-imports' }, + ], + '@typescript-eslint/ban-types': [ + 'error', + { + extendDefaults: true, + types: { + Function: false, + '{}': false, + }, + }, + ], + quotes: [ + 'error', + 'single', + { + allowTemplateLiterals: true, + avoidEscape: true, + }, + ], + 'max-len': [ + 'warn', + { + code: 85, + ignoreComments: true, + ignoreUrls: true, + ignoreStrings: true, + ignoreTemplateLiterals: true, + ignoreRegExpLiterals: true, + }, + ], + }, +} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b6f02c6 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,42 @@ +name: Release Obsidian plugin + +on: + push: + tags: + - '*' + +env: + PLUGIN_NAME: obsidian-teleprompter + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: '18.x' + + - name: Build plugin + id: build + run: | + npm install + npm run build + mkdir ${{ env.PLUGIN_NAME }} + cp dist/main.js dist/manifest.json dist/versions.json dist/styles.css ${{ env.PLUGIN_NAME }} + zip -r ${{ env.PLUGIN_NAME }}.zip ${{ env.PLUGIN_NAME }} + + - name: Create release + id: create_release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + tag="${GITHUB_REF#refs/tags/}" + + gh release create "$tag" \ + --title="$tag" \ + --draft \ + dist/main.js dist/manifest.json dist/styles.css ${{ env.PLUGIN_NAME }}.zip diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..adb156a --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +# Intellij +*.iml +.idea + +# npm +node_modules +pnpm-lock.yaml +package-lock.json +yarn.lock + +# build +main.js +*.js.map +styles.css + +dist diff --git a/.postcssrc.js b/.postcssrc.js new file mode 100644 index 0000000..02fa427 --- /dev/null +++ b/.postcssrc.js @@ -0,0 +1,5 @@ +module.exports = () => { + return { + plugins: [require('postcss-prefixwrap')(`.app-teleprompter`)], + } +} diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..85bdd12 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,8 @@ +{ + "semi": false, + "singleQuote": true, + "trailingComma": "all", + "singleAttributePerLine": true, + "eslintIntegration": true, + "tabWidth": 2 +} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..e6784d3 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,45 @@ +# Contributing to Obsidian Teleprompter +Thank you for considering contributing to Obsidian Teleprompter! + +## How Can I Contribute? + +There are several ways to contribute to this project: + +1. **Report Bugs**: If you encounter a bug or issue, please +[create a new issue](https://github.com/lumetrium/obsidian-teleprompter/issues/new). +Be sure to provide as much detail as possible, +including your environment and any steps to reproduce the issue. + +2. **Suggest Enhancements**: If you have an idea for an improvement or feature, +feel free to [start a discussion](https://github.com/lumetrium/obsidian-teleprompter/discussions/new/choose). +Please check for existing discussions to avoid duplication. + +3. **Submit Pull Requests**: If you would like to contribute code, +please fork this repository, create a new branch, make your changes, +and submit a pull request. Be sure to include a clear and concise description +of your changes. + +## Getting Started + +To get started with contributing, follow these steps: + +1. Fork the repository on GitHub. +2. Clone your forked repository to your local machine. +3. Create a new branch for your changes: `git checkout -b feature/your-feature-name`. +4. Make your changes and commit them with a descriptive commit message. +5. Push your changes to your fork on GitHub: `git push origin feature/your-feature-name`. +6. Open a pull request to the main repository. Please include a clear title and description of your changes. + +## Development + +1. Install the dependencies with `yarn install` +2. Start the development server with `yarn dev` +3. In your file manager, navigate to `/.obsidian/plugins/` +4. Create a symlink to the `obsidian-teleprompter/dist` folder +5. Open Obsidian and enable the plugin in the settings + +## Building + +```bash +yarn build +``` \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e72bfdd --- /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. + + + Copyright (C) + + 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: + + Copyright (C) + 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 +. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..5b2b5e1 --- /dev/null +++ b/README.md @@ -0,0 +1,106 @@ +

Obsidian Teleprompter

+ +

+ +

+ +

+An Obsidian plugin designed to seamlessly integrate
+teleprompter functionality into your note-taking workflow. +

+ +## About the plugin + +Open Teleprompter window and focus the note you want to read in Obsidian. +Teleprompter window will display the contents of the note in a large, +easy-to-read format. It will automatically scroll as you read, +allowing you to maintain a steady reading pace. + +## Features + +### Controls + +- **Play / Pause** - toggle auto-scroll +- **Pin Note** - preserve content when switching focus to other notes +- **Speed** - scroll speed +- **Font Size** - size of the text +- **Line Height** - space between lines +- **Letter Spacing** - space between letters +- **Font Family** - font used for the text +- **Padding** - space between the text and the edges of the window +- **Flip Horizontally** - flip the text horizontally +- **Flip Vertically** - flip the text vertically +- **Text Color** - color of the text +- **Background Color** - color of the background +- **View Mode** - choose between 2 different content display modes: "Markdown" or "Plain Text" +- **Open Settings** - a button that opens the plugin settings + +### Panels + +You can add as many panels as you want and customize their content, size, +position, and more. The available panels are: + +- **Control Panel**: Contains a list of controls that you can add, remove, and reorder. +- **Page Minimap**: Displays a minimap of the content for + easy navigation and better context awareness. + +### Hotkeys + +Use hotkeys for all possible actions within the Teleprompter window. +Every control provides multiple different hotkeys, so you can set up the one that +best suits your case. + +## Screenshots + +

+Teleprompter in a separate tab + + +Teleprompter in a separate window + + +Settings: Panels tab + + +

+ +
+ MORE SCREENSHOTS + +Settings: Controls tab + + +Settings: expanded Font Size control in the Controls tab + + +Settings: expanded Control Panel in the Panels tab in white theme (if you're into that) + + +Hotkeys + + +
+ +## Installation + +Only manual installation is supported at the moment. + +### Manual Installation + +1. Download the latest `zip` from the latest [Github Release](https://github.com/lumetrium/obsidian-teleprompter/releases) +2. Extract obsidian-teleprompter folder from the zip + to your vault's plugins folder `/.obsidian/plugins/` (Note: `.obsidian` folder may be hidden, you need to show it firstly) +3. Open Settings > community plugins, and reload and activate the plugin below installed plugins list + +For details see [the forums](https://forum.obsidian.md/t/plugins-mini-faq/7737). + +## Recommendations + +Also check out this browser extension made by the same author: + + + + + +**[Definer - Popup Dictionary & Translator](https://lumetrium.com/definer)** +Instant definitions, translations, and search results for words and phrases you select or type. diff --git a/assets/logos/definer.png b/assets/logos/definer.png new file mode 100644 index 0000000..e73966f Binary files /dev/null and b/assets/logos/definer.png differ diff --git a/assets/logos/lumetrium.png b/assets/logos/lumetrium.png new file mode 100644 index 0000000..68f0a3b Binary files /dev/null and b/assets/logos/lumetrium.png differ diff --git a/assets/logos/teleprompter.png b/assets/logos/teleprompter.png new file mode 100644 index 0000000..038588e Binary files /dev/null and b/assets/logos/teleprompter.png differ diff --git a/assets/screenshots/hotkeys.png b/assets/screenshots/hotkeys.png new file mode 100644 index 0000000..8b62911 Binary files /dev/null and b/assets/screenshots/hotkeys.png differ diff --git a/assets/screenshots/settings-controls-expanded.png b/assets/screenshots/settings-controls-expanded.png new file mode 100644 index 0000000..fff15c5 Binary files /dev/null and b/assets/screenshots/settings-controls-expanded.png differ diff --git a/assets/screenshots/settings-controls.png b/assets/screenshots/settings-controls.png new file mode 100644 index 0000000..cc63bfe Binary files /dev/null and b/assets/screenshots/settings-controls.png differ diff --git a/assets/screenshots/settings-panels-expanded-white.png b/assets/screenshots/settings-panels-expanded-white.png new file mode 100644 index 0000000..9d2b964 Binary files /dev/null and b/assets/screenshots/settings-panels-expanded-white.png differ diff --git a/assets/screenshots/settings-panels.png b/assets/screenshots/settings-panels.png new file mode 100644 index 0000000..62d0aeb Binary files /dev/null and b/assets/screenshots/settings-panels.png differ diff --git a/assets/screenshots/tab.png b/assets/screenshots/tab.png new file mode 100644 index 0000000..087e966 Binary files /dev/null and b/assets/screenshots/tab.png differ diff --git a/assets/screenshots/window.png b/assets/screenshots/window.png new file mode 100644 index 0000000..3f9ffb8 Binary files /dev/null and b/assets/screenshots/window.png differ diff --git a/package.json b/package.json new file mode 100644 index 0000000..71bebe3 --- /dev/null +++ b/package.json @@ -0,0 +1,44 @@ +{ + "name": "obsidian-teleprompter", + "version": "1.0.0", + "description": "Teleprompter plugin for Obsidian", + "main": "main.js", + "scripts": { + "dev": "vite build --watch", + "build": "vite build" + }, + "keywords": [ + "obsidian", + "teleprompter" + ], + "author": "Lumetirum ", + "license": "GPL-3.0-only", + "dependencies": { + "@mdi/js": "^7.2.96", + "@vueuse/core": "^10.2.1", + "lodash": "^4.17.21", + "nanoid": "^4.0.2", + "remove-markdown": "^0.5.0", + "vue": "^3.3.4", + "vue-draggable-plus": "0.2.4", + "vue-markdown-render": "^2.0.1", + "vuetify": "^3.3.5" + }, + "devDependencies": { + "@types/lodash": "^4.14.196", + "@typescript-eslint/eslint-plugin": "^6.0.0", + "@typescript-eslint/parser": "^6.0.0", + "@vitejs/plugin-vue": "^4.2.3", + "eslint": "^8.45.0", + "eslint-config-prettier": "^8.10.0", + "eslint-plugin-prettier": "^5.0.0", + "eslint-plugin-vue": "^9.15.1", + "obsidian": "^1.4.11", + "postcss-prefixwrap": "1.41.0", + "prettier": "^3.0.0", + "sass": "^1.63.6", + "typescript": "^5.1.6", + "vite": "^4.4.4", + "vite-plugin-vuetify": "^1.0.2" + } +} diff --git a/public/.hotreload b/public/.hotreload new file mode 100644 index 0000000..e69de29 diff --git a/public/manifest.json b/public/manifest.json new file mode 100644 index 0000000..bc6bbf0 --- /dev/null +++ b/public/manifest.json @@ -0,0 +1,10 @@ +{ + "id": "teleprompter", + "name": "Teleprompter", + "version": "1.0.0", + "minAppVersion": "1.2.8", + "description": "Teleprompter window for live presentations and video production.", + "author": "Lumetrium", + "authorUrl": "https://www.lumetrium.com", + "isDesktopOnly": false +} diff --git a/public/versions.json b/public/versions.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/public/versions.json @@ -0,0 +1 @@ +{} diff --git a/src/App.vue b/src/App.vue new file mode 100644 index 0000000..3ee8afb --- /dev/null +++ b/src/App.vue @@ -0,0 +1,28 @@ + + + + + + + diff --git a/src/SettingsApp.vue b/src/SettingsApp.vue new file mode 100644 index 0000000..ada7d1d --- /dev/null +++ b/src/SettingsApp.vue @@ -0,0 +1,23 @@ + + + + + \ No newline at end of file diff --git a/src/components/ConfirmationMenu.vue b/src/components/ConfirmationMenu.vue new file mode 100644 index 0000000..494139f --- /dev/null +++ b/src/components/ConfirmationMenu.vue @@ -0,0 +1,158 @@ + + + + + diff --git a/src/components/RangeInput.vue b/src/components/RangeInput.vue new file mode 100644 index 0000000..7ceec40 --- /dev/null +++ b/src/components/RangeInput.vue @@ -0,0 +1,67 @@ + + + + + diff --git a/src/components/SelectInput.vue b/src/components/SelectInput.vue new file mode 100644 index 0000000..56ec1e5 --- /dev/null +++ b/src/components/SelectInput.vue @@ -0,0 +1,61 @@ + + + diff --git a/src/components/accordion/Accordion.vue b/src/components/accordion/Accordion.vue new file mode 100644 index 0000000..e064e47 --- /dev/null +++ b/src/components/accordion/Accordion.vue @@ -0,0 +1,12 @@ + + + + + diff --git a/src/components/accordion/AccordionItem.vue b/src/components/accordion/AccordionItem.vue new file mode 100644 index 0000000..912aa07 --- /dev/null +++ b/src/components/accordion/AccordionItem.vue @@ -0,0 +1,146 @@ + + + + + \ No newline at end of file diff --git a/src/components/icons/DefinerLogo.vue b/src/components/icons/DefinerLogo.vue new file mode 100644 index 0000000..ff46f51 --- /dev/null +++ b/src/components/icons/DefinerLogo.vue @@ -0,0 +1,80 @@ + + + + + \ No newline at end of file diff --git a/src/components/icons/LumetriumLogo.vue b/src/components/icons/LumetriumLogo.vue new file mode 100644 index 0000000..1c8c437 --- /dev/null +++ b/src/components/icons/LumetriumLogo.vue @@ -0,0 +1,118 @@ + + + + + diff --git a/src/components/icons/TeleprompterLogo.vue b/src/components/icons/TeleprompterLogo.vue new file mode 100644 index 0000000..5646e9a --- /dev/null +++ b/src/components/icons/TeleprompterLogo.vue @@ -0,0 +1,65 @@ + + + + + diff --git a/src/constants.ts b/src/constants.ts new file mode 100644 index 0000000..0e8b07d --- /dev/null +++ b/src/constants.ts @@ -0,0 +1,15 @@ + +export const VIEW_TYPE = 'teleprompter' + +export const APP_ATTR = 'teleprompter' +export const APP_CLASS = 'app-teleprompter' + +export const VIEW_CLASS = 'app-teleprompter-view' +export const SETTINGS_CLASS = 'app-teleprompter-settings' + + +export const AUTHOR_NAME = 'Lumetrium' +export const AUTHOR_WEBSITE = 'www.lumetrium.com' + +export const APP_NAME = 'Teleprompter' +export const APP_WEBSITE = 'www.github.com/lumetrium/teleprompter' diff --git a/src/features/about/About.vue b/src/features/about/About.vue new file mode 100644 index 0000000..438f218 --- /dev/null +++ b/src/features/about/About.vue @@ -0,0 +1,32 @@ + + + + + diff --git a/src/features/about/AboutApp.vue b/src/features/about/AboutApp.vue new file mode 100644 index 0000000..7d58312 --- /dev/null +++ b/src/features/about/AboutApp.vue @@ -0,0 +1,41 @@ + + + + + diff --git a/src/features/about/AboutMessage.vue b/src/features/about/AboutMessage.vue new file mode 100644 index 0000000..249d23b --- /dev/null +++ b/src/features/about/AboutMessage.vue @@ -0,0 +1,13 @@ + diff --git a/src/features/about/AboutProject.vue b/src/features/about/AboutProject.vue new file mode 100644 index 0000000..09fe6dd --- /dev/null +++ b/src/features/about/AboutProject.vue @@ -0,0 +1,41 @@ + + + + + diff --git a/src/features/about/AboutRecommendations.vue b/src/features/about/AboutRecommendations.vue new file mode 100644 index 0000000..d94e8f3 --- /dev/null +++ b/src/features/about/AboutRecommendations.vue @@ -0,0 +1,47 @@ + + + + + diff --git a/src/features/about/index.ts b/src/features/about/index.ts new file mode 100644 index 0000000..6f9b6ff --- /dev/null +++ b/src/features/about/index.ts @@ -0,0 +1,20 @@ +import { defineFeature } from '@/features/feature' +import { useSettingsFeature } from '@/features/settings' +import { mdiInformation } from '@mdi/js' +import About from '@/features/about/About.vue' + +export const useAboutFeature = defineFeature('about', (id) => { + useSettingsFeature().use({ + id, + tab: { name: 'About', priority: 99999 }, + icon: mdiInformation, + defaults: { + name: 'About' + }, + components: { + layout: () => About, + }, + }) + + return {} +}) diff --git a/src/features/bg-color/BgColorIcon.vue b/src/features/bg-color/BgColorIcon.vue new file mode 100644 index 0000000..8d712f6 --- /dev/null +++ b/src/features/bg-color/BgColorIcon.vue @@ -0,0 +1,31 @@ + + + + + diff --git a/src/features/bg-color/index.ts b/src/features/bg-color/index.ts new file mode 100644 index 0000000..f8877fe --- /dev/null +++ b/src/features/bg-color/index.ts @@ -0,0 +1,45 @@ +import { defineFeature } from '@/features/feature' +import { computed, ref } from 'vue' +import { useControlFeature } from '@/features/control' +import { ControlType } from '@/features/control/enums' +import { useContentFeature } from '@/features/content' +import BgColorIcon from '@/features/bg-color/BgColorIcon.vue' + +export const useBgColorFeature = defineFeature('bg-color', (id) => { + const value = ref(null) + const label = 'Background Color' + const desc = 'Content\'s background color' + + useControlFeature().use({ + id, + type: ControlType.COLOR, + defaults: { + label, + desc, + value: null, + resetValue: null, + }, + state: { + value, + }, + components: { + icon: () => BgColorIcon, + }, + }) + + useContentFeature().useModifier({ + id, + defaults: { + name: label, + }, + styles: { + backgroundColor: computed(() => value.value ?? 'var(--color-base-00)'), + }, + }) + + return { + useStore: () => ({ + value, + }), + } +}) diff --git a/src/features/commands/index.ts b/src/features/commands/index.ts new file mode 100644 index 0000000..3791245 --- /dev/null +++ b/src/features/commands/index.ts @@ -0,0 +1,21 @@ +import { defineFeature } from '@/features/feature' +import { computed } from 'vue' +import { usePluggable } from '@/hooks/usePluggable/usePluggable' +import type { CommandsOptions, CommandsState } from '@/features/commands/types' +import { flatten } from 'lodash' + +export const useCommandFeature = defineFeature('command', (id) => { + const { use, pluginsList } = usePluggable() + + const list = computed(() => + flatten(pluginsList.value.map((group) => group.state.list)), + ) + + return { + use, + useStore: () => ({ + list, + }), + persist: false, + } +}) diff --git a/src/features/commands/types.ts b/src/features/commands/types.ts new file mode 100644 index 0000000..1a6f02e --- /dev/null +++ b/src/features/commands/types.ts @@ -0,0 +1,16 @@ +import type { Pluggable, PluggableOptions } from '@/hooks/usePluggable/types' +import type { Command as ObsidianCommand } from 'obsidian' + +export type Command = ObsidianCommand + +export interface CommandsState { + list: Command[] + isDisabled?: boolean +} + +export interface CommandsOptions extends PluggableOptions {} + +export type PluggableCommands = Pluggable< + CommandsState, + CommandsOptions +> diff --git a/src/features/content-md/ContentMd.vue b/src/features/content-md/ContentMd.vue new file mode 100644 index 0000000..8a3bb03 --- /dev/null +++ b/src/features/content-md/ContentMd.vue @@ -0,0 +1,14 @@ + + + \ No newline at end of file diff --git a/src/features/content-md/index.ts b/src/features/content-md/index.ts new file mode 100644 index 0000000..b70cde2 --- /dev/null +++ b/src/features/content-md/index.ts @@ -0,0 +1,19 @@ +import { useContentFeature } from '@/features/content' +import ContentMd from '@/features/content-md/ContentMd.vue' +import { defineFeature } from '@/features/feature' +import { mdiLanguageMarkdown } from '@mdi/js' + +export const useContentMdFeature = defineFeature('content-md', (id) => { + useContentFeature().useView({ + id, + icon: mdiLanguageMarkdown, + defaults: { + name: 'Markdown', + }, + components: { + content: () => ContentMd, + }, + }) + + return {} +}) diff --git a/src/features/content-plain/ContentPlain.vue b/src/features/content-plain/ContentPlain.vue new file mode 100644 index 0000000..4de59a1 --- /dev/null +++ b/src/features/content-plain/ContentPlain.vue @@ -0,0 +1,16 @@ + + + diff --git a/src/features/content-plain/index.ts b/src/features/content-plain/index.ts new file mode 100644 index 0000000..3e79271 --- /dev/null +++ b/src/features/content-plain/index.ts @@ -0,0 +1,19 @@ +import ContentPlain from '@/features/content-plain/ContentPlain.vue' +import { defineFeature } from '@/features/feature' +import { useContentFeature } from '@/features/content' +import { mdiFormatTextVariant } from '@mdi/js' + +export const useContentPlainFeature = defineFeature('content-plain', (id) => { + useContentFeature().useView({ + id, + icon: mdiFormatTextVariant, + defaults: { + name: 'Plain text', + }, + components: { + content: () => ContentPlain, + }, + }) + + return {} +}) diff --git a/src/features/content/Content.vue b/src/features/content/Content.vue new file mode 100644 index 0000000..ff519e8 --- /dev/null +++ b/src/features/content/Content.vue @@ -0,0 +1,92 @@ + + + + + \ No newline at end of file diff --git a/src/features/content/ContentScroller.vue b/src/features/content/ContentScroller.vue new file mode 100644 index 0000000..61e5e7d --- /dev/null +++ b/src/features/content/ContentScroller.vue @@ -0,0 +1,66 @@ + + + + + diff --git a/src/features/content/ContentView.vue b/src/features/content/ContentView.vue new file mode 100644 index 0000000..3b10383 --- /dev/null +++ b/src/features/content/ContentView.vue @@ -0,0 +1,25 @@ + + + + + diff --git a/src/features/content/hooks/useContentCommands.ts b/src/features/content/hooks/useContentCommands.ts new file mode 100644 index 0000000..951bf61 --- /dev/null +++ b/src/features/content/hooks/useContentCommands.ts @@ -0,0 +1,42 @@ +import { computed } from 'vue' +import { flatten } from 'lodash' +import type { Command } from '@/features/commands/types' +import { useContentFeature } from '@/features/content' + +export function useContentCommands() { + const commands = computed(() => getCommands()) + + function getCommands(): Command[] { + return flatten([...getScrollCommands()]) + } + + function getScrollCommands(): Command[] { + const store = useContentFeature().useStore() + return [ + { + id: 'content:scroll-up', + name: 'Scroll up', + callback: () => store.requestToScrollBy(-50), + }, + { + id: 'content:scroll-down', + name: 'Scroll down', + callback: () => store.requestToScrollBy(50), + }, + { + id: 'content:scroll-to-top', + name: 'Scroll to top', + callback: () => store.requestToScrollBy(-store.contentScrollHeight), + }, + { + id: 'content:scroll-to-bottom', + name: 'Scroll to bottom', + callback: () => store.requestToScrollBy(store.contentScrollHeight), + }, + ] + } + + return { + commands, + } +} diff --git a/src/features/content/hooks/useContentDimensionsObserver.ts b/src/features/content/hooks/useContentDimensionsObserver.ts new file mode 100644 index 0000000..602e2aa --- /dev/null +++ b/src/features/content/hooks/useContentDimensionsObserver.ts @@ -0,0 +1,45 @@ +import { + type MaybeElementRef, + useMutationObserver, + useResizeObserver, + useScroll, +} from '@vueuse/core' +import { debounce } from 'obsidian' +import { toRefs, unref, watch } from 'vue' +import { useContentFeature } from '@/features/content' + +export function useContentDimensionsObserver( + element: MaybeElementRef, +) { + const store = useContentFeature().useStore() + function persistDimensions() { + const target = unref(element) + if (!target) return + store.contentScrollTop = target.scrollTop + store.contentScrollHeight = target.scrollHeight + store.contentHeight = target.clientHeight + + // can't use target.clientWidth here because it's rounding the value + // https://developer.mozilla.org/en-US/docs/Web/API/Element/clientWidth + store.contentWidth = target.firstElementChild?.getBoundingClientRect().width + } + + const persistDimensionsDebounced = debounce(persistDimensions, 10, true) + + useMutationObserver(element, (entries) => persistDimensionsDebounced(), { + attributes: true, + }) + useResizeObserver(element, (entries) => persistDimensionsDebounced()) + useScroll(element, { onScroll: persistDimensions }) + + watch( + () => store.scrollBy, + ({ deltaY }) => { + unref(element)?.scrollBy({ + top: deltaY, + left: 0, + behavior: 'instant', + }) + }, + ) +} diff --git a/src/features/content/hooks/useContentScrolller.ts b/src/features/content/hooks/useContentScrolller.ts new file mode 100644 index 0000000..19dd72f --- /dev/null +++ b/src/features/content/hooks/useContentScrolller.ts @@ -0,0 +1,41 @@ +import { + computed, + type MaybeRef, + onBeforeUnmount, + onMounted, + ref, + unref, + watch, +} from 'vue' +import type { MaybeElementRef } from '@vueuse/core' + +export function useContentScroller(options: { + element: MaybeElementRef + speed: MaybeRef + isPlaying: MaybeRef +}) { + const speed = computed(() => unref(options.speed) * 5) + const scrollDelay = computed(() => + 100 - speed.value > 0 ? 100 - speed.value : 0, + ) + const scrollStep = computed( + () => 1 + (!scrollDelay.value ? speed.value / 100 : 0), + ) + const timeout = ref() + + onMounted(() => scroll()) + onBeforeUnmount(() => clearTimeout(timeout.value)) + + function scroll() { + if (!unref(options.isPlaying) || !unref(options.element)) return + requestAnimationFrame(() => { + if (unref(options.speed)) { + unref(options.element)?.scrollBy(0, scrollStep.value) + } + if (timeout.value) clearTimeout(timeout.value) + timeout.value = setTimeout(scroll, scrollDelay.value) + }) + } + + watch(() => unref(options.isPlaying), scroll) +} diff --git a/src/features/content/index.ts b/src/features/content/index.ts new file mode 100644 index 0000000..2a470da --- /dev/null +++ b/src/features/content/index.ts @@ -0,0 +1,99 @@ +import type { + ContentModifierOptions, + ContentModifierState, + ContentViewState, +} from '@/features/content/types' +import { ControlType } from '@/features/control/enums' +import { defineFeature } from '@/features/feature' +import { usePluggable } from '@/hooks/usePluggable/usePluggable' +import { mdiTextBox } from '@mdi/js' +import { computed, readonly, ref } from 'vue' +import { useControlFeature } from '../control' +import { useCommandFeature } from '@/features/commands' +import { useContentCommands } from '@/features/content/hooks/useContentCommands' +import { watchOnce } from '@vueuse/core' + +export const useContentFeature = defineFeature('content', (id) => { + const { use: useView, plugins: views } = usePluggable() + const { + use: useModifier, + plugins: modifiers, + pluginsList: modifiersList, + } = usePluggable() + + const content = ref(null) + const contentWidth = ref(null) + const contentHeight = ref(null) + const contentScrollTop = ref(0) + const contentScrollHeight = ref(0) + const scrollBy = ref<{ deltaY: number }>({ deltaY: 0 }) + const activeViewId = ref() + const resetViewId = ref() + + const viewItems = computed(() => + Object.values(views.value).map((view) => ({ + id: view.id, + label: view.state?.name, + icon: view.icon, + value: view, + })), + ) + + watchOnce(viewItems, (items) => { + if (!resetViewId.value) resetViewId.value = items[0].id + if (!activeViewId.value) activeViewId.value = resetViewId.value + + useControlFeature().use({ + id, + type: ControlType.SELECT, + icon: mdiTextBox, + defaults: { + label: 'View mode', + desc: 'Content display mode', + value: computed(() => viewItems.value[0].id), + resetValue: computed(() => viewItems.value[0].id), + items: viewItems, + }, + state: { + value: computed({ + get: () => activeViewId.value ?? viewItems.value[0]?.id, + set: (value) => (activeViewId.value = value), + }), + resetValue: resetViewId.value, + items: viewItems, + }, + }) + }) + + useCommandFeature().use({ + id, + defaults: { + list: [], + }, + state: { + list: useContentCommands().commands, + }, + }) + + return { + useView, + useModifier, + persist: false, + useStore: () => ({ + views: readonly(views), + modifiers: readonly(modifiers), + modifiersList: readonly(modifiersList), + + activeViewId, + content, + contentWidth, + contentHeight, + contentScrollTop, + contentScrollHeight, + scrollBy, + requestToScrollBy(deltaY: number) { + scrollBy.value = { deltaY } + }, + }), + } +}) diff --git a/src/features/content/store/content.store.ts b/src/features/content/store/content.store.ts new file mode 100644 index 0000000..172fe40 --- /dev/null +++ b/src/features/content/store/content.store.ts @@ -0,0 +1,20 @@ +import { useContentFeature } from '@/features/content' +import { PluggableControl } from '@/features/control/types' +import { createInjectionState } from '@/utils/createInjectionState' +import {computed, reactive, ref, UnwrapNestedRefs} from 'vue' +import { toRefs } from 'vue' + +const [useProvideContentStore, useDefaultContentStore] = createInjectionState( + () => { + const store = toRefs(useContentFeature().useStore()) + return reactive({ + ...store, + }) + }, +) + +function useContentStore() { + return useDefaultContentStore() +} + +export { useProvideContentStore, useContentStore } diff --git a/src/features/content/types.ts b/src/features/content/types.ts new file mode 100644 index 0000000..513bb80 --- /dev/null +++ b/src/features/content/types.ts @@ -0,0 +1,26 @@ +import type { PluggableMap } from '@/hooks/usePluggable/types' + +export interface ContentViewState { + name: string + index?: number + data?: T +} + +export interface ContentModifierState { + name: string + index?: number +} + +export interface ContentModifierOptions { + id: string + defaults: ContentModifierState + state: ContentViewState + styles?: object + classes?: string[] + contentStyles?: object +} + +export type PluggableContentModifier = PluggableMap< + ContentModifierState, + ContentModifierOptions +> diff --git a/src/features/control/elements/ControlButton.vue b/src/features/control/elements/ControlButton.vue new file mode 100644 index 0000000..ca91467 --- /dev/null +++ b/src/features/control/elements/ControlButton.vue @@ -0,0 +1,67 @@ + + + + + diff --git a/src/features/control/elements/ControlIcon.vue b/src/features/control/elements/ControlIcon.vue new file mode 100644 index 0000000..2c70a28 --- /dev/null +++ b/src/features/control/elements/ControlIcon.vue @@ -0,0 +1,49 @@ + + + \ No newline at end of file diff --git a/src/features/control/elements/ControlLabel.vue b/src/features/control/elements/ControlLabel.vue new file mode 100644 index 0000000..cbf9c9b --- /dev/null +++ b/src/features/control/elements/ControlLabel.vue @@ -0,0 +1,40 @@ + + + + + \ No newline at end of file diff --git a/src/features/control/elements/ControlMenu.vue b/src/features/control/elements/ControlMenu.vue new file mode 100644 index 0000000..1f0a63e --- /dev/null +++ b/src/features/control/elements/ControlMenu.vue @@ -0,0 +1,85 @@ + + + + + diff --git a/src/features/control/enums.ts b/src/features/control/enums.ts new file mode 100644 index 0000000..7c6b73e --- /dev/null +++ b/src/features/control/enums.ts @@ -0,0 +1,11 @@ +export const ControlType = { + NUMBER: 'number', + SLIDER: 'slider', + SELECT: 'select', + TOGGLE: 'toggle', + TEXT: 'text', + DIALOG: 'dialog', + ACTION: 'action', + COLOR: 'color', + MULTI_SLIDER: 'multi-slider', +} as const diff --git a/src/features/control/hooks/useControlCommands.ts b/src/features/control/hooks/useControlCommands.ts new file mode 100644 index 0000000..d53b210 --- /dev/null +++ b/src/features/control/hooks/useControlCommands.ts @@ -0,0 +1,171 @@ +import { computed, type Ref, unref } from 'vue' +import type { ControlTypeType, PluggableControl } from '@/features/control/types' +import { ControlType } from '@/features/control/enums' +import { flatten } from 'lodash' +import type { Command } from '@/features/commands/types' + +export function useControlCommands(controls: Ref) { + const commands = computed(() => + flatten(controls.value.map((control) => getCommandsForControl(control))), + ) + + function getCommandsForControl(control: PluggableControl): Command[] { + if (getIsType(control, ControlType.SLIDER)) { + return getControlSliderCommands(control) + } + + if (getIsType(control, ControlType.MULTI_SLIDER)) { + return getControlMultiSliderCommands(control) + } + + if (getIsType(control, ControlType.TOGGLE)) { + return getControlToggleCommands(control) + } + + if (getIsType(control, ControlType.SELECT)) { + return getControlSelectCommands(control) + } + + if (getIsType(control, ControlType.ACTION)) { + return getControlActionCommands(control) + } + + return getControlDefaultCommands(control) + } + + return { + commands, + } +} + +function getIsType( + control: PluggableControl, + type: T, +): control is PluggableControl { + return control.type === type +} + +function getLabel(control: PluggableControl) { + const label = control.state.label + const defaultLabel = control.defaults.label + return label && label !== defaultLabel + ? `${control.defaults.label} (${label})` + : defaultLabel +} + +export function getControlSliderCommands( + control: PluggableControl, +): Command[] { + return [ + { + id: `control:${control.id}:up`, + name: `${getLabel(control)} Up`, + callback: () => (control.state.value += control.state.step), + }, + { + id: `control:${control.id}:down`, + name: `${getLabel(control)} Down`, + callback: () => (control.state.value -= control.state.step), + }, + { + id: `control:${control.id}:reset`, + name: `${getLabel(control)} Reset`, + callback: () => (control.state.value = control.state.resetValue), + }, + ] +} + +export function getControlMultiSliderCommands( + control: PluggableControl, +): Command[] { + function getMultiSliderItemLabel(i: number) { + const label = control.state.labels[i] + const defaultLabel = control.defaults.labels[i] + return label && label !== defaultLabel + ? `${defaultLabel} (${label})` + : defaultLabel + } + + return flatten( + control.state.value.map((item, i) => [ + { + id: `control:${control.id}:${i}:up`, + name: `${getLabel(control)} ${getMultiSliderItemLabel(i)} Up`, + callback: () => (control.state.value[i] += control.state.step[i]), + }, + { + id: `control:${control.id}:${i}:down`, + name: `${getLabel(control)} ${getMultiSliderItemLabel(i)} Down`, + callback: () => (control.state.value[i] -= control.state.step[i]), + }, + { + id: `control:${control.id}:${i}:reset`, + name: `${getLabel(control)} ${getMultiSliderItemLabel(i)} Reset`, + callback: () => (control.state.value[i] = control.state.resetValue[i]), + }, + ]), + ) +} + +export function getControlToggleCommands( + control: PluggableControl, +): Command[] { + return [ + { + id: `control:${control.id}:true`, + name: `${getLabel(control)} On`, + callback: () => (control.state.value = true), + }, + { + id: `control:${control.id}:false`, + name: `${getLabel(control)} Off`, + callback: () => (control.state.value = false), + }, + { + id: `control:${control.id}:toggle`, + name: `${getLabel(control)} Toggle`, + callback: () => (control.state.value = !control.state.value), + }, + { + id: `control:${control.id}:reset`, + name: `${getLabel(control)} Reset`, + callback: () => (control.state.value = control.state.resetValue), + }, + ] +} + +export function getControlActionCommands( + control: PluggableControl, +): Command[] { + return [ + { + id: `control:${control.id}:trigger`, + name: getLabel(control), + callback: () => (control.state.value = new Date().getTime()), + }, + ] +} + +export function getControlSelectCommands( + control: PluggableControl, +): Command[] { + return [ + { + id: `control:${control.id}:reset`, + name: `${getLabel(control)} Reset`, + callback: () => (control.state.value = control.state.resetValue), + }, + ] +} + +export function getControlDefaultCommands( + control: PluggableControl, +): Command[] { + return [ + { + id: `control:${control.id}:reset`, + name: `${getLabel(control)} Reset`, + callback: () => (control.state.value = control.state.resetValue), + }, + ] +} diff --git a/src/features/control/hooks/useControlComponents.ts b/src/features/control/hooks/useControlComponents.ts new file mode 100644 index 0000000..1f16e13 --- /dev/null +++ b/src/features/control/hooks/useControlComponents.ts @@ -0,0 +1,117 @@ +import { ControlType } from '@/features/control/enums' +import ControlSliderView from '@/features/control/views/ControlSliderView.vue' +import ControlSelectView from '@/features/control/views/ControlSelectView.vue' +import ControlTextView from '@/features/control/views/ControlTextView.vue' +import ControlColorView from '@/features/control/views/ControlColorView.vue' +import type { Ref } from 'vue' +import type { PluggableControl } from '@/features/control/types' +import ControlPanelMenuCompactView from '@/features/control/panel/compact/ControlPanelMenuCompactView.vue' +import ControlPanelSelectCompactView from '@/features/control/panel/compact/ControlPanelSelectCompactView.vue' +import ControlPanelToggleCompactView from '@/features/control/panel/compact/ControlPanelToggleCompactView.vue' +import ControlPanelDialogCompactView from '@/features/control/panel/compact/ControlPanelDialogCompactView.vue' +import ControlPanelDefaultCompactView from '@/features/control/panel/compact/ControlPanelDefaultCompactView.vue' +import ControlPanelDefaultView from '@/features/control/panel/normal/ControlPanelDefaultView.vue' +import ControlNumberSettings from '@/features/control/settings/ControlNumberSettings.vue' +import ControlSelectSettings from '@/features/control/settings/ControlSelectSettings.vue' +import ControlMultiSliderView from '@/features/control/views/ControlMultiSliderView.vue' +import ControlPanelToggleView + from '@/features/control/panel/normal/ControlPanelToggleView.vue' +import ControlPanelSelectView + from '@/features/control/panel/normal/ControlPanelSelectView.vue' +import ControlToggleSettings + from '@/features/control/settings/ControlToggleSettings.vue' +import ControlNumbersSettings from '@/features/control/settings/ControlNumbersSettings.vue' +import ControlPanelColorView + from '@/features/control/panel/normal/ControlPanelColorView.vue' +import ControlPanelMultiSliderView + from '@/features/control/panel/normal/ControlPanelMultiSliderView.vue' +import ControlPanelActionView + from '@/features/control/panel/normal/ControlPanelActionView.vue' + +export function useControlComponents(control: Ref) { + function getControlView() { + const customView = control.value.components.content?.() + if (customView) return customView + switch (control.value.type) { + case ControlType.SLIDER: + return ControlSliderView + case ControlType.SELECT: + return ControlSelectView + case ControlType.TEXT: + return ControlTextView + case ControlType.COLOR: + return ControlColorView + case ControlType.MULTI_SLIDER: + return ControlMultiSliderView + default: + return undefined + } + } + + function getPanelView() { + switch (control.value.type) { + case ControlType.ACTION: + return ControlPanelActionView + case ControlType.SELECT: + return ControlPanelSelectView + case ControlType.TOGGLE: + return ControlPanelToggleView + case ControlType.COLOR: + return ControlPanelColorView + case ControlType.MULTI_SLIDER: + return ControlPanelMultiSliderView + default: + return ControlPanelDefaultView + } + } + + function getPanelCompactView() { + switch (control.value.type) { + case ControlType.SLIDER: + return ControlPanelMenuCompactView + case ControlType.SELECT: + return ControlPanelSelectCompactView + case ControlType.TOGGLE: + return ControlPanelToggleCompactView + case ControlType.TEXT: + return ControlPanelMenuCompactView + case ControlType.COLOR: + return ControlPanelMenuCompactView + case ControlType.DIALOG: + return ControlPanelDialogCompactView + case ControlType.MULTI_SLIDER: + return ControlPanelMenuCompactView + default: + return ControlPanelDefaultCompactView + } + } + + function getSettingsView() { + const customView = control.value.components.settings?.() + if (customView) return customView + switch (control.value.type) { + case ControlType.NUMBER: + case ControlType.SLIDER: + return ControlNumberSettings + case ControlType.MULTI_SLIDER: + return ControlNumbersSettings + case ControlType.SELECT: + return ControlSelectSettings + case ControlType.TOGGLE: + return ControlToggleSettings + case ControlType.TEXT: + return ControlTextView + case ControlType.COLOR: + return ControlColorView + default: + return undefined + } + } + + return { + getControlView, + getPanelView, + getPanelCompactView, + getSettingsView, + } +} diff --git a/src/features/control/index.ts b/src/features/control/index.ts new file mode 100644 index 0000000..25ac1e1 --- /dev/null +++ b/src/features/control/index.ts @@ -0,0 +1,119 @@ +import ControlPanel from '@/features/control/panel/ControlPanel.vue' +import ControlPanelSettings from '@/features/control/settings/ControlPanelSettings.vue' +import type { + ControlOptions, + ControlStateType, + ControlTypeType, +} from '@/features/control/types' +import { defineFeature } from '@/features/feature' +import { usePanelFeature } from '@/features/panel' +import { PanelLocation } from '@/features/panel/constants' +import { useSettingsFeature } from '@/features/settings' +import type { PluggableMap, PluggableSetup } from '@/hooks/usePluggable/types' +import { usePluggable } from '@/hooks/usePluggable/usePluggable' +import { mdiTuneVariant } from '@mdi/js' +import { computed } from 'vue' +import cloneDeep from 'lodash/cloneDeep' +import ControlSettings from '@/features/control/settings/ControlSettings.vue' +import ControlIcon from '@/features/control/elements/ControlIcon.vue' +import { useCommandFeature } from '@/features/commands' +import { useControlCommands } from '@/features/control/hooks/useControlCommands' + +export const useControlFeature = defineFeature('control', (id) => { + const { + use, + plugins, + pluginsList, + getDiffsDeep, + extendPluginsState, + applyDefaults, + } = usePluggable() + + const pluginsWithStateAsDefaults = computed< + PluggableMap + >(() => + Object.values(plugins.value).reduce((acc, plugin) => { + acc[plugin.id] = { + ...plugin, + defaults: cloneDeep(plugin.state), + state: plugin.state, + } + return acc + }, {} as any), + ) + + + usePanelFeature().use({ + id, + plugins: pluginsWithStateAsDefaults, + defaults: { + name: 'Control Panel', + location: PanelLocation.TOP, + height: 48, + minHeight: 48, + width: 200, + minWidth: 48, + isOpen: true, + icon: mdiTuneVariant, + items: [], + }, + components: { + content: () => ControlPanel, + settings: () => ControlPanelSettings, + }, + }) + + useSettingsFeature().use({ + id, + tab: 'Controls', + icon: mdiTuneVariant, + defaults: { + name: 'Controls', + items: computed(() => + Object.values(plugins.value) + .sort((a, b) => a.defaults.label > b.defaults.label ? 1 : -1) + .map((plugin) => ({ + id: plugin.id, + name: plugin.defaults.label, + icon: plugin.icon, + state: plugin.state, + defaults: plugin.defaults, + components: { + icon: () => ControlIcon, + content: () => ControlSettings, + }, + } + )), + ), + }, + restoreDefaults: () => applyDefaults(plugins), + }) + + useCommandFeature().use({ + id, + defaults: { + list: [], + }, + state: { + list: useControlCommands(pluginsList).commands, + }, + }) + + return { + use: ( + plugin: PluggableSetup, ControlOptions>, + ) => { + use(plugin) + }, + useStore: () => ({ + plugins, + pluginsList, + }), + persist: { + reduce: (state) => getDiffsDeep({ plugins }), + merge: (state, savedState) => ({ + plugins: extendPluginsState(plugins, savedState?.plugins), + }), + }, + } +}) diff --git a/src/features/control/panel/ControlPanel.vue b/src/features/control/panel/ControlPanel.vue new file mode 100644 index 0000000..0ac67ff --- /dev/null +++ b/src/features/control/panel/ControlPanel.vue @@ -0,0 +1,42 @@ + + + + + diff --git a/src/features/control/panel/ControlPanelView.vue b/src/features/control/panel/ControlPanelView.vue new file mode 100644 index 0000000..da3a259 --- /dev/null +++ b/src/features/control/panel/ControlPanelView.vue @@ -0,0 +1,138 @@ + + + + + diff --git a/src/features/control/panel/compact/ControlPanelDefaultCompactView.vue b/src/features/control/panel/compact/ControlPanelDefaultCompactView.vue new file mode 100644 index 0000000..f7ab074 --- /dev/null +++ b/src/features/control/panel/compact/ControlPanelDefaultCompactView.vue @@ -0,0 +1,18 @@ + + + \ No newline at end of file diff --git a/src/features/control/panel/compact/ControlPanelDialogCompactView.vue b/src/features/control/panel/compact/ControlPanelDialogCompactView.vue new file mode 100644 index 0000000..df6b2c0 --- /dev/null +++ b/src/features/control/panel/compact/ControlPanelDialogCompactView.vue @@ -0,0 +1,25 @@ + + + diff --git a/src/features/control/panel/compact/ControlPanelMenuCompactView.vue b/src/features/control/panel/compact/ControlPanelMenuCompactView.vue new file mode 100644 index 0000000..863f48f --- /dev/null +++ b/src/features/control/panel/compact/ControlPanelMenuCompactView.vue @@ -0,0 +1,25 @@ + + + diff --git a/src/features/control/panel/compact/ControlPanelSelectCompactView.vue b/src/features/control/panel/compact/ControlPanelSelectCompactView.vue new file mode 100644 index 0000000..6bd9174 --- /dev/null +++ b/src/features/control/panel/compact/ControlPanelSelectCompactView.vue @@ -0,0 +1,34 @@ + + + diff --git a/src/features/control/panel/compact/ControlPanelToggleCompactView.vue b/src/features/control/panel/compact/ControlPanelToggleCompactView.vue new file mode 100644 index 0000000..9f68b02 --- /dev/null +++ b/src/features/control/panel/compact/ControlPanelToggleCompactView.vue @@ -0,0 +1,17 @@ + + + diff --git a/src/features/control/panel/normal/ControlPanelActionView.vue b/src/features/control/panel/normal/ControlPanelActionView.vue new file mode 100644 index 0000000..06723fc --- /dev/null +++ b/src/features/control/panel/normal/ControlPanelActionView.vue @@ -0,0 +1,15 @@ + + + \ No newline at end of file diff --git a/src/features/control/panel/normal/ControlPanelColorView.vue b/src/features/control/panel/normal/ControlPanelColorView.vue new file mode 100644 index 0000000..c9f1fa0 --- /dev/null +++ b/src/features/control/panel/normal/ControlPanelColorView.vue @@ -0,0 +1,24 @@ + + + diff --git a/src/features/control/panel/normal/ControlPanelDefaultView.vue b/src/features/control/panel/normal/ControlPanelDefaultView.vue new file mode 100644 index 0000000..37d9864 --- /dev/null +++ b/src/features/control/panel/normal/ControlPanelDefaultView.vue @@ -0,0 +1,19 @@ + + + \ No newline at end of file diff --git a/src/features/control/panel/normal/ControlPanelExpandView.vue b/src/features/control/panel/normal/ControlPanelExpandView.vue new file mode 100644 index 0000000..b7a355a --- /dev/null +++ b/src/features/control/panel/normal/ControlPanelExpandView.vue @@ -0,0 +1,37 @@ + + + + + diff --git a/src/features/control/panel/normal/ControlPanelMenuView.vue b/src/features/control/panel/normal/ControlPanelMenuView.vue new file mode 100644 index 0000000..be3eb4f --- /dev/null +++ b/src/features/control/panel/normal/ControlPanelMenuView.vue @@ -0,0 +1,42 @@ + + + diff --git a/src/features/control/panel/normal/ControlPanelMultiSliderView.vue b/src/features/control/panel/normal/ControlPanelMultiSliderView.vue new file mode 100644 index 0000000..193c108 --- /dev/null +++ b/src/features/control/panel/normal/ControlPanelMultiSliderView.vue @@ -0,0 +1,19 @@ + + + diff --git a/src/features/control/panel/normal/ControlPanelSelectView.vue b/src/features/control/panel/normal/ControlPanelSelectView.vue new file mode 100644 index 0000000..0a02288 --- /dev/null +++ b/src/features/control/panel/normal/ControlPanelSelectView.vue @@ -0,0 +1,40 @@ + + + diff --git a/src/features/control/panel/normal/ControlPanelToggleView.vue b/src/features/control/panel/normal/ControlPanelToggleView.vue new file mode 100644 index 0000000..0016544 --- /dev/null +++ b/src/features/control/panel/normal/ControlPanelToggleView.vue @@ -0,0 +1,20 @@ + + + \ No newline at end of file diff --git a/src/features/control/settings/ControlNumberSettings.vue b/src/features/control/settings/ControlNumberSettings.vue new file mode 100644 index 0000000..cbaf343 --- /dev/null +++ b/src/features/control/settings/ControlNumberSettings.vue @@ -0,0 +1,46 @@ + + + diff --git a/src/features/control/settings/ControlNumbersSettings.vue b/src/features/control/settings/ControlNumbersSettings.vue new file mode 100644 index 0000000..f58c1c2 --- /dev/null +++ b/src/features/control/settings/ControlNumbersSettings.vue @@ -0,0 +1,70 @@ + + + diff --git a/src/features/control/settings/ControlPanelSettings.vue b/src/features/control/settings/ControlPanelSettings.vue new file mode 100644 index 0000000..a98066a --- /dev/null +++ b/src/features/control/settings/ControlPanelSettings.vue @@ -0,0 +1,28 @@ + + + \ No newline at end of file diff --git a/src/features/control/settings/ControlSelectSettings.vue b/src/features/control/settings/ControlSelectSettings.vue new file mode 100644 index 0000000..d6876ce --- /dev/null +++ b/src/features/control/settings/ControlSelectSettings.vue @@ -0,0 +1,40 @@ + + + \ No newline at end of file diff --git a/src/features/control/settings/ControlSettings.vue b/src/features/control/settings/ControlSettings.vue new file mode 100644 index 0000000..3d6d013 --- /dev/null +++ b/src/features/control/settings/ControlSettings.vue @@ -0,0 +1,34 @@ + + + diff --git a/src/features/control/settings/ControlTextSettings.vue b/src/features/control/settings/ControlTextSettings.vue new file mode 100644 index 0000000..32a4a61 --- /dev/null +++ b/src/features/control/settings/ControlTextSettings.vue @@ -0,0 +1,11 @@ + + + + + diff --git a/src/features/control/settings/ControlToggleSettings.vue b/src/features/control/settings/ControlToggleSettings.vue new file mode 100644 index 0000000..648e0be --- /dev/null +++ b/src/features/control/settings/ControlToggleSettings.vue @@ -0,0 +1,35 @@ + + + diff --git a/src/features/control/settings/list/ControlListAddMenu.vue b/src/features/control/settings/list/ControlListAddMenu.vue new file mode 100644 index 0000000..f7c049a --- /dev/null +++ b/src/features/control/settings/list/ControlListAddMenu.vue @@ -0,0 +1,124 @@ + + + + + diff --git a/src/features/control/settings/list/ControlListItem.vue b/src/features/control/settings/list/ControlListItem.vue new file mode 100644 index 0000000..ba006da --- /dev/null +++ b/src/features/control/settings/list/ControlListItem.vue @@ -0,0 +1,101 @@ + + + + + diff --git a/src/features/control/settings/list/ControlListItemActions.vue b/src/features/control/settings/list/ControlListItemActions.vue new file mode 100644 index 0000000..f0cd3b6 --- /dev/null +++ b/src/features/control/settings/list/ControlListItemActions.vue @@ -0,0 +1,83 @@ + + + + + \ No newline at end of file diff --git a/src/features/control/settings/list/ControlListItemConfigure.vue b/src/features/control/settings/list/ControlListItemConfigure.vue new file mode 100644 index 0000000..62e790f --- /dev/null +++ b/src/features/control/settings/list/ControlListItemConfigure.vue @@ -0,0 +1,15 @@ + + + + + diff --git a/src/features/control/settings/list/ControlListSettings.vue b/src/features/control/settings/list/ControlListSettings.vue new file mode 100644 index 0000000..407a47b --- /dev/null +++ b/src/features/control/settings/list/ControlListSettings.vue @@ -0,0 +1,58 @@ + + + \ No newline at end of file diff --git a/src/features/control/store/control.store.ts b/src/features/control/store/control.store.ts new file mode 100644 index 0000000..2553538 --- /dev/null +++ b/src/features/control/store/control.store.ts @@ -0,0 +1,55 @@ +import { useControlFeature } from '@/features/control' +import { + computed, + type ComputedRef, + type UnwrapNestedRefs, + watch, + type WritableComputedRef, +} from 'vue' +import type { ControlState, PluggableControl } from '@/features/control/types' +import type { Modify } from '@/utils/utility-types' +import { createInjectionState } from '@/utils/createInjectionState' +import { unref } from 'vue' +import { useControlComponents } from '@/features/control/hooks/useControlComponents' + +type TypedSettingItemStore = Modify< + ReturnType, + { + state: WritableComputedRef> + defaults: ComputedRef> + } +> + +const [useProvideControlStore, useDefaultControlStore] = createInjectionState( + (idOrControl: string | PluggableControl) => { + const store = useControlFeature().useStore() + const control = computed(() => + typeof idOrControl === 'string' + ? store.plugins[idOrControl] + : idOrControl, + ) + + const state = computed({ + get: () => control.value?.state, + set: (value) => { + control.value.state = value + }, + }) + + return { + control, + id: control.value.id, + icon: computed(() => control.value?.icon), + type: computed(() => control.value.type), + defaults: computed(() => control.value.defaults), + state, + components: useControlComponents(control), + } + }, +) + +function useControlStore() { + return useDefaultControlStore() as TypedSettingItemStore +} + +export { useProvideControlStore, useControlStore } diff --git a/src/features/control/types.ts b/src/features/control/types.ts new file mode 100644 index 0000000..abd6acb --- /dev/null +++ b/src/features/control/types.ts @@ -0,0 +1,75 @@ +import type { ControlType } from '@/features/control/enums' +import type { Pluggable, PluggableOptions } from '@/hooks/usePluggable/types' + +export interface ControlOptions + extends PluggableOptions> { + type?: T +} + +export type ControlTypeType = (typeof ControlType)[keyof typeof ControlType] + +export type ControlTypeStates = { + [ControlType.NUMBER]: ControlNumberState + [ControlType.SLIDER]: ControlSliderState + [ControlType.SELECT]: ControlSelectState + [ControlType.TOGGLE]: ControlToggleState + [ControlType.COLOR]: ControlColorState + [ControlType.TEXT]: ControlTextState + [ControlType.DIALOG]: ControlDialogState + [ControlType.ACTION]: ControlActionState + [ControlType.MULTI_SLIDER]: ControlMultiSliderState +} + +export type ControlStateType = + ControlTypeStates[T] + +export interface ControlState { + label: string + desc?: string + value?: T + resetValue?: T + isDetailedView?: boolean +} + +export interface ControlNumberState extends ControlState { + min: number + max: number + step: number +} +export interface ControlSliderState extends ControlNumberState {} +export interface ControlSelectState extends ControlState { + items: { id: string; label: string; value?: T; icon?: string }[] +} + +export interface ControlToggleState extends ControlState { + activeLabel?: string + inactiveLabel?: string + highlightColor?: string +} + +export interface ControlTextState extends ControlState { + minLength?: number + maxLength?: number +} + +export interface ControlColorState extends ControlState { + presets?: string[] + mode?: 'rgb' | 'rgba' | 'hsl' | 'hsla' | 'hex' | 'hexa' +} + +export interface ControlDialogState extends ControlState {} + +export interface ControlActionState extends ControlState {} + +export interface ControlMultiSliderState + extends ControlState { + min: T + max: T + step: T + labels: { [P in keyof T]: string } + icons?: { [P in keyof T]: string } + units?: string +} + +export type PluggableControl = + Pluggable, ControlOptions> diff --git a/src/features/control/views/ControlColorView.vue b/src/features/control/views/ControlColorView.vue new file mode 100644 index 0000000..278fc1e --- /dev/null +++ b/src/features/control/views/ControlColorView.vue @@ -0,0 +1,40 @@ + + + + + diff --git a/src/features/control/views/ControlMultiSliderView.vue b/src/features/control/views/ControlMultiSliderView.vue new file mode 100644 index 0000000..3b9f17f --- /dev/null +++ b/src/features/control/views/ControlMultiSliderView.vue @@ -0,0 +1,39 @@ + + + + diff --git a/src/features/control/views/ControlSelectView.vue b/src/features/control/views/ControlSelectView.vue new file mode 100644 index 0000000..1926790 --- /dev/null +++ b/src/features/control/views/ControlSelectView.vue @@ -0,0 +1,30 @@ + + + diff --git a/src/features/control/views/ControlSliderView.vue b/src/features/control/views/ControlSliderView.vue new file mode 100644 index 0000000..3011d1f --- /dev/null +++ b/src/features/control/views/ControlSliderView.vue @@ -0,0 +1,19 @@ + + + diff --git a/src/features/control/views/ControlTextView.vue b/src/features/control/views/ControlTextView.vue new file mode 100644 index 0000000..d2eed65 --- /dev/null +++ b/src/features/control/views/ControlTextView.vue @@ -0,0 +1,10 @@ + + + diff --git a/src/features/control/views/ControlView.vue b/src/features/control/views/ControlView.vue new file mode 100644 index 0000000..9e4311c --- /dev/null +++ b/src/features/control/views/ControlView.vue @@ -0,0 +1,9 @@ + + + diff --git a/src/features/feature.ts b/src/features/feature.ts new file mode 100644 index 0000000..e35719a --- /dev/null +++ b/src/features/feature.ts @@ -0,0 +1,58 @@ +import type { Feature, FeatureEventListener, FeatureSetup } from '@/features/types' +import { reactive, ref } from 'vue' + +const features = ref<{ [id: string]: Feature }>({}) + +const listeners = ref<{ + [featureId: string]: { [event: string]: Set } +}>({}) + +export function useFeatures() { + return { + features, + listeners, + } +} + +export function defineFeatureEmits(featureId: string, events: string[]) { + return (event: string) => { + if (events.includes(event)) { + const listenersSet = listeners.value[featureId]?.[event] + if (listenersSet?.size) listenersSet.forEach((listener) => listener()) + } + } +} + +export function defineFeature( + id: ID, + setup: FeatureSetup, +): () => Feature { + const feature = setup(id) as Feature + + feature.id = id + + features.value[id] = feature + + feature.addEventListener = ( + event: string, + listener: FeatureEventListener, + ) => { + listeners.value[id] ??= {} + listeners.value[id][event] ??= new Set() + listeners.value[id][event].add(listener) + } + + feature.removeEventListener = ( + event: string, + listener: FeatureEventListener, + ) => { + listeners.value[id]?.[event].delete(listener) + } + + const originalUseStore = feature.useStore + feature.useStore = originalUseStore + ? () => reactive(originalUseStore() as object) as State & Actions + : undefined + + return () => feature +} diff --git a/src/features/flip/FlipXIcon.vue b/src/features/flip/FlipXIcon.vue new file mode 100644 index 0000000..b5a3f44 --- /dev/null +++ b/src/features/flip/FlipXIcon.vue @@ -0,0 +1,23 @@ + + + + + diff --git a/src/features/flip/FlipYIcon.vue b/src/features/flip/FlipYIcon.vue new file mode 100644 index 0000000..95291df --- /dev/null +++ b/src/features/flip/FlipYIcon.vue @@ -0,0 +1,23 @@ + + + + + diff --git a/src/features/flip/flip-x/index.ts b/src/features/flip/flip-x/index.ts new file mode 100644 index 0000000..462fe2d --- /dev/null +++ b/src/features/flip/flip-x/index.ts @@ -0,0 +1,33 @@ +import { defineFeature } from '@/features/feature' +import { ref } from 'vue' +import { useControlFeature } from '@/features/control' +import { ControlType } from '@/features/control/enums' +import FlipXIcon from '@/features/flip/FlipXIcon.vue' + +export const useFlipXFeature = defineFeature('flip-x', (id) => { + const value = ref(false) + + useControlFeature().use({ + id, + type: ControlType.TOGGLE, + defaults: { + label: 'Flip Horizontally', + desc: "Reverse the content's orientation along the X-axis.", + value: false, + resetValue: false, + activeLabel: 'Flipped', + }, + state: { + value, + }, + components: { + icon: () => FlipXIcon, + }, + }) + + return { + useStore: () => ({ + value, + }), + } +}) diff --git a/src/features/flip/flip-y/index.ts b/src/features/flip/flip-y/index.ts new file mode 100644 index 0000000..d222889 --- /dev/null +++ b/src/features/flip/flip-y/index.ts @@ -0,0 +1,33 @@ +import { defineFeature } from '@/features/feature' +import { ref } from 'vue' +import { useControlFeature } from '@/features/control' +import { ControlType } from '@/features/control/enums' +import FlipYIcon from '@/features/flip/FlipYIcon.vue' + +export const useFlipYFeature = defineFeature('flip-y', (id) => { + const value = ref(false) + + useControlFeature().use({ + id, + type: ControlType.TOGGLE, + defaults: { + label: 'Flip Vertically', + desc: "Reverse the content's orientation along the Y-axis.", + value: false, + resetValue: false, + activeLabel: 'Flipped', + }, + state: { + value, + }, + components: { + icon: () => FlipYIcon, + }, + }) + + return { + useStore: () => ({ + value, + }), + } +}) diff --git a/src/features/flip/index.ts b/src/features/flip/index.ts new file mode 100644 index 0000000..408ac91 --- /dev/null +++ b/src/features/flip/index.ts @@ -0,0 +1,22 @@ +import { defineFeature } from '@/features/feature' +import { computed } from 'vue' +import { useContentFeature } from '@/features/content' +import { useFlipXFeature } from '@/features/flip/flip-x' +import { useFlipYFeature } from '@/features/flip/flip-y' + +export const useFlipFeature = defineFeature('flip', (id) => { + const flipX = useFlipXFeature().useStore() + const flipY = useFlipYFeature().useStore() + + useContentFeature().useModifier({ + id, + defaults: { + name: 'Flip', + }, + styles: { + scale: computed(() => (flipX.value ? -1 : 1) + ' ' + (flipY.value ? -1 : 1)), + }, + }) + + return {} +}) diff --git a/src/features/font-family/index.ts b/src/features/font-family/index.ts new file mode 100644 index 0000000..0b8f105 --- /dev/null +++ b/src/features/font-family/index.ts @@ -0,0 +1,59 @@ +import { defineFeature } from '@/features/feature' +import { computed, ref } from 'vue' +import { useControlFeature } from '@/features/control' +import { ControlType } from '@/features/control/enums' +import { useContentFeature } from '@/features/content' +import { mdiFormatFont } from '@mdi/js' + +export const useFontFamilyFeature = defineFeature('font-family', (id) => { + const DEFAULT_FONT_ID = 'Default' + + const value = ref(DEFAULT_FONT_ID) + const label = 'Font Family' + const desc = 'Typeface for text elements' + + useControlFeature().use({ + id, + type: ControlType.SELECT, + icon: mdiFormatFont, + defaults: { + label, + desc, + value: DEFAULT_FONT_ID, + resetValue: DEFAULT_FONT_ID, + items: computed(() => [ + { label: 'Default', id: DEFAULT_FONT_ID }, + { label: 'Arial', id: 'Arial' }, + { label: 'Courier New', id: 'Courier New' }, + { label: 'Georgia', id: 'Georgia' }, + { label: 'Helvetica', id: 'Helvetica' }, + { label: 'Times New Roman', id: 'Times New Roman' }, + { label: 'Trebuchet MS', id: 'Trebuchet MS' }, + { label: 'Tahoma', id: 'Tahoma' }, + { label: 'Roboto', id: 'Roboto' }, + { label: 'Verdana', id: 'Verdana' }, + ]), + }, + state: { + value, + }, + }) + + useContentFeature().useModifier({ + id, + defaults: { + name: label, + }, + styles: { + fontFamily: computed(() => + value.value === DEFAULT_FONT_ID ? 'var(--font-interface)' : value.value, + ), + }, + }) + + return { + useStore: () => ({ + value, + }), + } +}) diff --git a/src/features/font-size/index.ts b/src/features/font-size/index.ts new file mode 100644 index 0000000..daa9267 --- /dev/null +++ b/src/features/font-size/index.ts @@ -0,0 +1,46 @@ +import { defineFeature } from '@/features/feature' +import { computed, ref } from 'vue' +import { useControlFeature } from '@/features/control' +import { ControlType } from '@/features/control/enums' +import { useContentFeature } from '@/features/content' +import { mdiFormatSize } from '@mdi/js' + +export const useFontSizeFeature = defineFeature('font-size', (id) => { + const value = ref(60) + const label = 'Font Size' + const desc = 'Size of the text' + + useControlFeature().use({ + id, + type: ControlType.SLIDER, + icon: mdiFormatSize, + defaults: { + label, + desc, + value: value.value, + resetValue: value.value, + min: 1, + max: 200, + step: 1, + }, + state: { + value, + }, + }) + + useContentFeature().useModifier({ + id, + defaults: { + name: label, + }, + styles: { + fontSize: computed(() => value.value + 'px'), + }, + }) + + return { + useStore: () => ({ + value, + }), + } +}) diff --git a/src/features/letter-spacing/index.ts b/src/features/letter-spacing/index.ts new file mode 100644 index 0000000..33221f5 --- /dev/null +++ b/src/features/letter-spacing/index.ts @@ -0,0 +1,46 @@ +import { defineFeature } from '@/features/feature' +import { computed, ref } from 'vue' +import { useControlFeature } from '@/features/control' +import { ControlType } from '@/features/control/enums' +import { useContentFeature } from '@/features/content' +import { mdiFormatLetterSpacing } from '@mdi/js' + +export const useLetterSpacingFeature = defineFeature('letter-spacing', (id) => { + const value = ref(0) + const label = 'Letter Spacing' + const desc = 'Space between the letters' + + useControlFeature().use({ + id, + type: ControlType.SLIDER, + icon: mdiFormatLetterSpacing, + defaults: { + label, + desc, + value: value.value, + resetValue: value.value, + min: -5, + max: 10, + step: 0.05, + }, + state: { + value, + }, + }) + + useContentFeature().useModifier({ + id, + defaults: { + name: label, + }, + styles: { + letterSpacing: computed(() => value.value + 'px'), + }, + }) + + return { + useStore: () => ({ + value, + }), + } +}) diff --git a/src/features/line-height/index.ts b/src/features/line-height/index.ts new file mode 100644 index 0000000..8ab7282 --- /dev/null +++ b/src/features/line-height/index.ts @@ -0,0 +1,46 @@ +import { defineFeature } from '@/features/feature' +import { computed, ref } from 'vue' +import { useControlFeature } from '@/features/control' +import { ControlType } from '@/features/control/enums' +import { useContentFeature } from '@/features/content' +import { mdiFormatLineHeight } from '@mdi/js' + +export const useLineHeightFeature = defineFeature('line-height', (id) => { + const value = ref(1.2) + const label = 'Line Height' + const desc = 'Space between the lines' + + useControlFeature().use({ + id, + type: ControlType.SLIDER, + icon: mdiFormatLineHeight, + defaults: { + label, + desc, + value: value.value, + resetValue: value.value, + min: 0.7, + max: 5, + step: 0.1 + }, + state: { + value, + }, + }) + + useContentFeature().useModifier({ + id, + defaults: { + name: label, + }, + styles: { + lineHeight: computed(() => value.value + 'em'), + }, + }) + + return { + useStore: () => ({ + value, + }), + } +}) diff --git a/src/features/loader.ts b/src/features/loader.ts new file mode 100644 index 0000000..07f5831 --- /dev/null +++ b/src/features/loader.ts @@ -0,0 +1,34 @@ +import { useFeatures } from '@/features/feature' +import type { Feature, FeatureLoadOptions } from '@/features/types' +import cloneDeep from 'lodash/cloneDeep' +import merge from 'lodash/merge' +import { watch } from 'vue' +export async function loadFeatures(options: FeatureLoadOptions): Promise { + import.meta.glob('./*/index.ts', { eager: true }) + const { features } = useFeatures() + + Object.values(features.value).forEach((feature: Feature) => { + const { useStore, persist } = feature + if (!useStore || persist === false) return + + const store = useStore() + + // restore + const savedState = options.restore(feature.id) + const mergeFn = + persist?.merge ?? + ((state, savedState) => ({ + ...state, + ...savedState, + })) + + const combinedState = mergeFn(store, cloneDeep(savedState)) + merge(store, combinedState) + + // persist + watch(store, (state) => { + const reduceFn = persist?.reduce ?? ((state: unknown) => state) + return options.persist(feature.id, reduceFn(state)) + }) + }) +} diff --git a/src/features/open-settings/index.ts b/src/features/open-settings/index.ts new file mode 100644 index 0000000..0ecf6fa --- /dev/null +++ b/src/features/open-settings/index.ts @@ -0,0 +1,27 @@ +import { useControlFeature } from '@/features/control' +import { defineFeature, defineFeatureEmits } from '@/features/feature' +import { mdiCog } from '@mdi/js' +import { ref, watch } from 'vue' +import { ControlType } from '@/features/control/enums' + +export const useOpenSettingsFeature = defineFeature('open-settings', (id) => { + const emit = defineFeatureEmits(id, ['click']) + const value = ref() + + watch(value, () => emit('click')) + + useControlFeature().use({ + id, + icon: mdiCog, + type: ControlType.ACTION, + defaults: { + label: 'Open Settings', + desc: 'Open plugin\'s tab in Obsidian settings', + }, + state: { + value, + }, + }) + + return {} +}) diff --git a/src/features/padding/index.ts b/src/features/padding/index.ts new file mode 100644 index 0000000..1a4b9b6 --- /dev/null +++ b/src/features/padding/index.ts @@ -0,0 +1,73 @@ +import { defineFeature } from '@/features/feature' +import { computed, ref } from 'vue' +import { useControlFeature } from '@/features/control' +import { ControlType } from '@/features/control/enums' +import { useContentFeature } from '@/features/content' +import { + mdiDockBottom, + mdiDockLeft, + mdiDockRight, + mdiDockTop, + mdiFitToPageOutline, +} from '@mdi/js' + +export const usePaddingFeature = defineFeature('padding', (id) => { + const value = ref([50, 5, 50, 5]) + const units = ref('%') + const label = 'Padding' + const desc = 'Space around the content' + + useControlFeature().use({ + id, + icon: mdiFitToPageOutline, + type: ControlType.MULTI_SLIDER, + defaults: { + label, + desc, + value: value.value, + resetValue: value.value, + units: units.value, + labels: ['Top', 'Right', 'Bottom', 'Left'], + min: [0, 0, 0, 0], + max: [100, 100, 100, 100], + step: [1, 1, 1, 1], + icons: [mdiDockTop, mdiDockRight, mdiDockBottom, mdiDockLeft], + }, + state: { + value, + units, + }, + }) + + const contentStore = useContentFeature().useStore() + + function getPixels(index: number, value: number): number { + return index % 2 === 0 + ? (contentStore.contentHeight * value) / 100 + : (contentStore.contentWidth * value) / 100 + } + + useContentFeature().useModifier({ + id, + defaults: { + name: label, + }, + styles: {}, + contentStyles: { + padding: computed(() => + Array.isArray(value.value) + ? value.value.reduce( + (acc, val, i) => acc + `${getPixels(i, val)}px `, + '', + ) + : '', + ), + }, + }) + + return { + useStore: () => ({ + value, + }), + } +}) diff --git a/src/features/pagemap/PagemapView.vue b/src/features/pagemap/PagemapView.vue new file mode 100644 index 0000000..a6a2361 --- /dev/null +++ b/src/features/pagemap/PagemapView.vue @@ -0,0 +1,179 @@ + + + + + diff --git a/src/features/pagemap/index.ts b/src/features/pagemap/index.ts new file mode 100644 index 0000000..b6ce063 --- /dev/null +++ b/src/features/pagemap/index.ts @@ -0,0 +1,26 @@ +import { defineFeature } from '@/features/feature' +import Pagemap from '@/features/pagemap/PagemapView.vue' +import { mdiGlassStange } from '@mdi/js' +import { usePanelFeature } from '@/features/panel' +import { PanelLocation } from '@/features/panel/constants' + +export const usePagemapFeature = defineFeature('pagemap', (id) => { + + usePanelFeature().use({ + id, + locations: [PanelLocation.RIGHT, PanelLocation.LEFT], + defaults: { + name: 'Page Minimap', + location: PanelLocation.RIGHT, + isOpen: true, + icon: mdiGlassStange, + width: 156, + minWidth: 15, + }, + components: { + content: () => Pagemap, + }, + }) + + return {} +}) diff --git a/src/features/panel/components/PanelIcon.vue b/src/features/panel/components/PanelIcon.vue new file mode 100644 index 0000000..9920727 --- /dev/null +++ b/src/features/panel/components/PanelIcon.vue @@ -0,0 +1,20 @@ + + + diff --git a/src/features/panel/components/PanelItem.vue b/src/features/panel/components/PanelItem.vue new file mode 100644 index 0000000..4f18b6b --- /dev/null +++ b/src/features/panel/components/PanelItem.vue @@ -0,0 +1,44 @@ + + + + + diff --git a/src/features/panel/components/PanelItemDrawer.vue b/src/features/panel/components/PanelItemDrawer.vue new file mode 100644 index 0000000..20f2837 --- /dev/null +++ b/src/features/panel/components/PanelItemDrawer.vue @@ -0,0 +1,42 @@ + + + + + diff --git a/src/features/panel/components/PanelItemToolbar.vue b/src/features/panel/components/PanelItemToolbar.vue new file mode 100644 index 0000000..364d115 --- /dev/null +++ b/src/features/panel/components/PanelItemToolbar.vue @@ -0,0 +1,45 @@ + + + + + diff --git a/src/features/panel/components/PanelResizeHandle.vue b/src/features/panel/components/PanelResizeHandle.vue new file mode 100644 index 0000000..47651af --- /dev/null +++ b/src/features/panel/components/PanelResizeHandle.vue @@ -0,0 +1,131 @@ + + + + + \ No newline at end of file diff --git a/src/features/panel/components/PanelSettingIcon.vue b/src/features/panel/components/PanelSettingIcon.vue new file mode 100644 index 0000000..9ff4245 --- /dev/null +++ b/src/features/panel/components/PanelSettingIcon.vue @@ -0,0 +1,44 @@ + + + diff --git a/src/features/panel/components/PanelSettings.vue b/src/features/panel/components/PanelSettings.vue new file mode 100644 index 0000000..6b445f9 --- /dev/null +++ b/src/features/panel/components/PanelSettings.vue @@ -0,0 +1,90 @@ + + + diff --git a/src/features/panel/components/PanelsList.vue b/src/features/panel/components/PanelsList.vue new file mode 100644 index 0000000..5ea7839 --- /dev/null +++ b/src/features/panel/components/PanelsList.vue @@ -0,0 +1,15 @@ + + + \ No newline at end of file diff --git a/src/features/panel/constants.ts b/src/features/panel/constants.ts new file mode 100644 index 0000000..a4f2dce --- /dev/null +++ b/src/features/panel/constants.ts @@ -0,0 +1,12 @@ +export const PanelLocation = { + TOP: 'top', + BOTTOM: 'bottom', + LEFT: 'left', + RIGHT: 'right' +} as const + +export const PanelAlignment = { + LEFT: 'left', + RIGHT: 'right', + CENTER: 'center' +} as const diff --git a/src/features/panel/hooks/usePanelLocation.ts b/src/features/panel/hooks/usePanelLocation.ts new file mode 100644 index 0000000..d313769 --- /dev/null +++ b/src/features/panel/hooks/usePanelLocation.ts @@ -0,0 +1,112 @@ +import { PanelAlignment, PanelLocation } from '@/features/panel/constants' +import { + mdiDockBottom, + mdiDockLeft, + mdiDockRight, + mdiDockTop, + mdiFormatAlignCenter, + mdiFormatAlignLeft, + mdiFormatAlignRight, +} from '@mdi/js' +import { computed, type MaybeRef, unref } from 'vue' +import type { PanelLocationType } from '@/features/panel/types' + +export function usePanelLocation(locationRef?: MaybeRef) { + const location = computed(() => unref(locationRef)) + + const isHorizontal = computed( + () => + location.value === PanelLocation.TOP || + location.value === PanelLocation.BOTTOM, + ) + + const isVertical = computed( + () => + location.value === PanelLocation.LEFT || + location.value === PanelLocation.RIGHT, + ) + + const menuLocation = computed<'top' | 'bottom' | 'start' | 'end' | 'center'>( + () => { + if (isHorizontal.value) { + return location.value === PanelLocation.TOP ? 'bottom' : 'top' + } else { + return location.value === PanelLocation.LEFT ? 'end' : 'start' + } + }, + ) + + const menuTransition = computed(() => + isHorizontal.value + ? location.value === PanelLocation.TOP + ? 'slide-y-transition' + : 'slide-y-reverse-transition' + : location.value === PanelLocation.LEFT + ? 'slide-x-transition' + : 'slide-x-reverse-transition', + ) + + const tooltipLocation = computed<'top start' | 'bottom start' | 'left' | 'right'>(() => { + if (isHorizontal.value) { + return location.value === PanelLocation.TOP ? 'bottom start' : 'top start' + } else { + return location.value === PanelLocation.LEFT ? 'right' : 'left' + } + }) + + const locationItems = computed(() => [ + { + title: 'Top', + value: PanelLocation.TOP, + icon: mdiDockTop, + }, + { + title: 'Bottom', + value: PanelLocation.BOTTOM, + icon: mdiDockBottom, + }, + { + title: 'Left', + value: PanelLocation.LEFT, + icon: mdiDockLeft, + }, + { + title: 'Right', + value: PanelLocation.RIGHT, + icon: mdiDockRight, + }, + ]) + + const alignmentItems = computed(() => [ + { + title: 'Default', + value: null, + }, + { + title: 'Center', + value: PanelAlignment.CENTER, + icon: mdiFormatAlignCenter, + }, + { + title: 'Left', + value: PanelAlignment.LEFT, + icon: mdiFormatAlignLeft, + }, + { + title: 'Right', + value: PanelAlignment.RIGHT, + icon: mdiFormatAlignRight, + }, + ]) + + return { + location, + isHorizontal, + isVertical, + locationItems, + alignmentItems, + menuLocation, + menuTransition, + tooltipLocation, + } +} diff --git a/src/features/panel/index.ts b/src/features/panel/index.ts new file mode 100644 index 0000000..dc339e8 --- /dev/null +++ b/src/features/panel/index.ts @@ -0,0 +1,131 @@ +import { defineFeature } from '@/features/feature' +import PanelSettings from '@/features/panel/components/PanelSettings.vue' +import type { + PanelOptions, + PanelState, + PluggablePanel, +} from '@/features/panel/types' +import { useSettingItems } from '@/features/settings/hooks/useSettingItems' +import { usePluggable } from '@/hooks/usePluggable/usePluggable' +import { defaultTo } from '@/utils/defaultTo' +import { mdiPageLayoutHeaderFooter } from '@mdi/js' +import { computed, type Ref, ref, unref } from 'vue' +import { useSettingsFeature } from '../settings' +import PanelIcon from '@/features/panel/components/PanelIcon.vue' +import PanelItemIcon from '@/features/panel/components/PanelSettingIcon.vue' +import type { PluggableReducedItem } from '@/hooks/usePluggable/usePluggableUtils' +import { genUniqueName } from '@/utils/genUniqueName' +import { createStateAccessor } from '@/utils/createStateAccessor/createStateAccessor' + +export const usePanelFeature = defineFeature('panel', (id) => { + const { + use, + plugins, + getPluginComponent, + getDiffsDeep, + getClonePluginCustom, + mergeArrayWithPlugins, + getPluginById, + } = usePluggable() + + const panels = ref([]) as Ref + + const getPanelFromPlugin = getClonePluginCustom( + (clone, plugin, extendWith) => { + const items = unref(extendWith?.state?.items) ?? unref(clone.state.items) + clone.state.items = mergeArrayWithPlugins( + (items ?? []) as PluggableReducedItem[], + plugin.plugins, + ) + }, + ) + + const defaultPanelsAccessor = createStateAccessor([], { + onGet: (value) => value.map((plugin) => getPanelFromPlugin(plugin)), + onSet: (value) => { + if (!panels.value.length) panels.value = defaultPanelsAccessor.get() + }, + }) + + useSettingsFeature().use({ + id, + tab: 'Panels', + icon: mdiPageLayoutHeaderFooter, + defaults: { + name: 'Panels', + items: [], + }, + state: { + name: 'Panels', + items: computed(() => + panels.value.map((item, i) => ({ + id: `${item.id}:${item.key}`, + name: item.state.name, + icon: item.state.icon, + state: item.state, + defaults: item.defaults, + target: item, + isEnabled: computed({ + get: () => item.state.isOpen, + set: (value) => (item.state.isOpen = value), + }), + components: { + content: () => PanelSettings, + settings: getPluginComponent(item.id, 'settings'), + icon: () => PanelItemIcon, + }, + })), + ), + }, + components: { + content: () => PanelSettings, + icon: () => PanelIcon, + }, + ...useSettingItems({ + plugins, + source: panels, + customClonePlugin: getPanelFromPlugin, + getDefaultItems: defaultPanelsAccessor.get, + onAddItem: (plugin) => { + return getPanelFromPlugin(plugin, { + state: { + name: genUniqueName( + plugin.state.name, + panels.value.map(({ state }) => state.name), + ), + }, + }) + }, + }), + }) + + return { + use, + useStore: () => ({ + plugins, + panels, + getPanelFromPlugin, + setDefaultPanels: defaultPanelsAccessor.set, + }), + persist: { + reduce: (state) => + getDiffsDeep( + { panels }, + { + panels: panels.value.map(({ id }) => getPluginById(id)), + }, + ), + merge: (state, savedState) => ({ + panels: defaultTo( + () => + mergeArrayWithPlugins( + savedState?.panels, + plugins.value, + getPanelFromPlugin, + ), + [], + ), + }), + }, + } +}) diff --git a/src/features/panel/store/panel.store.ts b/src/features/panel/store/panel.store.ts new file mode 100644 index 0000000..199ba11 --- /dev/null +++ b/src/features/panel/store/panel.store.ts @@ -0,0 +1,48 @@ +import { usePanelFeature } from '@/features/panel' +import type { PanelState, PluggablePanel } from '@/features/panel/types' +import { createInjectionState } from '@/utils/createInjectionState' +import { computed, reactive, type Ref, type WritableComputedRef } from 'vue' +import { PanelLocation } from '@/features/panel/constants' +import type { Modify } from '@/utils/utility-types' +import { usePanelLocation } from '@/features/panel/hooks/usePanelLocation' + +const [useProvidePanelStore, useDefaultPanelStore] = createInjectionState( + (panel: Ref) => { + const store = usePanelFeature().useStore() + const state = computed({ + get: () => panel.value.state, + set: (value) => (panel.value.state = value), + }) + + const location = usePanelLocation(computed(() => state.value.location)) + + function getIsCompact(options: { width?: number; height?: number }) { + const { width, height } = options + const { isHorizontal, isVertical } = location + return ( + (isHorizontal.value && height && state.value.height < height) || + (isVertical.value && width && state.value.width < width) + ) + } + + return { + panel, + state, + ...location, + + getIsCompact, + } + }, +) + +function usePanelStore() { + return useDefaultPanelStore() as Modify< + ReturnType, + { + panel: Ref> + state: WritableComputedRef> + } + > +} + +export { useProvidePanelStore, usePanelStore } diff --git a/src/features/panel/types.ts b/src/features/panel/types.ts new file mode 100644 index 0000000..842a74c --- /dev/null +++ b/src/features/panel/types.ts @@ -0,0 +1,46 @@ +import type { PanelAlignment, PanelLocation } from '@/features/panel/constants' +import type { + Pluggable, + PluggableMap, + PluggableOptions, +} from '@/hooks/usePluggable/types' +import type { MaybeRef } from 'vue' + +export type PanelLocationType = + (typeof PanelLocation)[keyof typeof PanelLocation] + +export type PanelAlignType = (typeof PanelAlignment)[keyof typeof PanelAlignment] + +export interface PanelHandle { + width: string + color: string + hoverColor: string +} + +export interface PanelState { + name: string + location: PanelLocationType + isOpen: boolean + alignment?: PanelAlignType + height?: number + width?: number + minHeight?: number + minWidth?: number + index?: number + handle?: PanelHandle + items?: ItemState[] + icon?: string +} + +export interface PanelOptions< + ItemState = unknown, + T extends PanelState = PanelState, +> extends PluggableOptions { + plugins?: MaybeRef + locations?: MaybeRef +} + +export type PluggablePanel = Pluggable< + PanelState, + PanelOptions +> diff --git a/src/features/pin-note/PinNoteIcon.vue b/src/features/pin-note/PinNoteIcon.vue new file mode 100644 index 0000000..b26d124 --- /dev/null +++ b/src/features/pin-note/PinNoteIcon.vue @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/src/features/pin-note/index.ts b/src/features/pin-note/index.ts new file mode 100644 index 0000000..af99e3f --- /dev/null +++ b/src/features/pin-note/index.ts @@ -0,0 +1,35 @@ +import { useControlFeature } from '@/features/control' +import { ControlType } from '@/features/control/enums' +import { defineFeature } from '@/features/feature' +import PinNoteIcon from '@/features/pin-note/PinNoteIcon.vue' +import { ref } from 'vue' + +export const usePinNoteFeature = defineFeature('pin-note', (id) => { + const value = ref(false) + const label = 'Pin Note' + const desc = 'Preserve content when switching focus to other notes' + + useControlFeature().use({ + id, + type: ControlType.TOGGLE, + defaults: { + label, + desc, + value: value.value, + activeLabel: 'Pinned', + inactiveLabel: 'Unpinned', + }, + state: { + value, + }, + components: { + icon: () => PinNoteIcon, + }, + }) + + return { + useStore: () => ({ + value, + }), + } +}) diff --git a/src/features/play/PlayIcon.vue b/src/features/play/PlayIcon.vue new file mode 100644 index 0000000..5dcd197 --- /dev/null +++ b/src/features/play/PlayIcon.vue @@ -0,0 +1,22 @@ + + + + + diff --git a/src/features/play/index.ts b/src/features/play/index.ts new file mode 100644 index 0000000..0543de8 --- /dev/null +++ b/src/features/play/index.ts @@ -0,0 +1,35 @@ +import { useControlFeature } from '@/features/control' +import { ControlType } from '@/features/control/enums' +import { defineFeature } from '@/features/feature' +import { ref } from 'vue' +import PlayIcon from '@/features/play/PlayIcon.vue' + +export const usePlayFeature = defineFeature('play', (id) => { + const value = ref(false) + const label = 'Play / Pause' + const desc = 'Toggle auto-scroll' + + useControlFeature().use({ + id, + type: ControlType.TOGGLE, + defaults: { + label, + desc, + value: value.value, + activeLabel: 'Playing', + inactiveLabel: 'Paused', + }, + state: { + value, + }, + components: { + icon: () => PlayIcon, + }, + }) + + return { + useStore: () => ({ + value, + }), + } +}) diff --git a/src/features/settings/Settings.vue b/src/features/settings/Settings.vue new file mode 100644 index 0000000..7502400 --- /dev/null +++ b/src/features/settings/Settings.vue @@ -0,0 +1,13 @@ + + + + + diff --git a/src/features/settings/components/accordion/SettingsAccordion.vue b/src/features/settings/components/accordion/SettingsAccordion.vue new file mode 100644 index 0000000..0b365f8 --- /dev/null +++ b/src/features/settings/components/accordion/SettingsAccordion.vue @@ -0,0 +1,33 @@ + + + \ No newline at end of file diff --git a/src/features/settings/components/accordion/SettingsAccordionItem.vue b/src/features/settings/components/accordion/SettingsAccordionItem.vue new file mode 100644 index 0000000..43026e3 --- /dev/null +++ b/src/features/settings/components/accordion/SettingsAccordionItem.vue @@ -0,0 +1,73 @@ + + + + + \ No newline at end of file diff --git a/src/features/settings/components/elements/SettingField.vue b/src/features/settings/components/elements/SettingField.vue new file mode 100644 index 0000000..5396d0a --- /dev/null +++ b/src/features/settings/components/elements/SettingField.vue @@ -0,0 +1,99 @@ + + + + + diff --git a/src/features/settings/components/elements/SettingsAddListItem.vue b/src/features/settings/components/elements/SettingsAddListItem.vue new file mode 100644 index 0000000..a91fecf --- /dev/null +++ b/src/features/settings/components/elements/SettingsAddListItem.vue @@ -0,0 +1,68 @@ + + + diff --git a/src/features/settings/components/elements/SettingsDelete.vue b/src/features/settings/components/elements/SettingsDelete.vue new file mode 100644 index 0000000..533eee3 --- /dev/null +++ b/src/features/settings/components/elements/SettingsDelete.vue @@ -0,0 +1,19 @@ + + + diff --git a/src/features/settings/components/elements/SettingsIcon.vue b/src/features/settings/components/elements/SettingsIcon.vue new file mode 100644 index 0000000..f7549a6 --- /dev/null +++ b/src/features/settings/components/elements/SettingsIcon.vue @@ -0,0 +1,32 @@ + + + diff --git a/src/features/settings/components/elements/SettingsRestoreDefault.vue b/src/features/settings/components/elements/SettingsRestoreDefault.vue new file mode 100644 index 0000000..1f4fd4a --- /dev/null +++ b/src/features/settings/components/elements/SettingsRestoreDefault.vue @@ -0,0 +1,19 @@ + + + \ No newline at end of file diff --git a/src/features/settings/components/list/SettingsList.vue b/src/features/settings/components/list/SettingsList.vue new file mode 100644 index 0000000..8978c60 --- /dev/null +++ b/src/features/settings/components/list/SettingsList.vue @@ -0,0 +1,21 @@ + + + \ No newline at end of file diff --git a/src/features/settings/components/list/SettingsListItem.vue b/src/features/settings/components/list/SettingsListItem.vue new file mode 100644 index 0000000..f6f50e8 --- /dev/null +++ b/src/features/settings/components/list/SettingsListItem.vue @@ -0,0 +1,34 @@ + + + + + diff --git a/src/features/settings/components/list/SettingsListItemActions.vue b/src/features/settings/components/list/SettingsListItemActions.vue new file mode 100644 index 0000000..9e65d1f --- /dev/null +++ b/src/features/settings/components/list/SettingsListItemActions.vue @@ -0,0 +1,31 @@ + + + + + \ No newline at end of file diff --git a/src/features/settings/components/list/SettingsListItemContent.vue b/src/features/settings/components/list/SettingsListItemContent.vue new file mode 100644 index 0000000..cd10a5c --- /dev/null +++ b/src/features/settings/components/list/SettingsListItemContent.vue @@ -0,0 +1,22 @@ + + + + + \ No newline at end of file diff --git a/src/features/settings/components/list/SettingsListItemHeader.vue b/src/features/settings/components/list/SettingsListItemHeader.vue new file mode 100644 index 0000000..b301d06 --- /dev/null +++ b/src/features/settings/components/list/SettingsListItemHeader.vue @@ -0,0 +1,38 @@ + + + + + \ No newline at end of file diff --git a/src/features/settings/components/tabs/SettingsTabs.vue b/src/features/settings/components/tabs/SettingsTabs.vue new file mode 100644 index 0000000..0099738 --- /dev/null +++ b/src/features/settings/components/tabs/SettingsTabs.vue @@ -0,0 +1,44 @@ + + + + + \ No newline at end of file diff --git a/src/features/settings/hooks/useSettingItems.ts b/src/features/settings/hooks/useSettingItems.ts new file mode 100644 index 0000000..cfd99e5 --- /dev/null +++ b/src/features/settings/hooks/useSettingItems.ts @@ -0,0 +1,65 @@ +import type { Pluggable, PluggableMap } from '@/hooks/usePluggable/types' +import { usePluggableUtils } from '@/hooks/usePluggable/usePluggableUtils' +import { computed, type Ref, unref } from 'vue' +import type { SettingItem } from '@/features/settings/types' +import type { DeepPartial } from '@/utils/utility-types' + +export function useSettingItems

(options: { + source: Ref + plugins: Ref + getDefaultItems: () => P[] + onAddItem?: (item: P) => P + customClonePlugin?: (plugin: P, extendWith?: DeepPartial) => P +}) { + const clonePlugin = + options.customClonePlugin ?? usePluggableUtils().clonePlugin + const { source, plugins, getDefaultItems, onAddItem } = options + + function moveItem(oldIndex: number, newIndex: number) { + source.value.splice(newIndex, 0, source.value.splice(oldIndex, 1)[0]) + } + + function removeItem(index: number) { + source.value.splice(index, 1) + } + + function addItem(id: string) { + const plugin = plugins.value[id] as P + if (plugin) { + source.value.push(onAddItem?.(plugin) ?? (clonePlugin(plugin) as P)) + } + } + + function restoreDefaults() { + source.value = getDefaultItems() + } + + function restoreItemDefaults(item: SettingItem) { + const index = source.value.indexOf(unref(item.target)) + if (index === -1) return + const target = source.value[index] + source.value[index] = clonePlugin(target, { state: target.defaults }) as P + } + + const addableItems = computed(() => + Object.values(plugins.value).map((plugin: Pluggable) => ({ + id: plugin.id, + icon: plugin.state?.icon ?? plugin.icon, + name: getItemName(plugin) ?? plugin.id, + })), + ) + + function getItemName(item: Pluggable) { + const state = item.state + return state?.name ?? state?.label ?? state?.title + } + + return { + restoreDefaults, + restoreItemDefaults, + removeItem, + moveItem, + addItem, + addableItems, + } +} diff --git a/src/features/settings/hooks/useSettingsTabs.ts b/src/features/settings/hooks/useSettingsTabs.ts new file mode 100644 index 0000000..cb8cc1a --- /dev/null +++ b/src/features/settings/hooks/useSettingsTabs.ts @@ -0,0 +1,40 @@ +import type { + SettingOptions, + SettingsTab, + SettingState, +} from '@/features/settings/types' +import type { PluggableMap } from '@/hooks/usePluggable/types' +import { computed, type Ref } from 'vue' + +export function useSettingsTabs( + plugins: Ref>, +) { + const tabMap = computed<{ [tabId: string]: SettingsTab }>(() => { + const map: { [tabId: string]: SettingsTab } = {} + Object.values(plugins.value).forEach((plugin) => { + const tabConfig = + typeof plugin.tab === 'object' && 'name' in plugin.tab + ? plugin.tab + : undefined + const tabName = tabConfig?.name || (plugin.tab as string) || 'Other' + + map[tabName] ??= { + id: tabName, + name: tabName, + plugins: [], + priority: tabConfig?.priority ?? 0, + } + + map[tabName].plugins.push(plugin) + }) + return map + }) + + const tabs = computed(() => + Object.values(tabMap.value).sort((a, b) => a.priority - b.priority), + ) + + return { + tabs, + } +} diff --git a/src/features/settings/index.ts b/src/features/settings/index.ts new file mode 100644 index 0000000..319dc37 --- /dev/null +++ b/src/features/settings/index.ts @@ -0,0 +1,18 @@ +import { defineFeature } from '@/features/feature' +import { useSettingsTabs } from '@/features/settings/hooks/useSettingsTabs' +import type { SettingOptions, SettingState } from '@/features/settings/types' +import { usePluggable } from '@/hooks/usePluggable/usePluggable' + +export const useSettingsFeature = defineFeature('settings', (id) => { + const { use, plugins } = usePluggable() + const { tabs } = useSettingsTabs(plugins) + + return { + use, + persist: false, + useStore: () => ({ + plugins, + tabs, + }), + } +}) diff --git a/src/features/settings/store/setting-item.store.ts b/src/features/settings/store/setting-item.store.ts new file mode 100644 index 0000000..8701602 --- /dev/null +++ b/src/features/settings/store/setting-item.store.ts @@ -0,0 +1,53 @@ +import { useSettingStore } from '@/features/settings/store/setting.store' +import type { SettingItem } from '@/features/settings/types' +import { createInjectionState } from '@/utils/createInjectionState' +import { computed, isRef, type Ref, unref, type WritableComputedRef } from 'vue' +import type { Modify } from '@/utils/utility-types' +import { usePluggableUtils } from '@/hooks/usePluggable/usePluggableUtils' + +type TypedSettingItemStore = Modify< + ReturnType, + { state: WritableComputedRef; target: WritableComputedRef } +> +const [useProvideSettingItemStore, useDefaultSettingItemStore] = + createInjectionState((itemRef: Ref) => { + const settingStore = useSettingStore() + const item = unref(itemRef) + + const { extendState } = usePluggableUtils() + + return { + item: itemRef, + id: item.id, + icon: item.icon, + components: item.components, + name: computed(() => itemRef.value.name), + target: computed(() => unref(itemRef.value.target)), + index: computed(() => settingStore.items.value.indexOf(item)), + isEnabled: computed({ + get: () => unref(itemRef.value.isEnabled), + set: (value) => { + if (isRef(itemRef.value.isEnabled)) + itemRef.value.isEnabled.value = value + else itemRef.value.isEnabled = value + }, + }), + state: computed({ + get: () => itemRef.value.state, + set: (value) => (itemRef.value.state = value), + }), + reset() { + if (settingStore.setting.value.restoreItemDefaults) { + settingStore.setting.value.restoreItemDefaults(item) + } else { + extendState(itemRef.value.state, item.defaults) + } + }, + } + }) + +function useSettingItemStore() { + return useDefaultSettingItemStore() as TypedSettingItemStore +} + +export { useProvideSettingItemStore, useSettingItemStore } diff --git a/src/features/settings/store/setting.store.ts b/src/features/settings/store/setting.store.ts new file mode 100644 index 0000000..084d1fc --- /dev/null +++ b/src/features/settings/store/setting.store.ts @@ -0,0 +1,26 @@ +import { useSettingsFeature } from '@/features/settings' +import { createInjectionState } from '@/utils/createInjectionState' +import cloneDeep from 'lodash/cloneDeep' +import merge from 'lodash/merge' +import { computed, isReadonly, isRef, toRaw, unref } from 'vue' + +export const [useProvideSettingStore, useSettingStore] = createInjectionState( + (id: string) => { + const store = useSettingsFeature().useStore() + const setting = computed(() => store.plugins[id]) + + return { + id, + setting, + icon: computed(() => setting.value.icon), + items: computed(() => unref(setting.value.state.items)), + state: computed({ + get: () => unref(setting).state, + set: (value) => { + setting.value.state = value + }, + }), + components: computed(() => setting.value.components), + } + }, +) diff --git a/src/features/settings/types.ts b/src/features/settings/types.ts new file mode 100644 index 0000000..d2045eb --- /dev/null +++ b/src/features/settings/types.ts @@ -0,0 +1,60 @@ +import type { + Pluggable, + PluggableComponents, + PluggableMap, + PluggableOptions, +} from '@/hooks/usePluggable/types' +import type { MaybeRef } from 'vue' + +export interface SettingState { + name: string + desc?: string + items: SettingItem[] +} + +export interface SettingItem { + id: string + name: string + desc?: string + icon?: string + isEnabled?: MaybeRef + state?: T + defaults?: T + components?: PluggableComponents + target?: MaybeRef +} + +export interface SettingAddableItem { + id: string + name: string + icon?: string +} + +export interface SettingOptions + extends PluggableOptions { + tab?: string | { name: string, priority: number } + addableItems?: MaybeRef + addItem?: (id: string) => void + removeItem?: (index: number) => void + moveItem?: (oldIndex: number, newIndex: number) => void + restoreDefaults?: () => void + restoreItemDefaults?: (item: SettingItem) => void +} + +export type SettingPluggable = Pluggable< + S, + SettingOptions +> + +export interface SettingsFeatureState { + plugins: PluggableMap +} + +export interface SettingsTab { + id: string + name: string + desc?: string + plugins: SettingPluggable[] + icon?: string + priority?: number +} diff --git a/src/features/speed/SpeedIcon.vue b/src/features/speed/SpeedIcon.vue new file mode 100644 index 0000000..94a8564 --- /dev/null +++ b/src/features/speed/SpeedIcon.vue @@ -0,0 +1,32 @@ + + + + + diff --git a/src/features/speed/constants.ts b/src/features/speed/constants.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/features/speed/index.ts b/src/features/speed/index.ts new file mode 100644 index 0000000..fb0f455 --- /dev/null +++ b/src/features/speed/index.ts @@ -0,0 +1,37 @@ +import { useControlFeature } from '@/features/control' +import { ControlType } from '@/features/control/enums' +import { defineFeature } from '@/features/feature' +import SpeedIcon from '@/features/speed/SpeedIcon.vue' +import { ref } from 'vue' + +export const useSpeedFeature = defineFeature('speed', (id) => { + const value = ref(18) + const label = 'Speed' + const desc = 'Speed of the scroll' + + useControlFeature().use({ + id, + type: ControlType.SLIDER, + defaults: { + label, + desc, + value: value.value, + resetValue: 18, + min: 0, + max: 50, + step: 1, + }, + state: { + value, + }, + components: { + icon: () => SpeedIcon, + }, + }) + + return { + useStore: () => ({ + value, + }), + } +}) diff --git a/src/features/speed/types.ts b/src/features/speed/types.ts new file mode 100644 index 0000000..fe00858 --- /dev/null +++ b/src/features/speed/types.ts @@ -0,0 +1,6 @@ +import type { ControlState } from '@/features/control/types' + +export interface SpeedControlState extends ControlState { + min: number + max: number +} diff --git a/src/features/text-color/TextColorIcon.vue b/src/features/text-color/TextColorIcon.vue new file mode 100644 index 0000000..39af2c0 --- /dev/null +++ b/src/features/text-color/TextColorIcon.vue @@ -0,0 +1,37 @@ + + + + + diff --git a/src/features/text-color/index.ts b/src/features/text-color/index.ts new file mode 100644 index 0000000..2456e64 --- /dev/null +++ b/src/features/text-color/index.ts @@ -0,0 +1,45 @@ +import { defineFeature } from '@/features/feature' +import { computed, ref } from 'vue' +import { useControlFeature } from '@/features/control' +import { ControlType } from '@/features/control/enums' +import { useContentFeature } from '@/features/content' +import TextColorIcon from '@/features/text-color/TextColorIcon.vue' + +export const useTextColorFeature = defineFeature('text-color', (id) => { + const value = ref(null) + const label = 'Text Color' + const desc = 'Content\'s text color' + + useControlFeature().use({ + id, + type: ControlType.COLOR, + defaults: { + label, + desc, + value: null, + resetValue: null, + }, + state: { + value, + }, + components: { + icon: () => TextColorIcon, + }, + }) + + useContentFeature().useModifier({ + id, + defaults: { + name: label, + }, + styles: { + color: computed(() => value.value ?? 'var(--color-text)'), + }, + }) + + return { + useStore: () => ({ + value, + }), + } +}) diff --git a/src/features/types.ts b/src/features/types.ts new file mode 100644 index 0000000..7779ff5 --- /dev/null +++ b/src/features/types.ts @@ -0,0 +1,41 @@ +import type { UnwrapNestedRefs } from 'vue' + +export interface FeatureSetupReturnType { + useStore?: () => State & Actions + persist?: FeatureStorePersistOptions | false +} +export type FeatureSetup = ( + id: string, +) => F & FeatureSetupReturnType + +export type FeatureEventListener = () => void + +export type FeatureEvents = { + addEventListener: (event: string, listener: FeatureEventListener) => void + removeEventListener: (event: string, listener: FeatureEventListener) => void +} + +export type Feature< + F extends FeatureSetupReturnType, + S = Record, + A = Record, + ID extends string = string, +> = { + [K in keyof F]: K extends 'useStore' + ? () => UnwrapNestedRefs> + : F[K] +} & { id: ID } & FeatureSetupReturnType & + FeatureEvents + +export interface FeatureStorePersistOptions { + reduce?: (state: State) => PersistedState + merge?: (state: State, savedState: PersistedState) => Partial +} + +export type FeatureDebugOptions = 'persistence' + +export interface FeatureLoadOptions { + debug?: { [featureId: string]: FeatureDebugOptions[] } + persist: (featureId: string, state: S) => void + restore: (featureId: string) => S +} diff --git a/src/hooks/usePluggable/types.ts b/src/hooks/usePluggable/types.ts new file mode 100644 index 0000000..b605114 --- /dev/null +++ b/src/hooks/usePluggable/types.ts @@ -0,0 +1,52 @@ +import type { Modify } from '@/utils/utility-types' +import type { Component, MaybeRef } from 'vue' + +export interface PluggableOptions { + id: string + icon?: string + defaults: State + state: State +} +export interface PluggableComponents { + icon?: () => Component + content?: () => Component + settings?: () => Component + layout?: () => Component +} + +export type Pluggable< + State = unknown, + Options extends PluggableOptions = PluggableOptions, +> = Options & { + /** + * Used to distinguish between plugins with the same id. + * For example, if you have two plugins with the same ids but different configurations. + */ + key?: string + /** + * Custom views + */ + components?: PluggableComponents +} + +export type PluggableMap< + State = unknown, + Options extends PluggableOptions = PluggableOptions, +> = { [id: string]: Pluggable } + +export type PluggableStateMap = { [pluginId: string]: State } + +// SETUP + +export type PluggableSetup< + State, + Options extends PluggableOptions = PluggableOptions, +> = Modify< + Options, + { + state?: { [P in keyof Partial]: MaybeRef } + defaults?: { [P in keyof Partial]: MaybeRef } + } +> & { + components?: PluggableComponents +} diff --git a/src/hooks/usePluggable/usePluggable.ts b/src/hooks/usePluggable/usePluggable.ts new file mode 100644 index 0000000..f846379 --- /dev/null +++ b/src/hooks/usePluggable/usePluggable.ts @@ -0,0 +1,58 @@ +import type { + Pluggable, + PluggableComponents, + PluggableMap, + PluggableOptions, + PluggableSetup, +} from '@/hooks/usePluggable/types' +import { usePluggableUtils } from '@/hooks/usePluggable/usePluggableUtils' +import cloneDeep from 'lodash/cloneDeep' +import { nanoid } from 'nanoid' +import { type Component, computed, readonly, ref } from 'vue' + +export function usePluggable< + S extends object, + O extends PluggableOptions = PluggableOptions, +>() { + const plugins = ref>({}) + const pluggableUtils = usePluggableUtils() + + const pluginsList = computed(() => Object.values(plugins.value)) + + function use(pluginSetup: PluggableSetup): Pluggable { + const plugin = { + components: {}, + ...(pluginSetup as Pluggable), + key: nanoid(), + defaults: readonly(pluginSetup.defaults), + state: { + ...cloneDeep(pluginSetup.defaults), + ...(pluginSetup.state ?? {}), + }, + } + plugins.value[plugin.id] = plugin + return plugin + } + + function getPluginById(id: string): Pluggable | undefined { + return plugins.value[id] + } + + function getPluginComponent( + pluginId: string, + componentName: keyof PluggableComponents, + defaultComponent?: () => Component, + ): () => Component { + const components = getPluginById(pluginId)?.components + return components?.[componentName] ?? defaultComponent + } + + return { + use, + plugins, + pluginsList, + getPluginById, + getPluginComponent, + ...pluggableUtils, + } +} diff --git a/src/hooks/usePluggable/usePluggableUtils.ts b/src/hooks/usePluggable/usePluggableUtils.ts new file mode 100644 index 0000000..d0c8bed --- /dev/null +++ b/src/hooks/usePluggable/usePluggableUtils.ts @@ -0,0 +1,172 @@ +import type { Pluggable, PluggableMap } from '@/hooks/usePluggable/types' +import type { DeepPartial } from '@/utils/utility-types' +import cloneDeep from 'lodash/cloneDeep' +import isEqual from 'lodash/isEqual' +import merge from 'lodash/merge' +import isEmpty from 'lodash/isEmpty' +import isPlainObject from 'lodash/isPlainObject' +import { nanoid } from 'nanoid' +import { isRef, type MaybeRef, toRaw, unref } from 'vue' + +export type PluggableReducedItem = { + id: string + state: DeepPartial + defaults?: DeepPartial +} +type DeepPartialPlugin = DeepPartial> +type DeepPartialValue = DeepPartial[keyof S] + +export function usePluggableUtils() { + function isPluggable(item: unknown): item is Pluggable { + return ( + item && + typeof item === 'object' && + !!(item as Pluggable)?.id && + !!(item as Pluggable)?.state && + !!(item as Pluggable)?.defaults + ) + } + + function getDiffs(state: S, defaults: S): Partial { + return Object.entries(state).reduce((acc, entry) => { + const key = entry[0] as keyof S + const value = unref(entry[1] as S[typeof key]) + if (!isEqual(value, unref(defaults[key]))) acc[key] = value + return acc + }, {} as Partial) + } + + function getDiffsDeep(state: S, defaults?: S): DeepPartial { + return Object.entries(state).reduce((acc, entry) => { + const key = entry[0] as keyof S + const value = unref(entry[1]) as DeepPartialValue + const defaultValue = unref(defaults?.[key]) as DeepPartialValue + + if (isPluggable(value)) { + const diffs = getDiffsDeep(value.state, defaultValue ?? value.defaults) + if (!isEmpty(diffs)) acc[key] = diffs as DeepPartialValue + } else if (Array.isArray(value) && isPluggable(value.at(0))) { + acc[key] = getPluggableDiffsArray( + value, + Array.isArray(defaultValue) ? defaultValue : undefined, + ) as DeepPartialValue + } else if (isPlainObject(value)) { + const diffs = getDiffsDeep(value, defaultValue) + if (!isEmpty(diffs)) acc[key] = diffs as DeepPartialValue + } else if (!isEqual(value, defaultValue)) { + acc[key] = value + } + return acc + }, {} as DeepPartial) + } + + function getPluggableDiffsArray( + arr: Pluggable[], + defaults?: S[] | Pluggable[], + ): PluggableReducedItem[] { + return arr.map((plugin: Pluggable, i) => { + const defaultState = isPluggable(defaults?.[i]) + ? (defaults[i] as Pluggable).defaults + : defaults?.[i] as S + return { + id: plugin.id, + state: getDiffsDeep(plugin.state, defaultState ?? plugin.defaults), + defaults: defaultState + ? getDiffsDeep(plugin.defaults, defaultState) + : undefined, + } + }) + } + + function extendPluginsState< + S, + Plugins extends Pluggable | PluggableMap, + >( + plugins: MaybeRef, + states: Record>, + ): Plugins { + plugins = unref(plugins) + const list = Array.isArray(plugins) ? plugins : Object.values(plugins) + for (const plugin of list) merge(plugin.state, states?.[plugin.id]) + return plugins + } + + function mergeArrayWithPlugins( + arr: PluggableReducedItem[], + plugins: MaybeRef>, + mergeFn: typeof clonePlugin = clonePlugin, + ): Pluggable[] { + return arr.reduce((acc, item) => { + const plugin = unref(unref(plugins)[item.id]) + if (plugin) acc.push(mergeFn(plugin, item)) + return acc + }, []) + } + + function clonePlugin( + plugin: Pluggable, + extendWith?: DeepPartialPlugin, + ): Pluggable { + const clone = merge({}, extendWith, toRaw(plugin)) as Pluggable + clone.key = nanoid() + extendState(clone.state, plugin.state, extendWith?.state) + extendState(clone.defaults, plugin.defaults, extendWith?.defaults) + return clone + } + + function extendState( + target: S, + source: S, + extendWith?: DeepPartial, + ): void { + const rawState = toRaw(source) + Object.entries(target).forEach((entry) => { + const [key, value] = entry as [keyof S, unknown] + const originalStateValue = rawState[key] + const extendWithValue = (extendWith as S)?.[key] + + if (isRef(originalStateValue)) { + target[key] = originalStateValue + } else if (typeof value === 'object') { + merge(value, originalStateValue, extendWithValue) + } else if ( + extendWithValue !== undefined || + originalStateValue !== undefined + ) { + target[key] = extendWithValue ?? originalStateValue + } + }) + } + + function getClonePluginCustom

( + apply: (clone: P, plugin: P, extendWith?: P) => void, + ) { + return (plugin: P, extendWith?: DeepPartial

) => { + const clone = clonePlugin(plugin, extendWith) as P + apply(clone, plugin, extendWith as P) + return clone + } + } + + function applyDefaults( + plugins: MaybeRef, + ): Plugins { + plugins = unref(plugins) + const list = Array.isArray(plugins) ? plugins : Object.values(plugins) + for (const plugin of list) plugin.state = cloneDeep(plugin.defaults) + return plugins + } + + return { + isPluggable, + getDiffs, + getDiffsDeep, + getPluggableDiffsArray, + applyDefaults, + extendPluginsState, + mergeArrayWithPlugins, + clonePlugin, + getClonePluginCustom, + extendState, + } +} diff --git a/src/init/initDefaultPanels.ts b/src/init/initDefaultPanels.ts new file mode 100644 index 0000000..9a1053d --- /dev/null +++ b/src/init/initDefaultPanels.ts @@ -0,0 +1,93 @@ +import { usePanelFeature } from '@/features/panel' +import { useControlFeature } from '@/features/control' +import { PanelAlignment, PanelLocation } from '@/features/panel/constants' +import { usePagemapFeature } from '@/features/pagemap' +import { usePlayFeature } from '@/features/play' +import { usePinNoteFeature } from '@/features/pin-note' +import { useSpeedFeature } from '@/features/speed' +import { useTextColorFeature } from '@/features/text-color' +import { useBgColorFeature } from '@/features/bg-color' +import { useLetterSpacingFeature } from '@/features/letter-spacing' +import { useLineHeightFeature } from '@/features/line-height' +import { useOpenSettingsFeature } from '@/features/open-settings' +import { useContentFeature } from '@/features/content' +import { useFontFamilyFeature } from '@/features/font-family' +import { useFontSizeFeature } from '@/features/font-size' +import { usePaddingFeature } from '@/features/padding' +import { useFlipXFeature } from '@/features/flip/flip-x' +import { useFlipYFeature } from '@/features/flip/flip-y' +import type { PluggablePanel } from '@/features/panel/types' + +export function initDefaultPanels() { + const panelFeatureStore = usePanelFeature().useStore() + const { setDefaultPanels, getPanelFromPlugin } = panelFeatureStore + + const controlPanelPlugin = panelFeatureStore.plugins[useControlFeature().id] + const pagemapPanelPlugin = panelFeatureStore.plugins[usePagemapFeature().id] + + const controlPlugins = useControlFeature().useStore().plugins + + const playFeature = usePlayFeature() + const pinNote = usePinNoteFeature() + const speedFeature = useSpeedFeature() + const bgColorFeature = useBgColorFeature() + const textColorFeature = useTextColorFeature() + const lineHeightFeature = useLineHeightFeature() + const letterSpacingFeature = useLetterSpacingFeature() + const paddingFeature = usePaddingFeature() + const openSettingsFeature = useOpenSettingsFeature() + const contentFeature = useContentFeature() + const fontFamilyFeature = useFontFamilyFeature() + const fontSizeFeature = useFontSizeFeature() + const flipXFeature = useFlipXFeature() + const flipYFeature = useFlipYFeature() + + const controlPanelItems = [ + controlPlugins[playFeature.id], + controlPlugins[pinNote.id], + controlPlugins[speedFeature.id], + controlPlugins[fontSizeFeature.id], + controlPlugins[lineHeightFeature.id], + controlPlugins[letterSpacingFeature.id], + controlPlugins[fontFamilyFeature.id], + controlPlugins[paddingFeature.id], + controlPlugins[flipXFeature.id], + controlPlugins[flipYFeature.id], + controlPlugins[textColorFeature.id], + controlPlugins[bgColorFeature.id], + controlPlugins[contentFeature.id], + controlPlugins[openSettingsFeature.id], + ] + + function createPanel(plugin: PluggablePanel, getState: () => object) { + return getPanelFromPlugin(plugin, { + state: getState(), + defaults: getState(), + }) + } + + setDefaultPanels([ + createPanel(controlPanelPlugin, () => ({ + name: 'Control Panel', + location: PanelLocation.TOP, + items: controlPanelItems, + })), + createPanel(controlPanelPlugin, () => ({ + name: 'Control Side-Panel', + location: PanelLocation.LEFT, + alignment: PanelAlignment.CENTER, + width: 250, + isOpen: false, + items: controlPanelItems, + })), + createPanel(pagemapPanelPlugin, () => ({ + name: 'Page Minimap', + })), + createPanel(pagemapPanelPlugin, () => ({ + name: 'Page Minimap Extra', + location: PanelLocation.LEFT, + width: 80, + isOpen: false, + })), + ]) +} diff --git a/src/layout/AppBody.vue b/src/layout/AppBody.vue new file mode 100644 index 0000000..220d77d --- /dev/null +++ b/src/layout/AppBody.vue @@ -0,0 +1,23 @@ + + + + + \ No newline at end of file diff --git a/src/layout/AppPanels.vue b/src/layout/AppPanels.vue new file mode 100644 index 0000000..c304dfa --- /dev/null +++ b/src/layout/AppPanels.vue @@ -0,0 +1,9 @@ + + + diff --git a/src/libs/vuetify.ts b/src/libs/vuetify.ts new file mode 100644 index 0000000..e1eb252 --- /dev/null +++ b/src/libs/vuetify.ts @@ -0,0 +1,59 @@ +import { createVuetify, type VuetifyOptions } from 'vuetify' +import { aliases, mdi } from 'vuetify/iconsets/mdi-svg' + +export interface AppVuetifyOptions { + container?: Element | string +} +export function getVuetifyOptions(options: AppVuetifyOptions = {}) { + const container = + typeof options.container !== 'string' + ? options.container + : { + // this is to avoid vuetify warning about missing container + querySelector: () => + activeDocument.querySelector(options.container as string), + appendChild: (child: Element) => + activeDocument + .querySelector(options.container as string) + ?.appendChild(child), + } + + return { + defaults: { + global: { + ripple: false, + }, + VMenu: { + transition: 'slide-y-transition', + attach: container, + }, + VTooltip: { + transition: 'scale-transition', + attach: container, + }, + VTextField: { + variant: 'plain', + density: 'compact', + }, + VSelect: { + variant: 'plain', + density: 'compact', + }, + VOverlay: { + attach: container, + }, + }, + theme: false, + icons: { + defaultSet: 'mdi', + aliases, + sets: { + mdi, + }, + }, + } as VuetifyOptions +} + +export function createVuetifyWithOptions(options: AppVuetifyOptions) { + return createVuetify(getVuetifyOptions(options)) +} diff --git a/src/plugin.ts b/src/plugin.ts new file mode 100644 index 0000000..af59666 --- /dev/null +++ b/src/plugin.ts @@ -0,0 +1,92 @@ +import { loadFeatures } from '@/features/loader' +import { debounce, MarkdownView, Plugin } from 'obsidian' +import { useOpenSettingsFeature } from './features/open-settings' +import { SettingTab } from './setting-tab' +import { TeleprompterView } from './view' +import { useCommandFeature } from '@/features/commands' +import { toRefs, watchEffect } from 'vue' +import { useContentFeature } from '@/features/content' +import { usePinNoteFeature } from '@/features/pin-note' +import { APP_NAME, VIEW_TYPE } from '@/constants' +import { initDefaultPanels } from '@/init/initDefaultPanels' + +export default class TeleprompterPlugin extends Plugin { + settings: Record = {} + async onload() { + await this.loadSettings() + + this.updateContent() + const updateContentDebounced = debounce(this.updateContent.bind(this), 300) + + this.registerEvent(this.app.vault.on('modify', updateContentDebounced)) + this.registerEvent( + this.app.workspace.on('active-leaf-change', () => { + if (usePinNoteFeature().useStore().value) return + updateContentDebounced() + }), + ) + + this.addRibbonIcon('scroll', APP_NAME, () => { + this.activateView() + }) + + this.addSettingTab(new SettingTab(this.app, this)) + + await this.registerFeatures() + this.registerView(VIEW_TYPE, (leaf) => new TeleprompterView(leaf)) + + // this.app.setting.openTabById('teleprompter') // only while developing + } + + async loadSettings() { + this.settings = Object.assign({}, await this.loadData()) + } + + async saveSettings() { + await this.saveData(this.settings) + } + + async activateView() { + if (this.app.workspace.getLeavesOfType(VIEW_TYPE).length === 0) { + await this.app.workspace.getRightLeaf(false).setViewState({ + type: VIEW_TYPE, + active: true, + }) + } + + this.app.workspace.revealLeaf( + this.app.workspace.getLeavesOfType(VIEW_TYPE)[0], + ) + } + + updateContent() { + const view = this.app.workspace.getActiveViewOfType(MarkdownView) + const content = view?.getViewData() + if (content) useContentFeature().useStore().content = content + } + + async registerFeatures() { + const debouncedSaveSettings = debounce( + () => this.saveSettings(), + 100, + false, + ) + await loadFeatures({ + persist: (id: string, state: any) => { + this.settings[id] = state + debouncedSaveSettings() + }, + restore: (id: string) => this.settings[id], + }) + + useOpenSettingsFeature().addEventListener('click', () => { + this.app.setting.open() + this.app.setting.openTabById('teleprompter') + }) + + const { list: commands } = toRefs(useCommandFeature().useStore()) + watchEffect(() => commands.value.forEach((c) => this.addCommand(c))) + + initDefaultPanels() + } +} diff --git a/src/setting-tab.ts b/src/setting-tab.ts new file mode 100644 index 0000000..181eae8 --- /dev/null +++ b/src/setting-tab.ts @@ -0,0 +1,37 @@ +import { createVuetifyWithOptions } from '@/libs/vuetify' +import SettingsApp from '@/SettingsApp.vue' +import { type App as VueApp, createApp } from 'vue' +import { type App as ObsidianApp, PluginSettingTab } from 'obsidian' +import type TeleprompterPlugin from './plugin' +import {APP_ATTR, APP_CLASS, SETTINGS_CLASS} from '@/constants' + +export class SettingTab extends PluginSettingTab { + plugin: TeleprompterPlugin + vueapp: VueApp + constructor(app: ObsidianApp, plugin: TeleprompterPlugin) { + super(app, plugin) + this.plugin = plugin + } + + display(): void { + const { containerEl } = this + + containerEl.empty() + const div = containerEl.createDiv() + + if (!containerEl.hasClass(SETTINGS_CLASS)) { + containerEl.classList.add(APP_CLASS) + containerEl.classList.add(SETTINGS_CLASS) + containerEl.setAttribute(APP_ATTR, '') + } + + this.vueapp = createApp(SettingsApp) + + this.vueapp.use( + createVuetifyWithOptions({ + container: `.${SETTINGS_CLASS}`, + }), + ) + this.vueapp.mount(div) + } +} diff --git a/src/styles/index.scss b/src/styles/index.scss new file mode 100644 index 0000000..baea51d --- /dev/null +++ b/src/styles/index.scss @@ -0,0 +1,236 @@ +$color-pack: false; +$reset: false; +$body-font-family: #{var(--font-default)}; + +body { + --v-high-emphasis-opacity: 0.9; + --v-border-opacity: 0.1; + --v-hover-opacity: 0.08; + --v-activated-opacity: 0.12; + --v-theme-overlay-multiplier: 1; + --v-border-color: var(--mono-rgb-100); + --v-focus-opacity: 0.1; + --v-pressed-opacity: 0.2; +} + +@import 'vuetify/styles'; + +@import 'vuetify/lib/components/VLocaleProvider/VLocaleProvider'; +@import 'vuetify/lib/components/VSelectionControl/VSelectionControl'; +@import 'vuetify/lib/components/VSelectionControlGroup/VSelectionControlGroup'; +@import 'vuetify/lib/components/VLayout/VLayout'; +@import 'vuetify/lib/components/VLayout/VLayoutItem'; +@import 'vuetify/lib/components/VApp/VApp'; +@import 'vuetify/lib/components/VAppBar/VAppBar'; +@import 'vuetify/lib/components/VTooltip/VTooltip'; +@import 'vuetify/lib/components/VWindow/VWindow'; +@import 'vuetify/lib/components/VBtn/VBtn'; +@import 'vuetify/lib/components/VColorPicker/VColorPicker'; +@import 'vuetify/lib/components/VColorPicker/VColorPickerCanvas'; +@import 'vuetify/lib/components/VColorPicker/VColorPickerEdit'; +@import 'vuetify/lib/components/VColorPicker/VColorPickerPreview'; +@import 'vuetify/lib/components/VColorPicker/VColorPickerSwatches'; +@import 'vuetify/lib/components/VTextField/VTextField'; +@import 'vuetify/lib/components/VMenu/VMenu'; +@import 'vuetify/lib/components/VBadge/VBadge'; +@import 'vuetify/lib/components/VCard/VCard'; +@import 'vuetify/lib/components/VIcon/VIcon'; +@import 'vuetify/lib/components/VList/VList'; +@import 'vuetify/lib/components/VList/VListItem'; +@import 'vuetify/lib/components/VMain/VMain'; +@import 'vuetify/lib/components/VNavigationDrawer/VNavigationDrawer'; +@import 'vuetify/lib/components/VSelect/VSelect'; +@import 'vuetify/lib/components/VSlider/VSlider'; +@import 'vuetify/lib/components/VSlider/VSliderTrack'; +@import 'vuetify/lib/components/VSlider/VSliderThumb'; +@import 'vuetify/lib/components/VTabs/VTabs'; +@import 'vuetify/lib/components/VTabs/VTab'; +@import 'vuetify/lib/components/VSwitch/VSwitch'; +@import 'vuetify/lib/components/VExpansionPanel/VExpansionPanel'; +@import 'vuetify/lib/components/VDivider/VDivider'; +@import 'vuetify/lib/components/VOverlay/VOverlay'; +@import 'vuetify/lib/components/VField/VField'; +@import 'vuetify/lib/components/VAvatar/VAvatar'; +@import 'vuetify/lib/components/VToolbar/VToolbar'; +@import 'vuetify/lib/components/VLabel/VLabel'; +@import 'vuetify/lib/components/VCheckbox/VCheckbox'; +@import 'vuetify/lib/components/VInput/VInput'; +@import 'vuetify/lib/components/VGrid/VGrid'; +@import 'vuetify/lib/components/VImg/VImg'; +@import 'vuetify/lib/components/VItemGroup/VItemGroup'; +@import 'vuetify/lib/components/VSheet/VSheet'; +//@import 'vuetify/lib/components/VChip/VChip'; +//@import 'vuetify/lib/components/VChipGroup/VChipGroup'; + +*, +::before, +::after { + background-repeat: no-repeat; + box-sizing: inherit; +} + +button, +[type='button'], +[type='reset'], +[type='submit'], +[role='button'] { + cursor: pointer; + color: inherit; +} + +.v-menu > .v-overlay__content > .v-card, +.v-menu > .v-overlay__content > .v-sheet, +.v-menu > .v-overlay__content > .v-list, +.v-sheet { + background: var(--color-base-10); +} + +.v-slider-track__fill { + background: var(--color-base-100); +} + +.v-slider-track__background { + background: var(--color-base-60); +} + +.v-divider { + opacity: 1 !important; +} + +.v-select { +} + +.v-input__control { +} + +.v-tooltip { + z-index: var(--layer-tooltip); + + .v-overlay__content { + max-width: 400px; + display: block; + text-align: center; + white-space: pre-line; + + background: rgba(#000000, 0.9); + color: white; + border-radius: var(--radius-s); + font-size: var(--font-smaller); + font-weight: var(--bold-weight); + padding: calc(var(--tag-padding-y) * 1.5) calc(var(--tag-padding-x) * 1.5); + text-transform: none; + text-transform: initial; + width: auto; + transition-duration: var(--anim-duration-moderate) !important; + transition-timing-function: var(--anim-motion-jumpy) !important; + transform-origin: center center !important; + } + + &:not(.v-overlay--active) .v-overlay__content { + opacity: 0; + transition: none; + } +} + +.v-btn { + text-transform: none; + letter-spacing: normal; + box-shadow: none; + &:hover, + &:active, + &:focus-within { + box-shadow: none; + } +} + +.v-slider-thumb__label { + &:before { + color: var(--color-base-70); + } + background: var(--color-base-70); + color: var(--color-base-00); +} + +.text-accent { + color: var(--text-accent); +} + +.drag-handle { + cursor: grab; + &:active { + cursor: grabbing; + } +} + +.v-switch { + .v-switch__thumb { + background: var(--color-base-70); + color: var(--color-base-70); + &.bg-accent { + background: var(--checkbox-color); + color: var(--checkbox-color); + } + } + .v-switch__track { + background: var(--color-base-70); + &.bg-accent { + background: var(--checkbox-color); + } + } +} + +.v-field, +.v-field.v-field--variant-plain { + --v-field-padding-top: 0; + --v-field-padding-bottom: 0; + --v-field-input-padding-bottom: 0; + --v-field-input-padding-top: 0; + --v-field-padding-end: 5px; + --v-field-padding-start: 5px; + --v-input-control-height: var(--input-height); + + background: var(--background-modifier-form-field); + border: var(--input-border-width) solid var(--background-modifier-border); + color: var(--text-normal); + font-family: inherit; + padding: var(--size-4-1) var(--size-4-2); + font-size: var(--font-ui-small); + border-radius: var(--input-radius); + outline: none; + transition: 0.15s opacity cubic-bezier(0.4, 0, 0.2, 1); + transition-property: opacity, border-color, box-shadow; + + &.v-field--focused { + box-shadow: 0 0 0 2px var(--background-modifier-border-focus); + } + + &:hover { + border-color: var(--background-modifier-border-hover); + } + + .v-field__input { + padding-top: 0; + align-items: center; + align-self: center; + height: var(--v-input-control-height); + + --v-input-chips-margin-top: 4px; + --v-input-chips-margin-bottom: 4px; + } + + .v-field-label { + margin: auto; + top: 0; + bottom: 0; + } + + input { + background: transparent; + border: none; + box-shadow: none; + } + + .v-field__append-inner { + align-items: center; + } +} diff --git a/src/utils/createInjectionState/index.ts b/src/utils/createInjectionState/index.ts new file mode 100644 index 0000000..dafb52c --- /dev/null +++ b/src/utils/createInjectionState/index.ts @@ -0,0 +1,31 @@ +import { type InjectionKey, inject, provide } from 'vue' + +/** + * Create global state that can be injected into components. + * + * This is a modified version of the same package in vueuse. + * The difference is that in this version you don't get the + * ``` + * [Vue warn]: injection "Symbol(InjectionState)" not found. + * ``` + * warning when you try to inject the state before it has been + * provided. It's achieved by providing `undefined` as the default value + * for the injection. + * + * @see https://vueuse.org/createInjectionState + */ +export function createInjectionState, Return>( + composable: (...args: Arguments) => Return, +): readonly [ + useProvidingState: (...args: Arguments) => Return, + useInjectedState: () => Return | undefined, +] { + const key: string | InjectionKey = Symbol('InjectionState') + const useProvidingState = (...args: Arguments) => { + const state = composable(...args) + provide(key, state) + return state + } + const useInjectedState = () => inject(key, undefined) + return [useProvidingState, useInjectedState] +} diff --git a/src/utils/createStateAccessor/createStateAccessor.ts b/src/utils/createStateAccessor/createStateAccessor.ts new file mode 100644 index 0000000..c27e2cb --- /dev/null +++ b/src/utils/createStateAccessor/createStateAccessor.ts @@ -0,0 +1,26 @@ +import { type Ref, ref } from 'vue' + +export function createStateAccessor( + initial: T, + options: { + onGet?: (value: T) => T + onSet?: (value: T) => void + } = {}, +) { + const state = ref(initial) as Ref + + function set(value: T) { + state.value = value + options.onSet?.(value) + } + + function get(): T { + const value = state.value + return options.onGet?.(value) ?? value + } + + return { + set, + get, + } +} diff --git a/src/utils/defaultTo/index.ts b/src/utils/defaultTo/index.ts new file mode 100644 index 0000000..307ebbd --- /dev/null +++ b/src/utils/defaultTo/index.ts @@ -0,0 +1,26 @@ +/** + * Returns the first argument if it's not `undefined`, otherwise the second. + * @param value + * @param defaultValue + * @example + * defaultTo('foo', 'bar') // 'foo' + * defaultTo(undefined, 'bar') // 'bar' + * defaultTo(() => 'foo', 'bar') // 'foo' + * defaultTo(() => undefined, 'bar') // 'bar' + * defaultTo(() => undefined, () => 'bar') // 'bar' + */ +export function defaultTo( + value: T | (() => T), + defaultValue?: T | (() => T), +): T | undefined { + try { + const result = resolve(value) + return result === undefined ? resolve(defaultValue) : result + } catch (e) { + return resolve(defaultValue) + } +} + +function resolve(value: T | (() => T)): T { + return typeof value === 'function' ? (value as () => T)() : value +} diff --git a/src/utils/genUniqueName/index.ts b/src/utils/genUniqueName/index.ts new file mode 100644 index 0000000..dfa90a8 --- /dev/null +++ b/src/utils/genUniqueName/index.ts @@ -0,0 +1,24 @@ +/** + * Generate a unique name based on the default name and existing names. + * @param defaultName + * @param existingNames + * @example + * genUniqueName('Panel', []) // 'Panel' + * genUniqueName('Panel', ['Panel']) // 'Panel 1' + * genUniqueName('Panel', ['Panel', 'Panel 1']) // 'Panel 2' + * genUniqueName('Panel', ['Panel', 'Panel 84', 'Panel 56']) // 'Panel 85' + */ +export function genUniqueName( + defaultName: string, + existingNames: string[], +): string { + const nums = existingNames.map((name) => { + const regex = new RegExp(`^${defaultName} (\\d+)$`, 'i') + return +regex.exec(name)?.[1] || 0 + }) + + const max = nums.length ? Math.max(...nums) : 0 + return !max && !existingNames.find((name) => name === defaultName) + ? defaultName + : `${defaultName} ${max + 1}` +} diff --git a/src/utils/utility-types.ts b/src/utils/utility-types.ts new file mode 100644 index 0000000..ffd0ff1 --- /dev/null +++ b/src/utils/utility-types.ts @@ -0,0 +1,7 @@ +export type Modify = Omit & R + +export type DeepPartial = T extends object + ? { + [P in keyof T]?: DeepPartial + } + : T diff --git a/src/view.ts b/src/view.ts new file mode 100644 index 0000000..14711f3 --- /dev/null +++ b/src/view.ts @@ -0,0 +1,54 @@ +import { ItemView, type WorkspaceLeaf } from 'obsidian' +import { type App as VueApp, createApp } from 'vue' +import App from './App.vue' +import { createVuetifyWithOptions } from './libs/vuetify' +import { + APP_ATTR, + APP_CLASS, + APP_NAME, + VIEW_CLASS, + VIEW_TYPE +} from '@/constants' + +export class TeleprompterView extends ItemView { + vueapp: VueApp + constructor(leaf: WorkspaceLeaf) { + super(leaf) + } + getViewType(): string { + return VIEW_TYPE + } + getDisplayText(): string { + return APP_NAME + } + getIcon(): string { + return 'scroll' + } + async onOpen() { + const { contentEl, containerEl } = this + contentEl.empty() + const div = contentEl.createDiv() + + if (!containerEl.hasClass(APP_CLASS)) { + containerEl.classList.add(APP_CLASS) + containerEl.classList.add(VIEW_CLASS) + containerEl.setAttribute(APP_ATTR, '') + } + + contentEl.style.padding = '0' + div.style.height = '100%' + + this.vueapp = createApp(App) + this.vueapp.use( + createVuetifyWithOptions({ + container: `.${VIEW_CLASS}`, + }), + ) + + setTimeout(() => this.vueapp.mount(div)) + } + + async onClose() { + this.vueapp?.unmount() + } +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..ccaf632 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "inlineSourceMap": true, + "inlineSources": true, + "module": "esnext", + "target": "es6", + "allowJs": true, + "noImplicitAny": true, + "moduleResolution": "node", + "allowSyntheticDefaultImports": true, + "importHelpers": false, + "isolatedModules": true, + "paths": { + "@/*": ["src/*"] + }, + "lib": ["dom", "es6", "scripthost", "es2022"], + "types": ["vite/client"] + }, + "include": ["**/*.ts", "**/*.vue"] +} diff --git a/vite.config.js b/vite.config.js new file mode 100644 index 0000000..381139a --- /dev/null +++ b/vite.config.js @@ -0,0 +1,41 @@ +import path from 'path' +import { defineConfig } from 'vite' +import vue from '@vitejs/plugin-vue' +import vuetify from 'vite-plugin-vuetify' + +export default defineConfig({ + plugins: [ + vue(), + vuetify({ styles: 'none', autoImport: true }), + ], + resolve: { + alias: { + '@': path.resolve(__dirname, './src'), + }, + }, + build: { + minify: false, + // Use Vite lib mode https://vitejs.dev/guide/build.html#library-mode + lib: { + entry: path.resolve(__dirname, './src/plugin.ts'), + formats: ['cjs'], + }, + rollupOptions: { + output: { + // Overwrite default Vite output fileName + entryFileNames: 'main.js', + assetFileNames: 'styles.css', + }, + external: ['obsidian'], + }, + emptyOutDir: false, // otherwise data.json that obsidian creates will get deleted on every change + outDir: './dist', + }, + define: { + document: 'activeDocument', + // window: 'activeWindow', + setTimeout: 'activeWindow.setTimeout', + setInterval: 'activeWindow.setInterval', + requestAnimationFrame: 'activeWindow.requestAnimationFrame', + } +})