source 90cbbd1ae1db cached
51 files
124.3 KB
30.3k tokens
53 symbols
1 requests
Download .txt
Repository: genesy/karabiner-complex-rules-generator
Branch: source
Commit: 90cbbd1ae1db
Files: 51
Total size: 124.3 KB

Directory structure:
gitextract_7_26yhlx/

├── .eslintrc
├── .gitignore
├── .prettierrc
├── LICENSE
├── README.md
├── package.json
├── public/
│   ├── index.html
│   ├── manifest.json
│   └── robots.txt
├── src/
│   ├── App.css
│   ├── App.test.tsx
│   ├── App.tsx
│   ├── AppLayout.tsx
│   ├── components/
│   │   ├── MainForm.tsx
│   │   ├── forms/
│   │   │   ├── AddConditionForm.tsx
│   │   │   ├── DeviceIfConditionForm.tsx
│   │   │   ├── EventChangedConditionForm.tsx
│   │   │   ├── FromEventForm.tsx
│   │   │   ├── FrontmostConditionForm.tsx
│   │   │   ├── InputSourceConditionForm.tsx
│   │   │   ├── KeyboardTypeConditionForm.tsx
│   │   │   ├── ManipulatorForm.tsx
│   │   │   ├── RuleForm.tsx
│   │   │   ├── ToEventForm.tsx
│   │   │   ├── ToEventFormsContainer.tsx
│   │   │   └── VariableConditionForm.tsx
│   │   └── shared/
│   │       ├── AppExpansionPanel.tsx
│   │       ├── AppSelect.tsx
│   │       ├── KeyCodeAndPointingButtonInput.tsx
│   │       └── KeyInput.tsx
│   ├── constants.ts
│   ├── ducks/
│   │   └── formState.ts
│   ├── helpers.ts
│   ├── index.css
│   ├── index.tsx
│   ├── react-app-env.d.ts
│   ├── serviceWorker.ts
│   ├── setupTests.ts
│   └── types/
│       ├── ICondition.ts
│       ├── IFormState.ts
│       ├── IFromEventDefinition.ts
│       ├── IManipulator.ts
│       ├── IMouseKey.ts
│       ├── IRule.ts
│       ├── ISimultaneous.ts
│       ├── IToEventDefinition.ts
│       ├── KeyOrder.ts
│       ├── KeyUpWhen.ts
│       ├── Modifier.ts
│       └── PointingButton.ts
└── tsconfig.json

================================================
FILE CONTENTS
================================================

================================================
FILE: .eslintrc
================================================
{
  "rules": {
    "react-hooks/exhaustive-deps": false
  }
}


================================================
FILE: .gitignore
================================================
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*


================================================
FILE: .prettierrc
================================================
{
  "semi": true,
  "singleQuote": true,
  "trailingComma": "all"
}


================================================
FILE: LICENSE
================================================
                    GNU GENERAL PUBLIC LICENSE
                       Version 3, 29 June 2007

 Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

                            Preamble

  The GNU General Public License is a free, copyleft license for
software and other kinds of works.

  The licenses for most software and other practical works are designed
to take away your freedom to share and change the works.  By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.  We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors.  You can apply it to
your programs, too.

  When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.

  To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights.  Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.

  For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received.  You must make sure that they, too, receive
or can get the source code.  And you must show them these terms so they
know their rights.

  Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.

  For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software.  For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.

  Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so.  This is fundamentally incompatible with the aim of
protecting users' freedom to change the software.  The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable.  Therefore, we
have designed this version of the GPL to prohibit the practice for those
products.  If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.

  Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary.  To prevent this, the GPL assures that
patents cannot be used to render the program non-free.

  The precise terms and conditions for copying, distribution and
modification follow.

                       TERMS AND CONDITIONS

  0. Definitions.

  "This License" refers to version 3 of the GNU General Public License.

  "Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.

  "The Program" refers to any copyrightable work licensed under this
License.  Each licensee is addressed as "you".  "Licensees" and
"recipients" may be individuals or organizations.

  To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy.  The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.

  A "covered work" means either the unmodified Program or a work based
on the Program.

  To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy.  Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.

  To "convey" a work means any kind of propagation that enables other
parties to make or receive copies.  Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.

  An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License.  If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.

  1. Source Code.

  The "source code" for a work means the preferred form of the work
for making modifications to it.  "Object code" means any non-source
form of a work.

  A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.

  The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form.  A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.

  The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities.  However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work.  For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.

  The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.

  The Corresponding Source for a work in source code form is that
same work.

  2. Basic Permissions.

  All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met.  This License explicitly affirms your unlimited
permission to run the unmodified Program.  The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work.  This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.

  You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force.  You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright.  Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.

  Conveying under any other circumstances is permitted solely under
the conditions stated below.  Sublicensing is not allowed; section 10
makes it unnecessary.

  3. Protecting Users' Legal Rights From Anti-Circumvention Law.

  No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.

  When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.

  4. Conveying Verbatim Copies.

  You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.

  You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.

  5. Conveying Modified Source Versions.

  You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:

    a) The work must carry prominent notices stating that you modified
    it, and giving a relevant date.

    b) The work must carry prominent notices stating that it is
    released under this License and any conditions added under section
    7.  This requirement modifies the requirement in section 4 to
    "keep intact all notices".

    c) You must license the entire work, as a whole, under this
    License to anyone who comes into possession of a copy.  This
    License will therefore apply, along with any applicable section 7
    additional terms, to the whole of the work, and all its parts,
    regardless of how they are packaged.  This License gives no
    permission to license the work in any other way, but it does not
    invalidate such permission if you have separately received it.

    d) If the work has interactive user interfaces, each must display
    Appropriate Legal Notices; however, if the Program has interactive
    interfaces that do not display Appropriate Legal Notices, your
    work need not make them do so.

  A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit.  Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.

  6. Conveying Non-Source Forms.

  You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:

    a) Convey the object code in, or embodied in, a physical product
    (including a physical distribution medium), accompanied by the
    Corresponding Source fixed on a durable physical medium
    customarily used for software interchange.

    b) Convey the object code in, or embodied in, a physical product
    (including a physical distribution medium), accompanied by a
    written offer, valid for at least three years and valid for as
    long as you offer spare parts or customer support for that product
    model, to give anyone who possesses the object code either (1) a
    copy of the Corresponding Source for all the software in the
    product that is covered by this License, on a durable physical
    medium customarily used for software interchange, for a price no
    more than your reasonable cost of physically performing this
    conveying of source, or (2) access to copy the
    Corresponding Source from a network server at no charge.

    c) Convey individual copies of the object code with a copy of the
    written offer to provide the Corresponding Source.  This
    alternative is allowed only occasionally and noncommercially, and
    only if you received the object code with such an offer, in accord
    with subsection 6b.

    d) Convey the object code by offering access from a designated
    place (gratis or for a charge), and offer equivalent access to the
    Corresponding Source in the same way through the same place at no
    further charge.  You need not require recipients to copy the
    Corresponding Source along with the object code.  If the place to
    copy the object code is a network server, the Corresponding Source
    may be on a different server (operated by you or a third party)
    that supports equivalent copying facilities, provided you maintain
    clear directions next to the object code saying where to find the
    Corresponding Source.  Regardless of what server hosts the
    Corresponding Source, you remain obligated to ensure that it is
    available for as long as needed to satisfy these requirements.

    e) Convey the object code using peer-to-peer transmission, provided
    you inform other peers where the object code and Corresponding
    Source of the work are being offered to the general public at no
    charge under subsection 6d.

  A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.

  A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling.  In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage.  For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product.  A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.

  "Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source.  The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.

  If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information.  But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).

  The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed.  Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.

  Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.

  7. Additional Terms.

  "Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law.  If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.

  When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it.  (Additional permissions may be written to require their own
removal in certain cases when you modify the work.)  You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.

  Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:

    a) Disclaiming warranty or limiting liability differently from the
    terms of sections 15 and 16 of this License; or

    b) Requiring preservation of specified reasonable legal notices or
    author attributions in that material or in the Appropriate Legal
    Notices displayed by works containing it; or

    c) Prohibiting misrepresentation of the origin of that material, or
    requiring that modified versions of such material be marked in
    reasonable ways as different from the original version; or

    d) Limiting the use for publicity purposes of names of licensors or
    authors of the material; or

    e) Declining to grant rights under trademark law for use of some
    trade names, trademarks, or service marks; or

    f) Requiring indemnification of licensors and authors of that
    material by anyone who conveys the material (or modified versions of
    it) with contractual assumptions of liability to the recipient, for
    any liability that these contractual assumptions directly impose on
    those licensors and authors.

  All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10.  If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term.  If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.

  If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.

  Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.

  8. Termination.

  You may not propagate or modify a covered work except as expressly
provided under this License.  Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).

  However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.

  Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.

  Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License.  If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.

  9. Acceptance Not Required for Having Copies.

  You are not required to accept this License in order to receive or
run a copy of the Program.  Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance.  However,
nothing other than this License grants you permission to propagate or
modify any covered work.  These actions infringe copyright if you do
not accept this License.  Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.

  10. Automatic Licensing of Downstream Recipients.

  Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License.  You are not responsible
for enforcing compliance by third parties with this License.

  An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations.  If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.

  You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License.  For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.

  11. Patents.

  A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based.  The
work thus licensed is called the contributor's "contributor version".

  A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version.  For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.

  Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.

  In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement).  To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.

  If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients.  "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.

  If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.

  A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License.  You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.

  Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.

  12. No Surrender of Others' Freedom.

  If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all.  For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.

  13. Use with the GNU Affero General Public License.

  Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work.  The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.

  14. Revised Versions of this License.

  The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

  Each version is given a distinguishing version number.  If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation.  If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.

  If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.

  Later license versions may give you additional or different
permissions.  However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.

  15. Disclaimer of Warranty.

  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

  16. Limitation of Liability.

  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.

  17. Interpretation of Sections 15 and 16.

  If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.

                     END OF TERMS AND CONDITIONS

            How to Apply These Terms to Your New Programs

  If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.

  To do so, attach the following notices to the program.  It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.

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:

    <program>  Copyright (C) <year>  <name of author>
    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
<https://www.gnu.org/licenses/>.

  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
<https://www.gnu.org/licenses/why-not-lgpl.html>.


================================================
FILE: README.md
================================================
[![Forks][forks-shield]][forks-url]
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]

<!-- PROJECT LOGO -->
<br />
<p align="center">
  <!-- <a href="https://github.com/genesy/karabiner-complex-rules-generator/">
    <img src="./logo.png" alt="Logo" width="80" height="80">
  </a> -->

  <h3 align="center">Karabiner Complex Rules Generator</h3>

  <p align="center">
    <a href="https://genesy.github.io/karabiner-complex-rules-generator/">View Demo</a>
    ·
    <a href="https://github.com/genesy/karabiner-complex-rules-generator/issues">Report Bug</a>
    ·
    <a href="https://github.com/genesy/karabiner-complex-rules-generator/issues">Request Feature</a>
    ·
    <a href="https://github.com/genesy/karabiner-complex-rules-generator/pulls">Send a Pull Request</a>
  </p>
</p>

<!-- TABLE OF CONTENTS -->

## Table of Contents

- [Table of Contents](#table-of-contents)
- [About The Project](#about-the-project)
  - [Built With](#built-with)
- [Getting Started](#getting-started)
  - [Prerequisites](#prerequisites)
  - [Installation](#installation)
- [Roadmap](#roadmap)
- [Contributing](#contributing)
- [License](#license)
- [Contact](#contact)
- [Acknowledgements](#acknowledgements)

<!-- ABOUT THE PROJECT -->

## About The Project

![Product Name Screen Shot](https://i.imgur.com/fCHYLzi.gif)

An open-source web app to help make and configure karabiner complex modification files!

### Built With

- ReactJS
- Material UI

<!-- GETTING STARTED -->

## Getting Started

### Prerequisites

- yarn

```sh
npm install yarn -g
```

### Installation

1. Clone the project

```sh
git clone https://github.com/genesy/karabiner-complex-rules-generator.git
```

2. Install NPM packages

```sh
yarn install
```

<!-- USAGE EXAMPLES -->

<!-- ## Usage -->

<!-- Use this space to show useful examples of how a project can be used. Additional screenshots, code examples and demos work well in this space. You may also link to more resources.

_For more examples, please refer to the [Documentation](https://example.com)_ -->

<!-- ROADMAP -->

## Roadmap

See the [open issues](https://github.com/genesy/karabiner-complex-rules-generator/issues) for a list of proposed features (and known issues).

<!-- CONTRIBUTING -->

## Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **extremely appreciated**.

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

<!-- LICENSE -->

## License

Distributed under the GNUv3 License. See `LICENSE` for more information.

<!-- CONTACT -->

## Contact

Gene Sy - [@GeneSy](https://twitter.com/GeneSy) - gnsyftw@gmail.com

Project Link: [https://github.com/genesy/karabiner-complex-rules-generator/](https://github.com/genesy/karabiner-complex-rules-generator/)

<!-- ACKNOWLEDGEMENTS -->

## Acknowledgements

- [Img Shields](https://shields.io)
- [GitHub Pages](https://pages.github.com)
- [Karabiner Elements](https://pqrs.org/osx/karabiner/)

<!-- MARKDOWN LINKS & IMAGES -->
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->

[forks-shield]: https://img.shields.io/github/forks/genesy/karabiner-complex-rules-generator?style=for-the-badge
[forks-url]: https://github.com/genesy/karabiner-complex-rules-generator/network/members
[stars-shield]: https://img.shields.io/github/stars/genesy/karabiner-complex-rules-generator?style=for-the-badge
[stars-url]: https://github.com/genesy/karabiner-complex-rules-generator/stargazers
[issues-shield]: https://img.shields.io/github/issues/genesy/karabiner-complex-rules-generator?style=for-the-badge
[issues-url]: https://github.com/genesy/karabiner-complex-rules-generator/issues
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=flat-square&logo=linkedin&colorB=555
[linkedin-url]: https://linkedin.com/in/roshan-lamichhane


================================================
FILE: package.json
================================================
{
  "name": "karabiner-complex-rules-generator",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^4.9.3",
    "@material-ui/icons": "^4.9.1",
    "@material-ui/lab": "^4.0.0-alpha.43",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "@types/jest": "^24.9.1",
    "@types/lodash": "^4.14.149",
    "@types/node": "^12.12.28",
    "@types/react": "^16.9.22",
    "@types/react-dom": "^16.9.5",
    "@types/react-redux": "^7.1.7",
    "immer": "^5.3.6",
    "lodash": "^4.17.15",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-redux": "^7.2.0",
    "react-scripts": "3.4.0",
    "redux": "^4.0.5",
    "typeface-roboto": "^0.0.75",
    "typescript": "^3.7.5"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "predeploy": "npm run build",
    "deploy": "gh-pages -b master -d build"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "homepage": "https://genesy.github.io/karabiner-complex-rules-generator",
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@types/material-ui": "^0.21.7",
    "gh-pages": "^2.2.0"
  }
}


================================================
FILE: public/index.html
================================================
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="description"
      content="Web site created using create-react-app"
    />
    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
    <!--
      manifest.json provides metadata used when your web app is installed on a
      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
    -->
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
    <!--
      Notice the use of %PUBLIC_URL% in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    -->
    <title>Karabiner Complex Rules Generator</title>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script
      async
      src="https://www.googletagmanager.com/gtag/js?id=UA-159092454-1"
    ></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag() {
        dataLayer.push(arguments);
      }
      gtag('js', new Date());

      gtag('config', 'UA-159092454-1');
    </script>
    <script async defer src="https://buttons.github.io/buttons.js"></script>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
  </body>
</html>


================================================
FILE: public/manifest.json
================================================
{
  "short_name": "React App",
  "name": "Create React App Sample",
  "icons": [
    {
      "src": "favicon.ico",
      "sizes": "64x64 32x32 24x24 16x16",
      "type": "image/x-icon"
    },
    {
      "src": "logo192.png",
      "type": "image/png",
      "sizes": "192x192"
    },
    {
      "src": "logo512.png",
      "type": "image/png",
      "sizes": "512x512"
    }
  ],
  "start_url": ".",
  "display": "standalone",
  "theme_color": "#000000",
  "background_color": "#ffffff"
}


================================================
FILE: public/robots.txt
================================================
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:


================================================
FILE: src/App.css
================================================
html,
body,
#root,
.App {
  height: 100%;
}

textarea {
  /* height: 80%; */
  width: 100%;
  font-size: 12px;
  background: #ddd;
  font-family: 'Courier New', Courier, monospace;
  /* min-height: 400px; */
}
.generated-code {
  height: 300px;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: scroll;
}

.MuiExpansionPanel-root {
  background-color: rgba(0, 0, 0, 0.05) !important;
}

.MuiExpansionPanel-root:hover {
  background-color: rgba(0, 0, 0, 0.08) !important;
}

.form-wrapper {
  max-height: calc(100vh - 57px);
  overflow: auto;
  position: relative;
}


================================================
FILE: src/App.test.tsx
================================================
import React from 'react';
import { render } from '@testing-library/react';
import App from './App';

test('renders learn react link', () => {
  const { getByText } = render(<App />);
  const linkElement = getByText(/learn react/i);
  expect(linkElement).toBeInTheDocument();
});


================================================
FILE: src/App.tsx
================================================
import React from 'react';
import './App.css';
import '@material-ui/core';
import 'typeface-roboto';
import AppLayout from './AppLayout';
import { formStateReducer } from './ducks/formState';
import { createStore } from 'redux';
import { Provider } from 'react-redux';

const store = createStore(formStateReducer);

function App() {
  return (
    <Provider store={store}>
      <div className="App">
        <AppLayout />
      </div>
    </Provider>
  );
}

export default App;


================================================
FILE: src/AppLayout.tsx
================================================
import React from 'react';
import {
  Container,
  AppBar,
  Typography,
  Toolbar,
  Grid,
  Box,
} from '@material-ui/core';

import MainForm from './components/MainForm';

interface Props {}

const AppLayout: React.FC<Props> = () => {
  return (
    <>
      <AppBar position="static">
        <Container>
          <Toolbar variant="dense">
            <Grid xs item>
              <Typography>
                Karabiner Complex Modification | Still a work in progress
              </Typography>
            </Grid>
            <Grid xs={3} item container justify="flex-end">
              <a
                className="github-button"
                href="https://github.com/genesy/karabiner-complex-rules-generator"
                data-icon="octicon-star"
                data-size="large"
                data-show-count="true"
                aria-label="Star genesy/karabiner-complex-rules-generator on GitHub"
              >
                Star
              </a>
            </Grid>
          </Toolbar>
        </Container>
      </AppBar>
      <Box marginTop={1}>
        <MainForm />
      </Box>
    </>
  );
};

export default AppLayout;


================================================
FILE: src/components/MainForm.tsx
================================================
import React, { useMemo, useEffect } from 'react';
import RuleForm from './forms/RuleForm';
import {
  Grid,
  Button,
  TextField,
  Box,
  Container,
  ButtonGroup,
  Typography,
} from '@material-ui/core';
import AddIcon from '@material-ui/icons/Add';
import _ from 'lodash';
import IRule from '../types/IRule';
import IManipulator from '../types/IManipulator';
import IFromEventDefinition from '../types/IFromEventDefinition';
import IToEventDefinition from '../types/IToEventDefinition';
import { useDispatch, useSelector } from 'react-redux';
import { addRule, setTitle, setWholeState } from '../ducks/formState';
import IFormState from '../types/IFormState';
import { ALL_KEYS } from '../constants';

interface Props {}
interface FormState {
  title: string;
  rules: any[];
}
// TODO: move to separate file
const toFields: string[] = [
  'to',
  'to_if_alone',
  'to_if_held_down',
  'to_after_key_up',
];

const parseJSONfirst = (text: any) => {
  let parsedJSON;
  if (typeof text === 'string') {
    parsedJSON = JSON.parse(text);
  } else if (typeof text === 'object') {
    parsedJSON = { ...text };
  }
  parsedJSON.rules = parsedJSON.rules.map((rule: any) => {
    rule.description = rule.description || '';
    rule.manipulators = rule.manipulators || [];
    rule.manipulators = rule.manipulators.map((manipulator: any) => {
      manipulator.type = manipulator.type || 'basic';
      manipulator.from = manipulator.from || {
        modifiers: {
          mandatory: [],
          optional: [],
        },
        simultaneous: [],
        simultaneous_options: {
          detect_key_down_uninterruptedly: false,
          to_after_key_up: [],
        },
      };
      if (typeof manipulator.from.key_code === 'string') {
        const kc = manipulator.from.key_code;
        manipulator.from.key_code = _.find(ALL_KEYS, { value: kc }) || {
          label: kc,
          value: kc,
        };
      }
      manipulator.conditions = manipulator.conditions || [];
      manipulator.to = manipulator.to || [];
      manipulator.to_after_key_up = manipulator.to_after_key_up || [];
      manipulator.to_if_alone = manipulator.to_if_alone || [];
      manipulator.to_if_held_down = manipulator.to_if_held_down || [];
      manipulator.to_delayed_action = manipulator.to_delayed_action || {
        to_if_invoked: [],
        to_if_canceled: [],
      };
      return manipulator;
    });
    return rule;
  });

  return parsedJSON;
};
const parseKey = (key: any) =>
  typeof key === 'string' ? key : key.value || '';

const parseKeys = (modifiers: any[]) => {
  return modifiers.map(parseKey);
};

const parseFromObject = (fromObject: IFromEventDefinition): any => {
  const _from = { ...fromObject };
  if (_.isEmpty(_from)) {
    return;
  }

  if (typeof _from.key_code === 'object') {
    _from.key_code = parseKey(_from.key_code);
  }
  if (_from.modifiers) {
    if (_from.modifiers.mandatory) {
      if (_from.modifiers.mandatory?.length === 0) {
        delete _from.modifiers.mandatory;
      } else {
        if (typeof _from.modifiers.mandatory === 'string') {
          _from.modifiers.mandatory = [_from.modifiers.mandatory];
        }
        _from.modifiers.mandatory = parseKeys(_from.modifiers.mandatory);
      }
    }
    if (_from.modifiers.optional) {
      if (_from.modifiers.optional.length === 0) {
        delete _from.modifiers.optional;
      } else {
        if (typeof _from.modifiers.optional === 'string') {
          _from.modifiers.optional = [_from.modifiers.optional];
        }
        _from.modifiers.optional = parseKeys(_from.modifiers.optional);
      }
    }
  }

  if (_from?.simultaneous_options?.to_after_key_up?.length === 0) {
    delete _from.simultaneous_options.to_after_key_up;
  }
  if (_from?.simultaneous?.length === 0) {
    delete _from.simultaneous;
  }
  if (_from?.simultaneous?.length) {
    _from.simultaneous = _from.simultaneous.map(sim => {
      if (sim.key_code) {
        sim.key_code = parseKey(sim.key_code);
      }
      return sim;
    });
  }

  if (
    _.isEqual(_from.simultaneous_options, {
      detect_key_down_uninterruptedly: false,
    })
  ) {
    delete _from.simultaneous_options;
  }
  if (!_from.pointing_button || _from.pointing_button === 'disabled') {
    delete _from.pointing_button;
  }
  if (_.isEmpty(_from.modifiers)) {
    delete _from.modifiers;
  }
  return _from;
};

const parseToObject = (toObject: IToEventDefinition): any => {
  const _to = { ...toObject };
  if (typeof _to.key_code === 'object') {
    _to.key_code = parseKey(toObject.key_code);
  }
  if (_to.modifiers?.length) {
    _to.modifiers = parseKeys(_to.modifiers);
  }
  return _to;
};

const parseRuleObject = (rule: IRule): any => {
  const _rule = { ...rule };
  if (!rule?.description?.length) {
    delete rule.description;
  }
  rule.manipulators = rule.manipulators.map((manipulator: IManipulator) => {
    manipulator.from = parseFromObject(manipulator.from);
    toFields.forEach(toField => {
      if (!manipulator[toField]) return;
      if (manipulator[toField]?.length === 0) {
        delete manipulator[toField];
        return;
      }
      manipulator[toField] = manipulator[toField].map(
        (toObject: IToEventDefinition) => {
          return parseToObject(toObject);
        },
      );
    });

    if (manipulator?.to_delayed_action?.to_if_invoked?.length === 0) {
      delete manipulator.to_delayed_action.to_if_invoked;
    }
    if (manipulator?.to_delayed_action?.to_if_canceled?.length === 0) {
      delete manipulator.to_delayed_action.to_if_canceled;
    }
    if (_.isEmpty(manipulator?.to_delayed_action)) {
      delete manipulator.to_delayed_action;
    }

    if (manipulator?.conditions?.length === 0) {
      delete manipulator.conditions;
    }
    return manipulator;
  });
  return _rule;
};

const parseStateToMinimumJSON = (state: any) => {
  const parsedState = _.cloneDeep(state);
  parsedState.rules = parsedState.rules.map((rule: IRule) => {
    return parseRuleObject(rule);
  });
  return parsedState;
};

const MainForm: React.FC<Props> = () => {
  const formState = useSelector((state: IFormState) => state);

  const dispatch = useDispatch();

  useEffect(() => {
    try {
      const state = JSON.parse(
        window.atob(
          window.location.href.slice(window.location.href.indexOf('#') + 1),
        ),
      );
      dispatch(setWholeState(parseJSONfirst(state)));
    } catch (e) {}
  }, []);

  const parsedState = parseStateToMinimumJSON(formState);

  const install = () => {
    const base64string = window.btoa(JSON.stringify(parsedState));
    let url = `karabiner://karabiner/assets/complex_modifications/import?url=data:application/json;charset=utf-8;base64,${base64string}`;
    window.location.href = url;
  };
  const generateUrl = () => {
    const base64string = window.btoa(JSON.stringify(parsedState));
    window.history.replaceState(undefined, '', '#' + base64string);
    alert('copy the url in your addess bar to share');
  };

  const titleForm = useMemo(() => {
    return (
      <Box m={1}>
        <TextField
          fullWidth
          onChange={e => dispatch(setTitle(e.target.value))}
          value={formState.title}
          variant="outlined"
          label="Modification Title"
        />
      </Box>
    );
  }, [formState.title]);
  return (
    <Container className="app-container">
      <Grid container direction="row" justify="space-between">
        <Grid item xs={8} className="form-wrapper">
          {titleForm}
          <Box p={1}>
            {formState.rules.map((rule, index) => (
              <RuleForm index={index} key={index} rule={rule} />
            ))}
            <Box mt={2}>
              <Button
                onClick={() => dispatch(addRule())}
                fullWidth
                color="primary"
                variant="contained"
                startIcon={<AddIcon />}
              >
                Rule
              </Button>
            </Box>
          </Box>
        </Grid>

        <Grid container xs={4} item direction="column">
          <Box p={2}>
            <Typography>Your Modification</Typography>
            <textarea
              className="generated-code"
              // value={JSON.stringify(formState, null, 2)}
              readOnly
              value={JSON.stringify(parsedState, null, 2)}
            />

            <Box mt={1} mb={1}>
              <ButtonGroup fullWidth>
                <Button onClick={install} color="primary" variant="contained">
                  Install!
                </Button>
                <Button
                  onClick={generateUrl}
                  color="primary"
                  variant="contained"
                >
                  Share!
                </Button>
              </ButtonGroup>
            </Box>
            <textarea
              placeholder="Paste existing modification here to edit"
              className="paste-code"
              onBlur={e => {
                try {
                  if (e.target.value)
                    dispatch(setWholeState(parseJSONfirst(e.target.value)));
                } catch (e) {
                  console.log({ e });
                }
              }}
            />
          </Box>
        </Grid>
      </Grid>
    </Container>
  );
};
export default MainForm;


================================================
FILE: src/components/forms/AddConditionForm.tsx
================================================
import React, { useState, useEffect } from 'react';
import {
  Box,
  TextField,
  FormControl,
  InputLabel,
  Select,
  MenuItem,
  Button,
  ButtonGroup,
} from '@material-ui/core';
import { titleCase, withSuffix } from '../../helpers';
import AppExpansionPanel from '../shared/AppExpansionPanel';
import IManipulator from '../../types/IManipulator';
import FrontmostConditionForm from './FrontmostConditionForm';
import DeviceIfConditionForm from './DeviceIfConditionForm';
import KeyboardTypeConditionForm from './KeyboardTypeConditionForm';
import VariableConditionForm from './VariableConditionForm';
import InputSourceConditionForm from './InputSourceConditionForm';
import EventChangedConditionForm from './EventChangedConditionForm';

interface Props {
  condition: any;
  index: number;
  setManipulator: (arg0: IManipulator) => void;
  manipulator: IManipulator;
}
const conditionTypes: string[] = [
  'frontmost_application_if',
  'frontmost_application_unless',
  'device_if',
  'device_unless',
  'keyboard_type_if',
  'keyboard_type_unless',
  'input_source_if',
  'input_source_unless',
  'variable_if',
  'variable_unless',
  'event_changed_if',
  'event_changed_unless',
];

const AddConditionForm: React.FC<Props> = ({
  condition,
  index,
  setManipulator,
  manipulator,
}) => {
  const setConditionState = (condition: any) => {
    const newManipulator = { ...manipulator };
    const newConditions = [...manipulator.conditions];
    newConditions[index] = condition;
    newManipulator.conditions = newConditions;
    setManipulator(newManipulator);
  };

  return (
    <AppExpansionPanel
      panelProps={{ defaultExpanded: index === 0 }}
      title={`${withSuffix(index + 1)} Condition`}
    >
      <FormControl fullWidth variant="filled">
        <InputLabel id="condition_type">Condition Type</InputLabel>
        <Select
          labelId="condition_type"
          value={condition.type}
          onChange={e => {
            setConditionState({ ...condition, type: e.target.value });
          }}
        >
          {conditionTypes.map(item => (
            <MenuItem value={item} key={item}>
              {titleCase(item)}
            </MenuItem>
          ))}
        </Select>
      </FormControl>

      <TextField
        fullWidth
        variant="filled"
        label={`Condition Description (optional)`}
        value={condition.description}
        onChange={e => {
          setConditionState({ ...condition, description: e.target.value });
        }}
      />

      {condition.type.indexOf('frontmost') === 0 && (
        <FrontmostConditionForm
          condition={condition}
          setConditionState={setConditionState}
        />
      )}
      {condition.type.indexOf('device') === 0 && (
        <DeviceIfConditionForm
          condition={condition}
          setConditionState={setConditionState}
        />
      )}
      {condition.type.indexOf('keyboard') === 0 && (
        <KeyboardTypeConditionForm
          condition={condition}
          setConditionState={setConditionState}
        />
      )}
      {condition.type.indexOf('input_source') === 0 && (
        <InputSourceConditionForm
          condition={condition}
          setConditionState={setConditionState}
        />
      )}
      {condition.type.indexOf('variable') === 0 && (
        <VariableConditionForm
          condition={condition}
          setConditionState={setConditionState}
        />
      )}
      {condition.type.indexOf('event_changed') === 0 && (
        <EventChangedConditionForm
          condition={condition}
          setConditionState={setConditionState}
        />
      )}
    </AppExpansionPanel>
  );
};

export default AddConditionForm;


================================================
FILE: src/components/forms/DeviceIfConditionForm.tsx
================================================
import React from 'react';
import {
  Box,
  TextField,
  ButtonGroup,
  Button,
  Checkbox,
  FormControlLabel,
} from '@material-ui/core';
import ICondition from '../../types/ICondition';
import AppExpansionPanel from '../shared/AppExpansionPanel';
import { withSuffix, titleCase } from '../../helpers';

interface Props {
  condition: ICondition;
  setConditionState: (arg0: ICondition) => void;
}

const DeviceIfConditionForm: React.FC<Props> = ({
  condition,
  setConditionState,
}) => {
  const addDeviceIdentifier = () => {
    const newCondition: any = { ...condition };
    newCondition.identifiers = newCondition.identifiers || [];
    const deviceIdentifiers = [...newCondition.identifiers];
    deviceIdentifiers.push('');
    newCondition.identifiers = deviceIdentifiers;
    setConditionState(newCondition);
  };

  const setIdentifier = (identifier: any, index: number) => {
    const newCondition = { ...condition };
    const newIdentifiers = [...newCondition.identifiers];
    newIdentifiers[index] = identifier;
    newCondition.identifiers = newIdentifiers;
    setConditionState(newCondition);
  };

  return (
    <Box>
      <Box>
        {!!condition?.identifiers?.length && (
          <AppExpansionPanel
            panelProps={{ defaultExpanded: true }}
            title="Device Identifiers"
          >
            {condition.identifiers.map((identifier, index: number) => (
              <AppExpansionPanel
                title={`${withSuffix(index + 1)} Device Identifier`}
                key={index}
              >
                {['vendor_id', 'product_id', 'location_id'].map(key => {
                  return (
                    <TextField
                      key={key}
                      fullWidth
                      label={titleCase(key) + ' (Optional)'}
                      variant="filled"
                      value={identifier[key]}
                      onChange={e => {
                        setIdentifier(
                          { ...identifier, [key]: e.target.value },
                          index,
                        );
                      }}
                    />
                  );
                })}

                <FormControlLabel
                  control={
                    <Checkbox
                      checked={!!identifier.is_keyboard}
                      onChange={e => {
                        setIdentifier(
                          { ...identifier, is_keyboard: e.target.checked },
                          index,
                        );
                      }}
                    />
                  }
                  label="Is Keyboard?"
                />
                <FormControlLabel
                  control={
                    <Checkbox
                      checked={!!identifier.is_pointing_device}
                      onChange={e => {
                        setIdentifier(
                          {
                            ...identifier,
                            is_pointing_device: e.target.checked,
                          },
                          index,
                        );
                      }}
                    />
                  }
                  label="Is Pointing Device?"
                />
              </AppExpansionPanel>
            ))}
          </AppExpansionPanel>
        )}
      </Box>
      <Box mt={2}>
        <ButtonGroup>
          <Button
            variant="contained"
            color="primary"
            onClick={addDeviceIdentifier}
          >
            Add Device Identifiers
          </Button>
        </ButtonGroup>
      </Box>
    </Box>
  );
};

export default DeviceIfConditionForm;


================================================
FILE: src/components/forms/EventChangedConditionForm.tsx
================================================
import React from 'react';
import {
  Box,
  TextField,
  FormLabel,
  FormControl,
  RadioGroup,
  FormControlLabel,
  Radio,
} from '@material-ui/core';
import ICondition from '../../types/ICondition';
import Autocomplete from '@material-ui/lab/Autocomplete';

interface Props {
  condition: ICondition;
  setConditionState: (arg0: ICondition) => void;
}

const EventChangedConditionForm: React.FC<Props> = ({
  condition,
  setConditionState,
}) => {
  return (
    <Box mt={2}>
      <FormControl component="fieldset">
        <FormLabel component="legend">Value</FormLabel>
        <RadioGroup
          defaultValue="true"
          onChange={e => {
            setConditionState({ ...condition, value: e.target.value });
          }}
        >
          <FormControlLabel label="true" value="true" control={<Radio />} />
          <FormControlLabel label="false" value="false" control={<Radio />} />
        </RadioGroup>
      </FormControl>
    </Box>
  );
};

export default EventChangedConditionForm;


================================================
FILE: src/components/forms/FromEventForm.tsx
================================================
import React, { useMemo } from 'react';
import {
  Box,
  Button,
  FormControlLabel,
  Checkbox,
  FormControl,
  InputLabel,
  Select,
  MenuItem,
} from '@material-ui/core';

import IFromEventDefinition from '../../types/IFromEventDefinition';
import KeyInput from '../shared/KeyInput';
import KeyCodeAndPointingButtonInput from '../shared/KeyCodeAndPointingButtonInput';
import _ from 'lodash';
import { titleCase, withSuffix } from '../../helpers';
import AppExpansionPanel from '../shared/AppExpansionPanel';
import { useDispatch } from 'react-redux';
import { setFromObject } from '../../ducks/formState';
import ISimultaneous from '../../types/ISimultaneous';
import ToEventForm from './ToEventForm';
import IToEventDefinition from '../../types/IToEventDefinition';

const optionalBoolean: string[] = ['none', 'true', 'false'];
const keyOrder: string[] = ['none', 'insensitive', 'strict', 'strict_inverse'];
const keyUpWhen: string[] = ['none', 'any', 'all'];

interface Props {
  fromObject: IFromEventDefinition;
  ruleIndex: number;
  manipulatorIndex: number;
}

const FromEventForm: React.FC<Props> = ({
  fromObject,
  ruleIndex,
  manipulatorIndex,
}) => {
  const dispatch = useDispatch();
  const _setFromObject = (fromObject: IFromEventDefinition) => {
    dispatch(setFromObject({ ruleIndex, manipulatorIndex, fromObject }));
  };
  const handleModifierChange = (event: any, value: any, type: string) => {
    _setFromObject({
      ...fromObject,
      modifiers: {
        ...fromObject.modifiers,
        [type]: value.map((v: any) =>
          typeof v === 'string' ? { label: v, value: v } : v,
        ),
      },
    });
  };

  const addSimultaneous = () => {
    const newFromObject = { ...fromObject };
    newFromObject.simultaneous = newFromObject.simultaneous || [];
    newFromObject.simultaneous = [...newFromObject.simultaneous, {}];
    _setFromObject(newFromObject);
  };

  return useMemo(
    () => (
      <Box className="form-container">
        <KeyCodeAndPointingButtonInput
          setEventObject={_setFromObject}
          eventObject={fromObject}
        />
        <div>
          <div>
            <KeyInput
              modifiers
              value={fromObject.modifiers?.mandatory || []}
              label="Mandatory Modifiers (optional)"
              onChange={(event: any, value: any) =>
                handleModifierChange(event, value, 'mandatory')
              }
            />
          </div>
          <div>
            <KeyInput
              modifiers
              keyCodes
              value={fromObject.modifiers?.optional || []}
              label="Optional Modifiers (optional)"
              onChange={(event: any, value: any) =>
                handleModifierChange(event, value, 'optional')
              }
            />
          </div>
        </div>
        <Box>
          {fromObject.simultaneous?.map((simultaneous: any, index: number) => {
            const setSimultaneous = (newSimultaneousObject: any) => {
              const newFromObject = { ...fromObject };
              if (newFromObject?.simultaneous?.length) {
                const newSim = [...newFromObject.simultaneous];
                newSim[index] = newSimultaneousObject;
                newFromObject.simultaneous = newSim;
                _setFromObject(newFromObject);
              }
            };
            return (
              <AppExpansionPanel
                key={index}
                panelProps={{ defaultExpanded: index === 0 }}
                title={`${withSuffix(index + 1)} Simultaneous Event`}
              >
                <KeyCodeAndPointingButtonInput
                  eventObject={simultaneous}
                  setEventObject={setSimultaneous}
                />
                <Button
                  variant="contained"
                  color="secondary"
                  onClick={() => {
                    const newFromObject = { ...fromObject };
                    if (newFromObject?.simultaneous?.length) {
                      const simultaneous = [...newFromObject.simultaneous];
                      simultaneous.splice(index, 1);
                      newFromObject.simultaneous = simultaneous;
                      _setFromObject(newFromObject);
                    }
                  }}
                >
                  Remove Simultaneous
                </Button>
              </AppExpansionPanel>
            );
          })}
          <Box mt={1} mb={1}>
            <Button
              variant="contained"
              color="default"
              fullWidth
              onClick={() => addSimultaneous()}
            >
              Add Simultaneous Event
            </Button>
          </Box>
        </Box>
        <Box>
          <AppExpansionPanel title="Simultaneous Options">
            <FormControlLabel
              control={
                <Checkbox
                  checked={
                    !!fromObject?.simultaneous_options
                      ?.detect_key_down_uninterruptedly
                  }
                  onChange={e => {
                    _setFromObject({
                      ...fromObject,
                      simultaneous_options: {
                        ...fromObject.simultaneous_options,
                        detect_key_down_uninterruptedly: e.target.checked,
                      },
                    });
                  }}
                />
              }
              label="Detect Key Down Uninterruptedly"
            />
            <FormControl fullWidth variant="filled">
              <InputLabel id="key_down_order">Key Down Order</InputLabel>
              <Select
                labelId="key_down_order"
                value={fromObject.simultaneous_options?.key_down_order}
                onChange={e => {
                  _setFromObject({
                    ...fromObject,
                    simultaneous_options: {
                      ...fromObject.simultaneous_options,
                      key_down_order: e.target.value,
                    },
                  });
                }}
              >
                {keyOrder.map(item => (
                  <MenuItem value={item} key={item}>
                    {titleCase(item)}
                  </MenuItem>
                ))}
              </Select>
            </FormControl>
            <FormControl fullWidth variant="filled">
              <InputLabel id="key_up_order">Key Up Order</InputLabel>
              <Select
                labelId="key_up_order"
                value={fromObject.simultaneous_options?.key_up_order}
                onChange={e => {
                  _setFromObject({
                    ...fromObject,
                    simultaneous_options: {
                      ...fromObject.simultaneous_options,
                      key_up_order: e.target.value,
                    },
                  });
                }}
              >
                {keyOrder.map(item => (
                  <MenuItem value={item} key={item}>
                    {titleCase(item)}
                  </MenuItem>
                ))}
              </Select>
            </FormControl>
            <FormControl fullWidth variant="filled">
              <InputLabel id="key_up_when">Key Up When</InputLabel>
              <Select
                labelId="key_up_when"
                value={fromObject.simultaneous_options?.key_up_when}
                onChange={e => {
                  _setFromObject({
                    ...fromObject,
                    simultaneous_options: {
                      ...fromObject.simultaneous_options,
                      key_up_when: e.target.value,
                    },
                  });
                }}
              >
                {keyUpWhen.map(item => (
                  <MenuItem value={item} key={item}>
                    {titleCase(item)}
                  </MenuItem>
                ))}
              </Select>
            </FormControl>

            <Box mt={1}>
              {fromObject.simultaneous_options?.to_after_key_up?.map(
                (toEvent: IToEventDefinition, index: number) => {
                  return (
                    <ToEventForm
                      toObject={toEvent}
                      setToObject={(toObject: IToEventDefinition) => {
                        const newFromObject = { ...fromObject };
                        const currentToField = [
                          ...newFromObject.simultaneous_options.to_after_key_up,
                        ];
                        currentToField[index] = toObject;
                        newFromObject.simultaneous_options = {
                          to_after_key_up: currentToField,
                        };
                        _setFromObject(newFromObject);
                      }}
                      removeToObject={() => {}}
                      index={index}
                      toField="to_after_key_up"
                      key={index}
                    />
                  );
                },
              )}
              <Button
                color="default"
                variant="contained"
                fullWidth
                onClick={() => {
                  const newFromObject: IFromEventDefinition = { ...fromObject };
                  const simOpts: any = {
                    ...newFromObject.simultaneous_options,
                  };
                  const toAfterKeyUp = simOpts.to_after_key_up
                    ? [...simOpts.to_after_key_up]
                    : [];
                  toAfterKeyUp.push({});
                  simOpts.to_after_key_up = toAfterKeyUp;
                  newFromObject.simultaneous_options = simOpts;
                  _setFromObject(newFromObject);
                }}
              >
                Add to_after_key_up event
              </Button>
            </Box>
          </AppExpansionPanel>
        </Box>
      </Box>
    ),
    [fromObject],
  );
};

export default FromEventForm;


================================================
FILE: src/components/forms/FrontmostConditionForm.tsx
================================================
import React from 'react';
import { Box, TextField, ButtonGroup, Button } from '@material-ui/core';
import ICondition from '../../types/ICondition';
import AppExpansionPanel from '../shared/AppExpansionPanel';

interface Props {
  condition: ICondition;
  setConditionState: (arg0: ICondition) => void;
}

const FrontmostConditionForm: React.FC<Props> = ({
  condition,
  setConditionState,
}) => {
  const setFilePath = (bundleIndex: number, value: string) => {
    const newCondition: any = { ...condition };
    const filePaths = [...newCondition.file_paths];
    filePaths[bundleIndex] = value;
    newCondition.file_paths = filePaths;
    setConditionState(newCondition);
  };
  const setBundleIdentifier = (bundleIndex: number, value: string) => {
    const newCondition: any = { ...condition };
    const bundleIdentifiers = [...newCondition.bundle_identifiers];
    bundleIdentifiers[bundleIndex] = value;
    newCondition.bundle_identifiers = bundleIdentifiers;
    setConditionState(newCondition);
  };
  const addBundleIdentifier = () => {
    const newCondition: any = { ...condition };
    newCondition.bundle_identifiers = newCondition.bundle_identifiers || [];
    const bundleIdentifiers = [...newCondition.bundle_identifiers];
    bundleIdentifiers.push('');
    newCondition.bundle_identifiers = bundleIdentifiers;
    setConditionState(newCondition);
  };

  const addFilePath = () => {
    const newCondition: any = { ...condition };
    newCondition.file_paths = newCondition.file_paths || [];
    const filePaths = [...newCondition.file_paths];
    filePaths.push('');
    newCondition.file_paths = filePaths;
    setConditionState(newCondition);
  };

  return (
    <Box>
      <Box>
        {!!condition?.bundle_identifiers?.length && (
          <AppExpansionPanel
            panelProps={{ defaultExpanded: true }}
            title="Bundle Identifiers"
          >
            {condition.bundle_identifiers.map(
              (identifier: string, bundleIndex: number) => (
                <TextField
                  key={bundleIndex}
                  value={identifier}
                  fullWidth
                  variant="filled"
                  label={`Regex Bundle Identifier ${bundleIndex + 1}`}
                  onChange={e => {
                    setBundleIdentifier(bundleIndex, e.target.value);
                  }}
                />
              ),
            )}
          </AppExpansionPanel>
        )}
        {!!condition?.file_paths?.length && (
          <AppExpansionPanel
            panelProps={{ defaultExpanded: true }}
            title="File Paths"
          >
            {condition.file_paths.map(
              (filePath: string, filePathIndex: number) => (
                <TextField
                  key={filePathIndex}
                  value={filePath}
                  fullWidth
                  variant="filled"
                  label={`Regex File Path ${filePathIndex + 1}`}
                  onChange={e => {
                    setFilePath(filePathIndex, e.target.value);
                  }}
                />
              ),
            )}
          </AppExpansionPanel>
        )}
      </Box>
      <Box mt={2}>
        <ButtonGroup>
          <Button
            variant="contained"
            color="primary"
            onClick={addBundleIdentifier}
          >
            Add Bundle Identifier
          </Button>
          <Button variant="contained" color="primary" onClick={addFilePath}>
            Add File Path
          </Button>
        </ButtonGroup>
      </Box>
    </Box>
  );
};

export default FrontmostConditionForm;


================================================
FILE: src/components/forms/InputSourceConditionForm.tsx
================================================
import React from 'react';
import { Box, TextField } from '@material-ui/core';
import ICondition from '../../types/ICondition';
import Autocomplete from '@material-ui/lab/Autocomplete';

interface Props {
  condition: ICondition;
  setConditionState: (arg0: ICondition) => void;
}

const InputSourceConditionForm: React.FC<Props> = ({
  condition,
  setConditionState,
}) => {
  return <Box>Unknown</Box>;
};

export default InputSourceConditionForm;


================================================
FILE: src/components/forms/KeyboardTypeConditionForm.tsx
================================================
import React from 'react';
import {
  Box,
  TextField,
  ButtonGroup,
  Button,
  Checkbox,
  FormControlLabel,
} from '@material-ui/core';
import ICondition from '../../types/ICondition';
import AppExpansionPanel from '../shared/AppExpansionPanel';
import { withSuffix, titleCase } from '../../helpers';
import Autocomplete from '@material-ui/lab/Autocomplete';

interface Props {
  condition: ICondition;
  setConditionState: (arg0: ICondition) => void;
}

const KeyboardTypeConditionForm: React.FC<Props> = ({
  condition,
  setConditionState,
}) => {
  return (
    <Box>
      <Box>
        <Autocomplete
          options={['ansi', 'iso', 'jis']}
          multiple
          freeSolo
          value={condition.keyboard_types}
          onChange={(_e, value) => {
            setConditionState({ ...condition, keyboard_types: value });
          }}
          autoHighlight={true}
          renderInput={params => (
            <TextField
              {...params}
              variant="filled"
              fullWidth
              label="Keyboard Type"
            />
          )}
        />
      </Box>
    </Box>
  );
};

export default KeyboardTypeConditionForm;


================================================
FILE: src/components/forms/ManipulatorForm.tsx
================================================
import React, { useMemo } from 'react';
import {
  Select,
  Box,
  ButtonGroup,
  FormControl,
  InputLabel,
  MenuItem,
  Button,
  Typography,
} from '@material-ui/core';

import { titleCase, withSuffix } from '../../helpers';
import AddConditionForm from './AddConditionForm';
import IManipulator from '../../types/IManipulator';
import ICondition from '../../types/ICondition';
import FromEventForm from './FromEventForm';
import IFromEventDefinition from '../../types/IFromEventDefinition';
import ToEventFormsContainer from './ToEventFormsContainer';
import _ from 'lodash';
import AppExpansionPanel from '../shared/AppExpansionPanel';
import AppSelect from '../shared/AppSelect';
import { useDispatch } from 'react-redux';
import { setManipulator, addToObject } from '../../ducks/formState';

const toFields: string[] = [
  'to',
  'to_if_alone',
  'to_if_held_down',
  'to_after_key_up',
];
const types: string[] = [
  'basic',
  'frontmost_application_if',
  'frontmost_application_unless',
  'device_if',
  'device_unless',
  'keyboard_type_if',
  'keyboard_type_unless',
  'input_source_if',
  'input_source_unless',
  'variable_if',
  'variable_unless',
  'event_changed_if',
  'event_changed_unless',
];

interface Props {
  manipulator: IManipulator;
  index: number;
  ruleIndex: number;
}

const ManipulatorForm: React.FC<Props> = ({
  manipulator,
  ruleIndex,
  index,
}) => {
  const dispatch = useDispatch();
  const addToEventForm = (toField: string) => {
    dispatch(addToObject({ manipulatorIndex: index, ruleIndex, toField }));
  };

  const _setManipulator = (newManipulator: IManipulator) => {
    dispatch(
      setManipulator({
        ruleIndex,
        index,
        manipulator: newManipulator,
      }),
    );
  };

  const addConditionToRule = () => {
    const newManipulator = { ...manipulator };
    newManipulator.conditions = newManipulator.conditions || [];
    const newConditions = [...newManipulator.conditions];
    newConditions.push({ type: 'frontmost_application_if' });
    newManipulator.conditions = newConditions;
    _setManipulator(newManipulator);
  };

  return useMemo(
    () => (
      <AppExpansionPanel
        panelProps={{ defaultExpanded: true }}
        title={`${withSuffix(index + 1)} Manipulator`}
      >
        <AppSelect
          label="Type"
          value={manipulator.type}
          options={types}
          onChange={(e: any) => {
            dispatch(
              setManipulator({
                manipulator: { ...manipulator, type: e.target.value },
                index,
                ruleIndex,
              }),
            );
          }}
        />
        <AppExpansionPanel
          panelProps={{ defaultExpanded: true }}
          title={`"From" Event`}
        >
          <FromEventForm
            fromObject={manipulator.from}
            manipulatorIndex={index}
            ruleIndex={ruleIndex}
          />
        </AppExpansionPanel>

        <ToEventFormsContainer
          manipulator={manipulator}
          ruleIndex={ruleIndex}
          manipulatorIndex={index}
        />

        {!!manipulator.conditions?.length && (
          <AppExpansionPanel
            panelProps={{ defaultExpanded: true }}
            title="Rule Conditions"
          >
            {manipulator.conditions.map(
              (condition: ICondition, index: number) => {
                return (
                  <AddConditionForm
                    key={index}
                    index={index}
                    condition={condition}
                    setManipulator={_setManipulator}
                    manipulator={manipulator}
                  />
                );
              },
            )}
          </AppExpansionPanel>
        )}

        <Box marginTop={1}>
          <Button
            color="primary"
            variant="contained"
            fullWidth
            onClick={() => {
              addConditionToRule();
            }}
          >
            Add Condition
          </Button>
        </Box>
      </AppExpansionPanel>
    ),
    [manipulator],
  );
};

export default ManipulatorForm;


================================================
FILE: src/components/forms/RuleForm.tsx
================================================
import React, { useMemo } from 'react';
import { Typography, Box, TextField, Button } from '@material-ui/core';

import ManipulatorForm from './ManipulatorForm';
import IManipulator from '../../types/IManipulator';
import IRule from '../../types/IRule';
import _ from 'lodash';
import { withSuffix } from '../../helpers';
import AppExpansionPanel from '../shared/AppExpansionPanel';
import { useDispatch } from 'react-redux';
import { removeRule, setRule, addManipulator } from '../../ducks/formState';

interface Props {
  rule: IRule;
  index: number;
}

const RuleForm: React.FC<Props> = ({ rule, index }) => {
  const dispatch = useDispatch();
  return useMemo(
    () => (
      <AppExpansionPanel
        title={
          <TextField
            label={`${withSuffix(index + 1)} Rule Description`}
            value={rule.description}
            onClick={event => event.stopPropagation()}
            onFocus={event => event.stopPropagation()}
            onChange={e =>
              dispatch(setRule(index, { ...rule, description: e.target.value }))
            }
            multiline
            fullWidth
          />
        }
        panelProps={{ defaultExpanded: index === 0 }}
      >
        <Box justifyContent="flex-end">
          <Button
            variant="text"
            size="small"
            color="secondary"
            onClick={() => dispatch(removeRule(index))}
          >
            Delete Rule!
          </Button>
        </Box>
        <Box mt={2}>
          {rule.manipulators.map(
            (manipulator: IManipulator, manipulatorIndex: number) => {
              return (
                <ManipulatorForm
                  manipulator={manipulator}
                  key={manipulatorIndex}
                  index={manipulatorIndex}
                  ruleIndex={index}
                />
              );
            },
          )}
        </Box>

        <Box mt={2}>
          <Button
            fullWidth
            variant="contained"
            color="primary"
            onClick={() => dispatch(addManipulator(index))}
          >
            Add Manipulator
          </Button>
        </Box>
      </AppExpansionPanel>
    ),
    [rule],
  );
};

export default RuleForm;


================================================
FILE: src/components/forms/ToEventForm.tsx
================================================
import React, { useState, useEffect, useMemo } from 'react';
import KeyCodeAndPointingButtonInput from '../shared/KeyCodeAndPointingButtonInput';
import IToEventDefinition from '../../types/IToEventDefinition';
import Modifier from '../../types/Modifier';
import {
  FormControl,
  FormLabel,
  FormControlLabel,
  Checkbox,
  Button,
  Box,
} from '@material-ui/core';
import KeyInput from '../shared/KeyInput';
import DeleteIcon from '@material-ui/icons/Delete';
import IManipulator from '../../types/IManipulator';
import AppExpansionPanel from '../shared/AppExpansionPanel';
import { suffix, titleCase } from '../../helpers';

interface Props {
  toObject: IToEventDefinition;
  setToObject: (arg0: IToEventDefinition) => void;
  removeToObject: () => void;
  index: number;
  toField: string;
}

const ToEventForm: React.FC<Props> = ({
  toObject,
  setToObject,
  removeToObject,
  index,
  toField,
}) => {
  const [showOptional, setShowOptional] = useState({
    keyCode: false,
    consumerKeyCode: false,
    pointingButton: false,
    simultaneous: false,
    simultaneousOptions: false,
  });

  useEffect(() => {
    const newToObject: any = { ...toObject };
    if (newToObject.pointing_button === 'disabled') {
      delete newToObject.pointing_button;
    }
    if (!showOptional.keyCode && !!newToObject.key_code) {
      delete newToObject.key_code;
    } else {
      newToObject.key_code = newToObject.key_code?.value;
    }
    if (!showOptional.consumerKeyCode && !!newToObject.consumer_key_code) {
      delete newToObject.consumer_key_code;
    }
    if (!newToObject.modifiers?.length) {
      delete newToObject.modifiers;
    } else {
      if (typeof newToObject.modifiers === 'string') {
        newToObject.modifiers = [newToObject.modifiers];
      }
      newToObject.modifiers = newToObject.modifiers.map(
        (m: Modifier) => m.value,
      );
    }
    if (newToObject.lazy === false) {
      delete newToObject.lazy;
    }
    if (newToObject.repeat === true) {
      delete newToObject.repeat;
    }
    if (newToObject.halt === false) {
      delete newToObject.halt;
    }
    // const toArray = [...ruleState[type]];
    // toArray[index] = { ...newToObject };

    // setRuleState({
    //   ...ruleState,
    //   [type]: toArray,
    // });
  }, [toObject, showOptional]);
  return (
    <AppExpansionPanel
      title={`${index + 1}${suffix(index + 1)} "${titleCase(toField)}" Event`}
    >
      <Box className="form-container">
        <KeyCodeAndPointingButtonInput
          setEventObject={setToObject}
          eventObject={toObject}
        />
        <KeyInput
          freeSolo={false}
          modifiers
          value={toObject.modifiers}
          label="Modifiers"
          onChange={(_e: any, value: any) => {
            setToObject({
              ...toObject,
              modifiers: value.map((v: any) =>
                typeof v === 'string' ? { label: v, value: v } : v,
              ),
            });
          }}
        />
        <FormControl fullWidth>
          <FormLabel>Additional Options</FormLabel>
          <FormControlLabel
            label="Lazy"
            control={
              <Checkbox
                checked={!!toObject.lazy}
                onChange={e => {
                  setToObject({ ...toObject, lazy: e.target.checked });
                }}
              />
            }
          />
          <FormControlLabel
            label="Repeat"
            control={
              <Checkbox
                checked={!!toObject.repeat}
                onChange={e => {
                  setToObject({ ...toObject, repeat: e.target.checked });
                }}
              />
            }
          />
          <FormControlLabel
            label="Halt"
            control={
              <Checkbox
                checked={!!toObject.halt}
                onChange={e => {
                  setToObject({ ...toObject, halt: e.target.checked });
                }}
              />
            }
          />
        </FormControl>

        <Button
          color="secondary"
          variant="contained"
          onClick={() => removeToObject()}
          startIcon={<DeleteIcon />}
        >
          Remove
        </Button>
      </Box>
    </AppExpansionPanel>
  );
};

export default ToEventForm;


================================================
FILE: src/components/forms/ToEventFormsContainer.tsx
================================================
import React from 'react';
import { Box, Button, ButtonGroup } from '@material-ui/core';

import { titleCase, suffix } from '../../helpers';
import ToEventForm from './ToEventForm';
import IManipulator from '../../types/IManipulator';
import IToEventDefinition from '../../types/IToEventDefinition';
import AppExpansionPanel from '../shared/AppExpansionPanel';
import { useDispatch } from 'react-redux';
import { setManipulator, addToObject } from '../../ducks/formState';

const toFields: string[] = [
  'to',
  'to_if_alone',
  'to_if_held_down',
  'to_after_key_up',
];

const toDelayedAction: string[] = ['to_if_invoked', 'to_if_canceled'];

interface Props {
  manipulator: IManipulator;
  manipulatorIndex: number;
  ruleIndex: number;
}

const TheForm = ({
  to,
  index,
  toField,
  manipulator,
  ruleIndex,
  manipulatorIndex,
}: {
  to: IToEventDefinition;
  index: number;
  toField: string;
  manipulator: IManipulator;
  ruleIndex: number;
  manipulatorIndex: number;
}) => {
  const toObject = { ...to };
  const dispatch = useDispatch();

  const _setManipulator = (newManipulator: IManipulator) =>
    dispatch(
      setManipulator({
        manipulator: newManipulator,
        ruleIndex,
        index: manipulatorIndex,
      }),
    );
  const setToObject = (newToObject: IToEventDefinition) => {
    const newManipulator = { ...manipulator };
    if (toDelayedAction.includes(toField)) {
      const _toDelayedAction = { ...newManipulator.to_delayed_action };
      _toDelayedAction[toField] = [..._toDelayedAction[toField]];
      _toDelayedAction[toField][index] = newToObject;
      newManipulator.to_delayed_action = _toDelayedAction;
    } else {
      const _toField = [...newManipulator[toField]];
      _toField[index] = newToObject;
      newManipulator[toField] = _toField;
    }
    _setManipulator(newManipulator);
  };
  const removeToObject = () => {
    const newManipulator = { ...manipulator };
    if (toDelayedAction.includes(toField)) {
      const _toDelayedAction = { ...newManipulator.to_delayed_action };
      _toDelayedAction[toField] = [..._toDelayedAction[toField]];
      _toDelayedAction[toField].splice(index, 1);
      newManipulator.to_delayed_action = _toDelayedAction;
    } else {
      const _toField = [...newManipulator[toField]];
      _toField.splice(index, 1);
      newManipulator[toField] = _toField;
    }
    _setManipulator(newManipulator);
  };

  const toEventFormProps = {
    toObject,
    setToObject,
    removeToObject,
    index,
    toField,
  };
  return <ToEventForm {...toEventFormProps} key={index} />;
};
const ToEventFormsContainer: React.FC<Props> = ({
  manipulator,
  ruleIndex,
  manipulatorIndex,
}) => {
  const dispatch = useDispatch();
  const addToEventForm = (toField: string) => {
    dispatch(addToObject({ manipulatorIndex, ruleIndex, toField }));
  };
  const totalDelayedAction =
    (manipulator?.to_delayed_action?.to_if_canceled?.length || 0) +
    (manipulator?.to_delayed_action?.to_if_invoked?.length || 0);
  return (
    <Box>
      {toFields.map((toField: string, toFieldsIndex: number) => {
        return (
          <Box mb={2} key={toField}>
            {manipulator[toField]?.length ? (
              <AppExpansionPanel
                key={toFieldsIndex}
                title={`${manipulator[toField].length} "${titleCase(
                  toField,
                )}" Events`}
              >
                {manipulator[toField].map(
                  (to: IToEventDefinition, index: number) => {
                    return (
                      <TheForm
                        to={to}
                        index={index}
                        toField={toField}
                        key={index}
                        ruleIndex={ruleIndex}
                        manipulatorIndex={manipulatorIndex}
                        manipulator={manipulator}
                      />
                    );
                  },
                )}
                <Box mt={2}>
                  <Button
                    variant="contained"
                    color="primary"
                    onClick={() => {
                      addToEventForm(toField);
                    }}
                    fullWidth
                  >
                    add {toField} event
                  </Button>
                </Box>
              </AppExpansionPanel>
            ) : (
              <Box mt={2}>
                <Button
                  variant="contained"
                  color="primary"
                  onClick={() => {
                    addToEventForm(toField);
                  }}
                  fullWidth
                >
                  add {toField} event
                </Button>
              </Box>
            )}
          </Box>
        );
      })}

      <AppExpansionPanel
        title={`${totalDelayedAction} "To Delayed Action" Events`}
      >
        {toDelayedAction.map((toField: string) => {
          return (
            <Box key={toField}>
              {manipulator?.to_delayed_action?.[toField]?.length ? (
                <AppExpansionPanel
                  key={toField}
                  title={`${
                    manipulator.to_delayed_action[toField].length
                  } "${titleCase(toField)}" Events`}
                >
                  {manipulator.to_delayed_action[toField].map(
                    (to: IToEventDefinition, index: number) => {
                      return (
                        <TheForm
                          to={to}
                          index={index}
                          toField={toField}
                          key={index}
                          ruleIndex={ruleIndex}
                          manipulatorIndex={manipulatorIndex}
                          manipulator={manipulator}
                        />
                      );
                    },
                  )}
                  <Box mt={2}>
                    <Button
                      variant="contained"
                      color="primary"
                      size="small"
                      onClick={() => {
                        addToEventForm(toField);
                      }}
                    >
                      Add {toField} Event
                    </Button>
                  </Box>
                </AppExpansionPanel>
              ) : (
                <Box mb={2}>
                  <Button
                    variant="contained"
                    color="primary"
                    fullWidth
                    onClick={() => {
                      addToEventForm(toField);
                    }}
                  >
                    Add {toField} Event
                  </Button>
                </Box>
              )}
            </Box>
          );
        })}
      </AppExpansionPanel>
    </Box>
  );
};

export default ToEventFormsContainer;


================================================
FILE: src/components/forms/VariableConditionForm.tsx
================================================
import React from 'react';
import { Box, TextField } from '@material-ui/core';
import ICondition from '../../types/ICondition';
import Autocomplete from '@material-ui/lab/Autocomplete';

interface Props {
  condition: ICondition;
  setConditionState: (arg0: ICondition) => void;
}

const VariableConditionForm: React.FC<Props> = ({
  condition,
  setConditionState,
}) => {
  return (
    <Box>
      <TextField
        fullWidth
        label="Variable Name"
        variant="filled"
        value={condition.name}
        onChange={e => {
          setConditionState({ ...condition, name: e.target.value });
        }}
      />
      <TextField
        fullWidth
        label="Variable Value"
        variant="filled"
        value={condition.value}
        onChange={e => {
          setConditionState({ ...condition, value: e.target.value });
        }}
      />
    </Box>
  );
};

export default VariableConditionForm;


================================================
FILE: src/components/shared/AppExpansionPanel.tsx
================================================
import React, { ReactChild } from 'react';
import {
  Typography,
  ExpansionPanelSummary,
  ExpansionPanel,
  Box,
  TextField,
  Button,
} from '@material-ui/core';
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';

interface Props {
  title: any;
  children: any;
  panelProps?: any;
}

const AppExpansionPanel: React.FC<Props> = ({
  title,
  children,
  panelProps = {},
}) => {
  return (
    <ExpansionPanel
      {...panelProps}
      aria-label="Expand"
      aria-controls="additional-actions3-content"
    >
      <ExpansionPanelSummary expandIcon={<ExpandMoreIcon />}>
        {title}
      </ExpansionPanelSummary>
      <Box p={2}>{children}</Box>
    </ExpansionPanel>
  );
};

export default AppExpansionPanel;


================================================
FILE: src/components/shared/AppSelect.tsx
================================================
import React, { useMemo } from 'react';
import { Select, FormControl, InputLabel, MenuItem } from '@material-ui/core';
import { titleCase } from '../../helpers';

interface Props {
  label: string;
  value: string;
  options: any[];
  onChange: any; //TODO: event function
}

const AppSelect: React.FC<Props> = ({
  label,
  value,
  options,
  onChange = () => {},
}) => {
  return useMemo(
    () => (
      <FormControl variant="filled" fullWidth>
        <InputLabel id="type">{label}</InputLabel>
        <Select labelId="type" value={value} onChange={onChange}>
          {options.map(option => (
            <MenuItem value={option} key={option}>
              {titleCase(option)}
            </MenuItem>
          ))}
        </Select>
      </FormControl>
    ),
    [label, value, options],
  );
};

export default AppSelect;


================================================
FILE: src/components/shared/KeyCodeAndPointingButtonInput.tsx
================================================
import React, { useEffect, useState, useMemo } from 'react';
import {
  InputLabel,
  Select,
  MenuItem,
  TextField,
  ButtonGroup,
  Button,
  Typography,
  FormControl,
  Box,
} from '@material-ui/core';
import KeyInput from './KeyInput';
const pointingButtons: any[] = [
  {
    label: 'None',
    value: '',
  },
  {
    label: 'Left Click',
    value: 'button1',
  },
  {
    label: 'Right Click',
    value: 'button2',
  },
  {
    label: 'Middle Click',
    value: 'button3',
  },
  {
    label: 'Mouse 4',
    value: 'button4',
  },
  {
    label: 'Mouse 5',
    value: 'button5',
  },
];

interface Props {
  eventObject: any;
  setEventObject: (obj: any) => void;
}

const KeyCodeAndPointingButtonInput: React.FC<Props> = ({
  eventObject = {},
  setEventObject = obj => {},
}) => {
  const [showOptional, setShowOptional] = useState({
    keyCode: false,
    consumerKeyCode: false,
  });

  useEffect(() => {
    const newOptional = {
      keyCode: !!eventObject.key_code,
      consumerKeyCode: !!eventObject.consumer_key_code,
    };
    console.log(eventObject.key_code);
    setShowOptional(newOptional);
  }, [eventObject.consumer_key_code, eventObject.key_code]);

  return useMemo(
    () => (
      <Box marginBottom={2}>
        <ButtonGroup>
          <Button
            disabled={showOptional.keyCode}
            variant="contained"
            onClick={() => {
              setShowOptional({
                ...showOptional,
                keyCode: true,
                consumerKeyCode: false,
              });
            }}
          >
            Key Code
          </Button>
          <Button
            disabled={showOptional.consumerKeyCode}
            variant="contained"
            onClick={() => {
              setShowOptional({
                ...showOptional,
                keyCode: false,
                consumerKeyCode: true,
              });
            }}
          >
            Consumer Key Code
          </Button>
          <Button
            variant="contained"
            onClick={() => {
              setShowOptional({
                ...showOptional,
                keyCode: false,
                consumerKeyCode: false,
              });
            }}
            disabled={!(showOptional.keyCode || showOptional.consumerKeyCode)}
            color="secondary"
          >
            Disable
          </Button>
        </ButtonGroup>
        <Box marginBottom={1}>
          {showOptional.keyCode && (
            <Box marginTop={2} marginBottom={3}>
              <KeyInput
                keyCodes
                modifiers
                multiple={false}
                value={eventObject.key_code}
                autoHighlight={false}
                label="Key Code (optional)"
                onChange={(_e: any, v: any) => {
                  setEventObject({
                    ...eventObject,
                    key_code:
                      typeof v === 'string' ? { label: v, value: v } : v,
                  });
                }}
              />
            </Box>
          )}
          {showOptional.consumerKeyCode && (
            <TextField
              placeholder=""
              margin="normal"
              variant="filled"
              label="Consumer Key Code (optional)"
              fullWidth
              value={eventObject.consumer_key_code || ''}
              onChange={e => {
                setEventObject({
                  ...eventObject,
                  consumer_key_code: e.currentTarget.value,
                });
              }}
            />
          )}
        </Box>

        <Box mt={2} mb={3}>
          <FormControl variant="filled" fullWidth>
            <InputLabel id="type">Pointing Button (optional)</InputLabel>
            <Select
              labelId="type"
              value={eventObject.pointing_button || ''}
              onChange={(event: any) => {
                setEventObject({
                  ...eventObject,
                  pointing_button: event.target.value || '',
                });
              }}
            >
              {pointingButtons.map(({ label, value }) => (
                <MenuItem value={value} key={value}>
                  {label}
                </MenuItem>
              ))}
            </Select>
          </FormControl>
        </Box>
      </Box>
    ),
    [showOptional, eventObject],
  );
};

export default KeyCodeAndPointingButtonInput;


================================================
FILE: src/components/shared/KeyInput.tsx
================================================
import React from 'react';
import Autocomplete from '@material-ui/lab/Autocomplete';
import { MODIFIERS, KEY_CODES } from '../../constants';
import { TextField } from '@material-ui/core';
import Modifier from '../../types/Modifier';

interface Props {
  // value: Modifier[];
  value: any;
  onChange: (e: any, value: any) => void;
  modifiers?: boolean;
  keyCodes?: boolean;
  multiple?: any;
  autoHighlight?: boolean;
  freeSolo?: boolean;
  label?: string;
}

const KeyInput: React.FC<Props> = ({
  value = [],
  onChange = e => {},
  modifiers = false,
  keyCodes = false,
  multiple = true,
  autoHighlight = false,
  freeSolo = true,
  label = 'keys',
}) => {
  let options: Modifier[] = [];
  let placeholderText: string[] = [];
  if (keyCodes) {
    options = [...options, ...KEY_CODES];
    placeholderText.push('Key Codes');
  }
  if (modifiers) {
    options = [...options, ...MODIFIERS];
    placeholderText.push('Modifiers');
  }
  return (
    <Autocomplete
      multiple={multiple}
      freeSolo={freeSolo}
      options={options}
      getOptionLabel={(o: any) => (typeof o === 'object' ? o.label : o) || ''}
      value={typeof value === 'string' ? [value] : value}
      onChange={onChange}
      autoHighlight={autoHighlight}
      renderInput={params => (
        <TextField
          {...params}
          variant="filled"
          label={label}
          placeholder={placeholderText.join(', ')}
          fullWidth
        />
      )}
    />
  );
};

export default KeyInput;


================================================
FILE: src/constants.ts
================================================
export const MODIFIERS = [
  {
    label: 'Function key',
    value: 'fn',
  },
  {
    label: 'Left Command',
    value: 'left_gui',
  },
  {
    label: 'Right Command',
    value: 'right_gui',
  },
  {
    label: 'Left Control',
    value: 'left_control',
  },
  {
    label: 'Right Control',
    value: 'right_control',
  },
  {
    label: 'Left Alt / Option',
    value: 'left_alt',
  },
  {
    label: 'Right Alt / Option',
    value: 'right_alt',
  },
  {
    label: 'Left Shift',
    value: 'left_shift',
  },
  {
    label: 'Right Shift',
    value: 'right_shift',
  },
];
export const KEY_CODES = [
  {
    label: '1',
    value: '1',
  },
  {
    label: '2',
    value: '2',
  },
  {
    label: '3',
    value: '3',
  },
  {
    label: '4',
    value: '4',
  },
  {
    label: '5',
    value: '5',
  },
  {
    label: '6',
    value: '6',
  },
  {
    label: '7',
    value: '7',
  },
  {
    label: '8',
    value: '8',
  },
  {
    label: '9',
    value: '9',
  },
  {
    label: '0',
    value: '0',
  },
  {
    label: 'A',
    value: 'a',
  },
  {
    label: 'B',
    value: 'b',
  },
  {
    label: 'C',
    value: 'c',
  },
  {
    label: 'D',
    value: 'd',
  },
  {
    label: 'E',
    value: 'e',
  },
  {
    label: 'F',
    value: 'f',
  },
  {
    label: 'G',
    value: 'g',
  },
  {
    label: 'H',
    value: 'h',
  },
  {
    label: 'I',
    value: 'i',
  },
  {
    label: 'J',
    value: 'j',
  },
  {
    label: 'K',
    value: 'k',
  },
  {
    label: 'L',
    value: 'l',
  },
  {
    label: 'M',
    value: 'm',
  },
  {
    label: 'N',
    value: 'n',
  },
  {
    label: 'O',
    value: 'o',
  },
  {
    label: 'P',
    value: 'p',
  },
  {
    label: 'Q',
    value: 'q',
  },
  {
    label: 'R',
    value: 'r',
  },
  {
    label: 'S',
    value: 's',
  },
  {
    label: 'T',
    value: 't',
  },
  {
    label: 'U',
    value: 'u',
  },
  {
    label: 'V',
    value: 'v',
  },
  {
    label: 'W',
    value: 'w',
  },
  {
    label: 'X',
    value: 'x',
  },
  {
    label: 'Y',
    value: 'y',
  },
  {
    label: 'Z',
    value: 'z',
  },
  {
    label: 'F1',
    value: 'f1',
  },
  {
    label: 'F2',
    value: 'f2',
  },
  {
    label: 'F3',
    value: 'f3',
  },
  {
    label: 'F4',
    value: 'f4',
  },
  {
    label: 'F5',
    value: 'f5',
  },
  {
    label: 'F6',
    value: 'f6',
  },
  {
    label: 'F7',
    value: 'f7',
  },
  {
    label: 'F8',
    value: 'f8',
  },
  {
    label: 'F9',
    value: 'f9',
  },
  {
    label: 'F10',
    value: 'f10',
  },
  {
    label: 'F11',
    value: 'f11',
  },
  {
    label: 'F12',
    value: 'f12',
  },
  {
    label: 'F12',
    value: 'f12',
  },
  {
    label: 'F12',
    value: 'f12',
  },
  {
    label: 'F13',
    value: 'f13',
  },
  {
    label: 'F14',
    value: 'f14',
  },
  {
    label: 'F15',
    value: 'f15',
  },
  {
    label: 'F16',
    value: 'f16',
  },
  {
    label: 'F17',
    value: 'f17',
  },
  {
    label: 'F18',
    value: 'f18',
  },
  {
    label: 'F19',
    value: 'f19',
  },
  {
    label: 'Escape',
    value: 'escape',
  },
  {
    label: '` Grave Accent, Tilde',
    value: 'grave_accent_and_tilde',
  },
  {
    label: 'Tab key',
    value: 'tab',
  },
  {
    label: 'Caps Lock',
    value: 'caps_lock',
  },
  {
    label: 'Spacebar',
    value: 'spacebar',
  },
  {
    label: 'Up Arrow',
    value: 'up_arrow',
  },
  {
    label: 'Left Arrow',
    value: 'left_arrow',
  },
  {
    label: 'Down Arrow',
    value: 'down_arrow',
  },
  {
    label: 'Right Arrow',
    value: 'right_arrow',
  },
  {
    label: 'Enter',
    value: 'return_or_enter',
  },
  {
    label: ' (Backslash)',
    value: 'backslash',
  },
  {
    label: '[ (Open Bracket)',
    value: 'open_bracket',
  },
  {
    label: '] (Close Bracket)',
    value: 'close_bracket',
  },
  {
    label: '; (Semicolon)',
    value: 'semicolon',
  },
  {
    label: "' (Quote)",
    value: 'quote',
  },
  {
    label: ', (Comma)',
    value: 'comma',
  },
  {
    label: '. (Period)',
    value: 'period',
  },
  {
    label: '/ (Slash)',
    value: 'slash',
  },
  {
    label: '- (Dash or Hyphen)',
    value: 'hyphen',
  },
  {
    label: '= (Equal)',
    value: 'equal_sign',
  },
  {
    label: 'Delete or Backspace',
    value: 'delete_or_backspace',
  },
  {
    label: 'Decrease Screen Brightness',
    value: 'display_brightness_decrement',
  },
  {
    label: 'Increase Screen Brightness',
    value: 'display_brightness_increment',
  },
  {
    label: 'Mission Control',
    value: 'mission_control',
  },
  {
    label: 'Launchpad',
    value: 'launchpad',
  },
  {
    label: 'Keyboard Brightness Decrease',
    value: 'illumination_decrement',
  },
  {
    label: 'Keyboard Brightness Increase',
    value: 'illumination_increment',
  },
  {
    label: 'Rewind / Previous',
    value: 'rewind',
  },
  {
    label: 'Play or Pause',
    value: 'play_or_pause',
  },
  {
    label: 'Fastforward / Next',
    value: 'fastforward',
  },
  {
    label: 'Mute',
    value: 'mute',
  },
  {
    label: 'Volume Down',
    value: 'volume_decrement',
  },
  {
    label: 'Volume Up',
    value: 'volume_increment',
  },
];

export const ALL_KEYS = [...MODIFIERS, ...KEY_CODES];


================================================
FILE: src/ducks/formState.ts
================================================
import IRule from '../types/IRule';
import IManipulator from '../types/IManipulator';
import _ from 'lodash';
import IFormState from '../types/IFormState';
import produce from 'immer';
import IFromEventDefinition from '../types/IFromEventDefinition';
import IToEventDefinition from '../types/IToEventDefinition';

export const initialManipulator: IManipulator = {
  type: 'basic',
  from: {
    modifiers: {
      mandatory: [],
      optional: [],
    },
    simultaneous: [],
    simultaneous_options: {
      detect_key_down_uninterruptedly: false,
      to_after_key_up: [],
    },
  },
  conditions: [],
  to: [],
  to_after_key_up: [],
  to_if_alone: [],
  to_if_held_down: [],
  to_delayed_action: {
    to_if_invoked: [],
    to_if_canceled: [],
  },
};

const getInitialRule = (): IRule => {
  return {
    description: '',
    manipulators: [initialManipulator],
  };
};
const initialFormState: IFormState = {
  title: '',
  rules: [getInitialRule()],
};

const SET_TITLE = 'SET_TITLE';
const ADD_RULE = 'ADD_RULE';
const REMOVE_RULE = 'REMOVE_RULE';
const SET_RULE = 'SET_RULE';
const ADD_MANIPULATOR = 'ADD_MANIPULATOR';
const SET_MANIPULATOR = 'SET_MANIPULATOR';
const SET_FROM_OBJECT = 'SET_FROM_OBJECT';
const ADD_TO_OBJECT = 'ADD_TO_OBJECT';
const SET_TO_OBJECT = 'SET_TO_OBJECT';
const SET_WHOLE_STATE = 'SET_WHOLE_STATE';

export const formStateReducer = (state = initialFormState, action: any) => {
  return produce(state, draft => {
    switch (action.type) {
      case SET_WHOLE_STATE:
        draft.title = action.payload.state.title;
        draft.rules = action.payload.state.rules;
        break;
      case REMOVE_RULE:
        draft.rules.splice(action.payload.index, 1);
        break;
      case SET_TITLE:
        draft.title = action.payload.title;
        break;

      case ADD_RULE:
        draft.rules.push(getInitialRule());
        break;
      case SET_RULE:
        if (action.payload) {
          const { rule, index } = action.payload;
          draft.rules[index] = rule;
        }
        break;
      case ADD_MANIPULATOR:
        if (action.payload) {
          const { ruleIndex } = action.payload;
          draft.rules[ruleIndex].manipulators.push(initialManipulator);
        }
        break;
      case SET_MANIPULATOR:
        if (action.payload) {
          const { ruleIndex, index, manipulator } = action.payload;
          draft.rules[ruleIndex].manipulators[index] = manipulator;
        }
        break;
      case SET_FROM_OBJECT:
        if (action.payload) {
          const { ruleIndex, manipulatorIndex, fromObject } = action.payload;
          draft.rules[ruleIndex].manipulators[
            manipulatorIndex
          ].from = fromObject;
        }
        break;
      case ADD_TO_OBJECT:
        if (action.payload) {
          const { toField, ruleIndex, manipulatorIndex } = action.payload;
          const initToObj = {
            repeat: true,
          };
          const manip = draft.rules[ruleIndex].manipulators[manipulatorIndex];
          if (toField === 'to_if_canceled' || toField === 'to_if_invoked') {
            if (toField === 'to_if_canceled') {
              manip.to_delayed_action.to_if_canceled.push(initToObj);
            } else {
              manip.to_delayed_action.to_if_invoked.push(initToObj);
            }
          } else {
            manip[toField].push(initToObj);
          }
        }
        break;
      case SET_TO_OBJECT:
        if (action.payload) {
          const {
            toField,
            ruleIndex,
            manipulatorIndex,
            toIndex,
            toObject,
          } = action.payload;

          // TODO: wtf is this can i fix this someday pls
          draft.rules[ruleIndex].manipulators[manipulatorIndex][toField][
            toIndex
          ] = toObject;
        }
        break;
      default:
        break;
    }
  });
};

export const setWholeState = (state: any) => {
  return {
    type: SET_WHOLE_STATE,
    payload: { state },
  };
};

export const setTitle = (title: string) => {
  return {
    type: SET_TITLE,
    payload: {
      title,
    },
  };
};

export const addRule = () => {
  return {
    type: ADD_RULE,
  };
};

export const removeRule = (index?: number) => {
  return {
    type: REMOVE_RULE,
    payload: {
      index,
    },
  };
};

export const setRule = (index: number, rule: IRule) => {
  return {
    type: SET_RULE,
    payload: {
      index,
      rule,
    },
  };
};

export const addManipulator = (ruleIndex: number) => {
  return {
    type: ADD_MANIPULATOR,
    payload: {
      ruleIndex,
    },
  };
};

export const setManipulator = ({
  ruleIndex,
  index,
  manipulator,
}: {
  ruleIndex: number;
  index: number;
  manipulator: IManipulator;
}) => {
  return {
    type: SET_MANIPULATOR,
    payload: {
      ruleIndex,
      index,
      manipulator,
    },
  };
};

export const setFromObject = ({
  ruleIndex,
  manipulatorIndex,
  fromObject,
}: {
  ruleIndex: number;
  manipulatorIndex: number;
  fromObject: IFromEventDefinition;
}) => {
  return {
    type: SET_FROM_OBJECT,
    payload: {
      ruleIndex,
      manipulatorIndex,
      fromObject,
    },
  };
};

export const addToObject = ({
  ruleIndex,
  manipulatorIndex,
  toField,
}: {
  ruleIndex: number;
  manipulatorIndex: number;
  toField: string;
}) => {
  return {
    type: ADD_TO_OBJECT,
    payload: {
      ruleIndex,
      manipulatorIndex,
      toField,
    },
  };
};

export const setToObject = ({
  ruleIndex,
  manipulatorIndex,
  toField,
  toIndex,
  toObject,
}: {
  ruleIndex: number;
  manipulatorIndex: number;
  toField: string;
  toIndex: number;
  toObject: IToEventDefinition;
}) => {
  return {
    type: SET_TO_OBJECT,
    payload: {
      ruleIndex,
      manipulatorIndex,
      toField,
      toIndex,
      toObject,
    },
  };
};


================================================
FILE: src/helpers.ts
================================================
export const suffix = (n: number) => {
  var s = ['th', 'st', 'nd', 'rd'];
  var d = (n | 0) % 100;
  return d > 3 && d < 21 ? 'th' : s[d % 10] || 'th';
};

export const withSuffix = (n: number) => {
  return `${n}${suffix(n)}`;
};

export const titleCase = (string: string) => {
  var sentence = string.toLowerCase().split('_');
  for (var i = 0; i < sentence.length; i++) {
    sentence[i] = sentence[i][0].toUpperCase() + sentence[i].slice(1);
  }
  return sentence.join(' ');
};


================================================
FILE: src/index.css
================================================
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

code {
  font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
    monospace;
}


================================================
FILE: src/index.tsx
================================================
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';

ReactDOM.render(<App />, document.getElementById('root'));

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();


================================================
FILE: src/react-app-env.d.ts
================================================
/// <reference types="react-scripts" />


================================================
FILE: src/serviceWorker.ts
================================================
// This optional code is used to register a service worker.
// register() is not called by default.

// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on subsequent visits to a page, after all the
// existing tabs open on the page have been closed, since previously cached
// resources are updated in the background.

// To learn more about the benefits of this model and instructions on how to
// opt-in, read https://bit.ly/CRA-PWA

const isLocalhost = Boolean(
  window.location.hostname === 'localhost' ||
    // [::1] is the IPv6 localhost address.
    window.location.hostname === '[::1]' ||
    // 127.0.0.0/8 are considered localhost for IPv4.
    window.location.hostname.match(
      /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
    )
);

type Config = {
  onSuccess?: (registration: ServiceWorkerRegistration) => void;
  onUpdate?: (registration: ServiceWorkerRegistration) => void;
};

export function register(config?: Config) {
  if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
    // The URL constructor is available in all browsers that support SW.
    const publicUrl = new URL(
      process.env.PUBLIC_URL,
      window.location.href
    );
    if (publicUrl.origin !== window.location.origin) {
      // Our service worker won't work if PUBLIC_URL is on a different origin
      // from what our page is served on. This might happen if a CDN is used to
      // serve assets; see https://github.com/facebook/create-react-app/issues/2374
      return;
    }

    window.addEventListener('load', () => {
      const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;

      if (isLocalhost) {
        // This is running on localhost. Let's check if a service worker still exists or not.
        checkValidServiceWorker(swUrl, config);

        // Add some additional logging to localhost, pointing developers to the
        // service worker/PWA documentation.
        navigator.serviceWorker.ready.then(() => {
          console.log(
            'This web app is being served cache-first by a service ' +
              'worker. To learn more, visit https://bit.ly/CRA-PWA'
          );
        });
      } else {
        // Is not localhost. Just register service worker
        registerValidSW(swUrl, config);
      }
    });
  }
}

function registerValidSW(swUrl: string, config?: Config) {
  navigator.serviceWorker
    .register(swUrl)
    .then(registration => {
      registration.onupdatefound = () => {
        const installingWorker = registration.installing;
        if (installingWorker == null) {
          return;
        }
        installingWorker.onstatechange = () => {
          if (installingWorker.state === 'installed') {
            if (navigator.serviceWorker.controller) {
              // At this point, the updated precached content has been fetched,
              // but the previous service worker will still serve the older
              // content until all client tabs are closed.
              console.log(
                'New content is available and will be used when all ' +
                  'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
              );

              // Execute callback
              if (config && config.onUpdate) {
                config.onUpdate(registration);
              }
            } else {
              // At this point, everything has been precached.
              // It's the perfect time to display a
              // "Content is cached for offline use." message.
              console.log('Content is cached for offline use.');

              // Execute callback
              if (config && config.onSuccess) {
                config.onSuccess(registration);
              }
            }
          }
        };
      };
    })
    .catch(error => {
      console.error('Error during service worker registration:', error);
    });
}

function checkValidServiceWorker(swUrl: string, config?: Config) {
  // Check if the service worker can be found. If it can't reload the page.
  fetch(swUrl, {
    headers: { 'Service-Worker': 'script' }
  })
    .then(response => {
      // Ensure service worker exists, and that we really are getting a JS file.
      const contentType = response.headers.get('content-type');
      if (
        response.status === 404 ||
        (contentType != null && contentType.indexOf('javascript') === -1)
      ) {
        // No service worker found. Probably a different app. Reload the page.
        navigator.serviceWorker.ready.then(registration => {
          registration.unregister().then(() => {
            window.location.reload();
          });
        });
      } else {
        // Service worker found. Proceed as normal.
        registerValidSW(swUrl, config);
      }
    })
    .catch(() => {
      console.log(
        'No internet connection found. App is running in offline mode.'
      );
    });
}

export function unregister() {
  if ('serviceWorker' in navigator) {
    navigator.serviceWorker.ready
      .then(registration => {
        registration.unregister();
      })
      .catch(error => {
        console.error(error.message);
      });
  }
}


================================================
FILE: src/setupTests.ts
================================================
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom/extend-expect';


================================================
FILE: src/types/ICondition.ts
================================================
interface IIdentifier {
  [key: string]: any;
  vendor_id?: number;
  product_id?: number;
  description?: string;
  is_keyboard?: boolean;
  is_pointing_device?: boolean;
}
export default interface ICondition {
  type: string;
  bundle_identifiers?: string[];
  file_paths?: string[];
  identifiers?: IIdentifier[];
  keyboard_types?: string[];
  input_sources?: string[];
  name?: string;
  value?: string;
  description?: string;
}


================================================
FILE: src/types/IFormState.ts
================================================
import IRule from './IRule';

export default interface IFormState {
  title: string;
  rules: IRule[];
}


================================================
FILE: src/types/IFromEventDefinition.ts
================================================
import ISimultaneous from './ISimultaneous';
import KeyOrder from './KeyOrder';
import KeyUpWhen from './KeyUpWhen';
import PointingButton from './PointingButton';
import IToEventDefinition from './IToEventDefinition';
import Modifier from './Modifier';

interface ISimultaneousOptions {
  detect_key_down_uninterruptedly?: Boolean;
  key_down_order?: KeyOrder | unknown;
  key_up_order?: KeyOrder | unknown;
  key_up_when?: KeyUpWhen | unknown;
  to_after_key_up: IToEventDefinition[];
}
export default interface IFromEventDefinition {
  key_code?: string;
  consumer_key_code?: string;
  pointing_button?: PointingButton;
  modifiers?: {
    mandatory?: any[];
    optional?: any[];
  };
  simultaneous: ISimultaneous[];
  simultaneous_options: ISimultaneousOptions;
}


================================================
FILE: src/types/IManipulator.ts
================================================
import IFromEventDefinition from './IFromEventDefinition';
import IToEventDefinition from './IToEventDefinition';
import ICondition from './ICondition';

interface IToDelayedAction {
  to_if_invoked: IToEventDefinition[];
  to_if_canceled: IToEventDefinition[];
}
export default interface IManipulator {
  [key: string]: any;
  type: string;
  from: IFromEventDefinition;
  description?: string;
  to: IToEventDefinition[];
  to_if_alone: IToEventDefinition[];
  to_if_held_down: IToEventDefinition[];
  to_after_key_up: IToEventDefinition[];
  to_delayed_action: IToDelayedAction | any;
  conditions: ICondition[];
  parameters?: any;
  _id?: string;
}


================================================
FILE: src/types/IMouseKey.ts
================================================
export default interface IMouseKEy {
  x?: Number;
  y?: Number;
  vertical_wheel?: Number;
  horizontal_wheel?: Number;
  speed_multiplier?: Number;
}


================================================
FILE: src/types/IRule.ts
================================================
import IFromEventDefinition from './IFromEventDefinition';
import IToEventDefinition from './IToEventDefinition';
import IManipulator from './IManipulator';

export default interface IRule {
  description: string;
  manipulators: IManipulator[];
  _id?: string;
}


================================================
FILE: src/types/ISimultaneous.ts
================================================
export default interface ISimultaneous {
  // TODO: add keycode label value type
  key_code?: string | any;
  consumer_code?: string | any;
  pointing_button?: string;
  _id?: string;
}


================================================
FILE: src/types/IToEventDefinition.ts
================================================
import IMouseKEy from './IMouseKey';

export default interface IToEventDefinition {
  key_code?: string;
  consumer_key_code?: string;
  pointing_button?: string;
  shell_command?: string;
  select_input_source?: string; // TODO: figure this out
  set_variable?: string;
  mouse_key?: IMouseKEy;
  modifiers?: string[];
  lazy?: Boolean;
  repeat?: Boolean;
  halt?: Boolean;
  hold_down_milliseconds?: Number;
  _id?: string;
}


================================================
FILE: src/types/KeyOrder.ts
================================================
declare type KeyOrder = 'insensitive' | 'strict' | 'strict_inverse';
export default KeyOrder;


================================================
FILE: src/types/KeyUpWhen.ts
================================================
declare type KeyUpWhen = 'any' | 'all';
export default KeyUpWhen;


================================================
FILE: src/types/Modifier.ts
================================================
declare type Modifier = {
  label: string;
  value: string;
};

export default Modifier;


================================================
FILE: src/types/PointingButton.ts
================================================
declare type PointingButton =
  | 'disabled'
  | 'button1'
  | 'button2'
  | 'button3'
  | 'button4'
  | 'button5';
export default PointingButton;


================================================
FILE: tsconfig.json
================================================
{
  "compilerOptions": {
    "downlevelIteration": true,
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "declaration": true,
    "jsx": "react"
  },
  "include": ["src"]
}
Download .txt
gitextract_7_26yhlx/

├── .eslintrc
├── .gitignore
├── .prettierrc
├── LICENSE
├── README.md
├── package.json
├── public/
│   ├── index.html
│   ├── manifest.json
│   └── robots.txt
├── src/
│   ├── App.css
│   ├── App.test.tsx
│   ├── App.tsx
│   ├── AppLayout.tsx
│   ├── components/
│   │   ├── MainForm.tsx
│   │   ├── forms/
│   │   │   ├── AddConditionForm.tsx
│   │   │   ├── DeviceIfConditionForm.tsx
│   │   │   ├── EventChangedConditionForm.tsx
│   │   │   ├── FromEventForm.tsx
│   │   │   ├── FrontmostConditionForm.tsx
│   │   │   ├── InputSourceConditionForm.tsx
│   │   │   ├── KeyboardTypeConditionForm.tsx
│   │   │   ├── ManipulatorForm.tsx
│   │   │   ├── RuleForm.tsx
│   │   │   ├── ToEventForm.tsx
│   │   │   ├── ToEventFormsContainer.tsx
│   │   │   └── VariableConditionForm.tsx
│   │   └── shared/
│   │       ├── AppExpansionPanel.tsx
│   │       ├── AppSelect.tsx
│   │       ├── KeyCodeAndPointingButtonInput.tsx
│   │       └── KeyInput.tsx
│   ├── constants.ts
│   ├── ducks/
│   │   └── formState.ts
│   ├── helpers.ts
│   ├── index.css
│   ├── index.tsx
│   ├── react-app-env.d.ts
│   ├── serviceWorker.ts
│   ├── setupTests.ts
│   └── types/
│       ├── ICondition.ts
│       ├── IFormState.ts
│       ├── IFromEventDefinition.ts
│       ├── IManipulator.ts
│       ├── IMouseKey.ts
│       ├── IRule.ts
│       ├── ISimultaneous.ts
│       ├── IToEventDefinition.ts
│       ├── KeyOrder.ts
│       ├── KeyUpWhen.ts
│       ├── Modifier.ts
│       └── PointingButton.ts
└── tsconfig.json
Download .txt
SYMBOL INDEX (53 symbols across 34 files)

FILE: src/App.tsx
  function App (line 12) | function App() {

FILE: src/AppLayout.tsx
  type Props (line 13) | interface Props {}

FILE: src/components/MainForm.tsx
  type Props (line 23) | interface Props {}
  type FormState (line 24) | interface FormState {

FILE: src/components/forms/AddConditionForm.tsx
  type Props (line 22) | interface Props {

FILE: src/components/forms/DeviceIfConditionForm.tsx
  type Props (line 14) | interface Props {

FILE: src/components/forms/EventChangedConditionForm.tsx
  type Props (line 14) | interface Props {

FILE: src/components/forms/FromEventForm.tsx
  type Props (line 29) | interface Props {

FILE: src/components/forms/FrontmostConditionForm.tsx
  type Props (line 6) | interface Props {

FILE: src/components/forms/InputSourceConditionForm.tsx
  type Props (line 6) | interface Props {

FILE: src/components/forms/KeyboardTypeConditionForm.tsx
  type Props (line 15) | interface Props {

FILE: src/components/forms/ManipulatorForm.tsx
  type Props (line 48) | interface Props {

FILE: src/components/forms/RuleForm.tsx
  type Props (line 13) | interface Props {

FILE: src/components/forms/ToEventForm.tsx
  type Props (line 19) | interface Props {

FILE: src/components/forms/ToEventFormsContainer.tsx
  type Props (line 21) | interface Props {

FILE: src/components/forms/VariableConditionForm.tsx
  type Props (line 6) | interface Props {

FILE: src/components/shared/AppExpansionPanel.tsx
  type Props (line 12) | interface Props {

FILE: src/components/shared/AppSelect.tsx
  type Props (line 5) | interface Props {

FILE: src/components/shared/KeyCodeAndPointingButtonInput.tsx
  type Props (line 41) | interface Props {

FILE: src/components/shared/KeyInput.tsx
  type Props (line 7) | interface Props {

FILE: src/constants.ts
  constant MODIFIERS (line 1) | const MODIFIERS = [
  constant KEY_CODES (line 39) | const KEY_CODES = [
  constant ALL_KEYS (line 402) | const ALL_KEYS = [...MODIFIERS, ...KEY_CODES];

FILE: src/ducks/formState.ts
  constant SET_TITLE (line 44) | const SET_TITLE = 'SET_TITLE';
  constant ADD_RULE (line 45) | const ADD_RULE = 'ADD_RULE';
  constant REMOVE_RULE (line 46) | const REMOVE_RULE = 'REMOVE_RULE';
  constant SET_RULE (line 47) | const SET_RULE = 'SET_RULE';
  constant ADD_MANIPULATOR (line 48) | const ADD_MANIPULATOR = 'ADD_MANIPULATOR';
  constant SET_MANIPULATOR (line 49) | const SET_MANIPULATOR = 'SET_MANIPULATOR';
  constant SET_FROM_OBJECT (line 50) | const SET_FROM_OBJECT = 'SET_FROM_OBJECT';
  constant ADD_TO_OBJECT (line 51) | const ADD_TO_OBJECT = 'ADD_TO_OBJECT';
  constant SET_TO_OBJECT (line 52) | const SET_TO_OBJECT = 'SET_TO_OBJECT';
  constant SET_WHOLE_STATE (line 53) | const SET_WHOLE_STATE = 'SET_WHOLE_STATE';

FILE: src/serviceWorker.ts
  type Config (line 23) | type Config = {
  function register (line 28) | function register(config?: Config) {
  function registerValidSW (line 65) | function registerValidSW(swUrl: string, config?: Config) {
  function checkValidServiceWorker (line 109) | function checkValidServiceWorker(swUrl: string, config?: Config) {
  function unregister (line 139) | function unregister() {

FILE: src/types/ICondition.ts
  type IIdentifier (line 1) | interface IIdentifier {
  type ICondition (line 9) | interface ICondition {

FILE: src/types/IFormState.ts
  type IFormState (line 3) | interface IFormState {

FILE: src/types/IFromEventDefinition.ts
  type ISimultaneousOptions (line 8) | interface ISimultaneousOptions {
  type IFromEventDefinition (line 15) | interface IFromEventDefinition {

FILE: src/types/IManipulator.ts
  type IToDelayedAction (line 5) | interface IToDelayedAction {
  type IManipulator (line 9) | interface IManipulator {

FILE: src/types/IMouseKey.ts
  type IMouseKEy (line 1) | interface IMouseKEy {

FILE: src/types/IRule.ts
  type IRule (line 5) | interface IRule {

FILE: src/types/ISimultaneous.ts
  type ISimultaneous (line 1) | interface ISimultaneous {

FILE: src/types/IToEventDefinition.ts
  type IToEventDefinition (line 3) | interface IToEventDefinition {

FILE: src/types/KeyOrder.ts
  type KeyOrder (line 1) | type KeyOrder = 'insensitive' | 'strict' | 'strict_inverse';

FILE: src/types/KeyUpWhen.ts
  type KeyUpWhen (line 1) | type KeyUpWhen = 'any' | 'all';

FILE: src/types/Modifier.ts
  type Modifier (line 1) | type Modifier = {

FILE: src/types/PointingButton.ts
  type PointingButton (line 1) | type PointingButton =
Condensed preview — 51 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (135K chars).
[
  {
    "path": ".eslintrc",
    "chars": 62,
    "preview": "{\n  \"rules\": {\n    \"react-hooks/exhaustive-deps\": false\n  }\n}\n"
  },
  {
    "path": ".gitignore",
    "chars": 310,
    "preview": "# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.\n\n# dependencies\n/node_modules\n/.pn"
  },
  {
    "path": ".prettierrc",
    "chars": 68,
    "preview": "{\n  \"semi\": true,\n  \"singleQuote\": true,\n  \"trailingComma\": \"all\"\n}\n"
  },
  {
    "path": "LICENSE",
    "chars": 35149,
    "preview": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free "
  },
  {
    "path": "README.md",
    "chars": 4093,
    "preview": "[![Forks][forks-shield]][forks-url]\n[![Stargazers][stars-shield]][stars-url]\n[![Issues][issues-shield]][issues-url]\n\n<!-"
  },
  {
    "path": "package.json",
    "chars": 1490,
    "preview": "{\n  \"name\": \"karabiner-complex-rules-generator\",\n  \"version\": \"0.1.0\",\n  \"private\": true,\n  \"dependencies\": {\n    \"@mate"
  },
  {
    "path": "public/index.html",
    "chars": 2204,
    "preview": "<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"utf-8\" />\n    <link rel=\"icon\" href=\"%PUBLIC_URL%/favicon.i"
  },
  {
    "path": "public/manifest.json",
    "chars": 492,
    "preview": "{\n  \"short_name\": \"React App\",\n  \"name\": \"Create React App Sample\",\n  \"icons\": [\n    {\n      \"src\": \"favicon.ico\",\n     "
  },
  {
    "path": "public/robots.txt",
    "chars": 67,
    "preview": "# https://www.robotstxt.org/robotstxt.html\nUser-agent: *\nDisallow:\n"
  },
  {
    "path": "src/App.css",
    "chars": 575,
    "preview": "html,\nbody,\n#root,\n.App {\n  height: 100%;\n}\n\ntextarea {\n  /* height: 80%; */\n  width: 100%;\n  font-size: 12px;\n  backgro"
  },
  {
    "path": "src/App.test.tsx",
    "chars": 280,
    "preview": "import React from 'react';\nimport { render } from '@testing-library/react';\nimport App from './App';\n\ntest('renders lear"
  },
  {
    "path": "src/App.tsx",
    "chars": 480,
    "preview": "import React from 'react';\nimport './App.css';\nimport '@material-ui/core';\nimport 'typeface-roboto';\nimport AppLayout fr"
  },
  {
    "path": "src/AppLayout.tsx",
    "chars": 1159,
    "preview": "import React from 'react';\nimport {\n  Container,\n  AppBar,\n  Typography,\n  Toolbar,\n  Grid,\n  Box,\n} from '@material-ui/"
  },
  {
    "path": "src/components/MainForm.tsx",
    "chars": 9338,
    "preview": "import React, { useMemo, useEffect } from 'react';\nimport RuleForm from './forms/RuleForm';\nimport {\n  Grid,\n  Button,\n "
  },
  {
    "path": "src/components/forms/AddConditionForm.tsx",
    "chars": 3703,
    "preview": "import React, { useState, useEffect } from 'react';\nimport {\n  Box,\n  TextField,\n  FormControl,\n  InputLabel,\n  Select,\n"
  },
  {
    "path": "src/components/forms/DeviceIfConditionForm.tsx",
    "chars": 3698,
    "preview": "import React from 'react';\nimport {\n  Box,\n  TextField,\n  ButtonGroup,\n  Button,\n  Checkbox,\n  FormControlLabel,\n} from "
  },
  {
    "path": "src/components/forms/EventChangedConditionForm.tsx",
    "chars": 1012,
    "preview": "import React from 'react';\nimport {\n  Box,\n  TextField,\n  FormLabel,\n  FormControl,\n  RadioGroup,\n  FormControlLabel,\n  "
  },
  {
    "path": "src/components/forms/FromEventForm.tsx",
    "chars": 10021,
    "preview": "import React, { useMemo } from 'react';\nimport {\n  Box,\n  Button,\n  FormControlLabel,\n  Checkbox,\n  FormControl,\n  Input"
  },
  {
    "path": "src/components/forms/FrontmostConditionForm.tsx",
    "chars": 3622,
    "preview": "import React from 'react';\nimport { Box, TextField, ButtonGroup, Button } from '@material-ui/core';\nimport ICondition fr"
  },
  {
    "path": "src/components/forms/InputSourceConditionForm.tsx",
    "chars": 451,
    "preview": "import React from 'react';\nimport { Box, TextField } from '@material-ui/core';\nimport ICondition from '../../types/ICond"
  },
  {
    "path": "src/components/forms/KeyboardTypeConditionForm.tsx",
    "chars": 1177,
    "preview": "import React from 'react';\nimport {\n  Box,\n  TextField,\n  ButtonGroup,\n  Button,\n  Checkbox,\n  FormControlLabel,\n} from "
  },
  {
    "path": "src/components/forms/ManipulatorForm.tsx",
    "chars": 4123,
    "preview": "import React, { useMemo } from 'react';\nimport {\n  Select,\n  Box,\n  ButtonGroup,\n  FormControl,\n  InputLabel,\n  MenuItem"
  },
  {
    "path": "src/components/forms/RuleForm.tsx",
    "chars": 2232,
    "preview": "import React, { useMemo } from 'react';\nimport { Typography, Box, TextField, Button } from '@material-ui/core';\n\nimport "
  },
  {
    "path": "src/components/forms/ToEventForm.tsx",
    "chars": 4317,
    "preview": "import React, { useState, useEffect, useMemo } from 'react';\nimport KeyCodeAndPointingButtonInput from '../shared/KeyCod"
  },
  {
    "path": "src/components/forms/ToEventFormsContainer.tsx",
    "chars": 6910,
    "preview": "import React from 'react';\nimport { Box, Button, ButtonGroup } from '@material-ui/core';\n\nimport { titleCase, suffix } f"
  },
  {
    "path": "src/components/forms/VariableConditionForm.tsx",
    "chars": 926,
    "preview": "import React from 'react';\nimport { Box, TextField } from '@material-ui/core';\nimport ICondition from '../../types/ICond"
  },
  {
    "path": "src/components/shared/AppExpansionPanel.tsx",
    "chars": 737,
    "preview": "import React, { ReactChild } from 'react';\nimport {\n  Typography,\n  ExpansionPanelSummary,\n  ExpansionPanel,\n  Box,\n  Te"
  },
  {
    "path": "src/components/shared/AppSelect.tsx",
    "chars": 836,
    "preview": "import React, { useMemo } from 'react';\nimport { Select, FormControl, InputLabel, MenuItem } from '@material-ui/core';\ni"
  },
  {
    "path": "src/components/shared/KeyCodeAndPointingButtonInput.tsx",
    "chars": 4436,
    "preview": "import React, { useEffect, useState, useMemo } from 'react';\nimport {\n  InputLabel,\n  Select,\n  MenuItem,\n  TextField,\n "
  },
  {
    "path": "src/components/shared/KeyInput.tsx",
    "chars": 1504,
    "preview": "import React from 'react';\nimport Autocomplete from '@material-ui/lab/Autocomplete';\nimport { MODIFIERS, KEY_CODES } fro"
  },
  {
    "path": "src/constants.ts",
    "chars": 5187,
    "preview": "export const MODIFIERS = [\n  {\n    label: 'Function key',\n    value: 'fn',\n  },\n  {\n    label: 'Left Command',\n    value"
  },
  {
    "path": "src/ducks/formState.ts",
    "chars": 5831,
    "preview": "import IRule from '../types/IRule';\nimport IManipulator from '../types/IManipulator';\nimport _ from 'lodash';\nimport IFo"
  },
  {
    "path": "src/helpers.ts",
    "chars": 483,
    "preview": "export const suffix = (n: number) => {\n  var s = ['th', 'st', 'nd', 'rd'];\n  var d = (n | 0) % 100;\n  return d > 3 && d "
  },
  {
    "path": "src/index.css",
    "chars": 366,
    "preview": "body {\n  margin: 0;\n  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',\n    'Ubuntu', 'Can"
  },
  {
    "path": "src/index.tsx",
    "chars": 452,
    "preview": "import React from 'react';\nimport ReactDOM from 'react-dom';\nimport './index.css';\nimport App from './App';\nimport * as "
  },
  {
    "path": "src/react-app-env.d.ts",
    "chars": 40,
    "preview": "/// <reference types=\"react-scripts\" />\n"
  },
  {
    "path": "src/serviceWorker.ts",
    "chars": 5295,
    "preview": "// This optional code is used to register a service worker.\n// register() is not called by default.\n\n// This lets the ap"
  },
  {
    "path": "src/setupTests.ts",
    "chars": 255,
    "preview": "// jest-dom adds custom jest matchers for asserting on DOM nodes.\n// allows you to do things like:\n// expect(element).to"
  },
  {
    "path": "src/types/ICondition.ts",
    "chars": 435,
    "preview": "interface IIdentifier {\n  [key: string]: any;\n  vendor_id?: number;\n  product_id?: number;\n  description?: string;\n  is_"
  },
  {
    "path": "src/types/IFormState.ts",
    "chars": 105,
    "preview": "import IRule from './IRule';\n\nexport default interface IFormState {\n  title: string;\n  rules: IRule[];\n}\n"
  },
  {
    "path": "src/types/IFromEventDefinition.ts",
    "chars": 771,
    "preview": "import ISimultaneous from './ISimultaneous';\nimport KeyOrder from './KeyOrder';\nimport KeyUpWhen from './KeyUpWhen';\nimp"
  },
  {
    "path": "src/types/IManipulator.ts",
    "chars": 654,
    "preview": "import IFromEventDefinition from './IFromEventDefinition';\nimport IToEventDefinition from './IToEventDefinition';\nimport"
  },
  {
    "path": "src/types/IMouseKey.ts",
    "chars": 152,
    "preview": "export default interface IMouseKEy {\n  x?: Number;\n  y?: Number;\n  vertical_wheel?: Number;\n  horizontal_wheel?: Number;"
  },
  {
    "path": "src/types/IRule.ts",
    "chars": 264,
    "preview": "import IFromEventDefinition from './IFromEventDefinition';\nimport IToEventDefinition from './IToEventDefinition';\nimport"
  },
  {
    "path": "src/types/ISimultaneous.ts",
    "chars": 186,
    "preview": "export default interface ISimultaneous {\n  // TODO: add keycode label value type\n  key_code?: string | any;\n  consumer_c"
  },
  {
    "path": "src/types/IToEventDefinition.ts",
    "chars": 429,
    "preview": "import IMouseKEy from './IMouseKey';\n\nexport default interface IToEventDefinition {\n  key_code?: string;\n  consumer_key_"
  },
  {
    "path": "src/types/KeyOrder.ts",
    "chars": 94,
    "preview": "declare type KeyOrder = 'insensitive' | 'strict' | 'strict_inverse';\nexport default KeyOrder;\n"
  },
  {
    "path": "src/types/KeyUpWhen.ts",
    "chars": 66,
    "preview": "declare type KeyUpWhen = 'any' | 'all';\nexport default KeyUpWhen;\n"
  },
  {
    "path": "src/types/Modifier.ts",
    "chars": 89,
    "preview": "declare type Modifier = {\n  label: string;\n  value: string;\n};\n\nexport default Modifier;\n"
  },
  {
    "path": "src/types/PointingButton.ts",
    "chars": 147,
    "preview": "declare type PointingButton =\n  | 'disabled'\n  | 'button1'\n  | 'button2'\n  | 'button3'\n  | 'button4'\n  | 'button5';\nexpo"
  },
  {
    "path": "tsconfig.json",
    "chars": 516,
    "preview": "{\n  \"compilerOptions\": {\n    \"downlevelIteration\": true,\n    \"target\": \"es5\",\n    \"lib\": [\"dom\", \"dom.iterable\", \"esnext"
  }
]

About this extraction

This page contains the full source code of the genesy/karabiner-complex-rules-generator GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 51 files (124.3 KB), approximately 30.3k tokens, and a symbol index with 53 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!