feat: is initial commit
2
.eslintignore
Normal file
@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
dist
|
49
.eslintrc
Normal file
@ -0,0 +1,49 @@
|
||||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaFeatures": {
|
||||
"jsx": true
|
||||
},
|
||||
"project": "./tsconfig.json",
|
||||
"sourceType": "module"
|
||||
},
|
||||
"settings": {
|
||||
"react": {
|
||||
"version": "detect"
|
||||
}
|
||||
},
|
||||
"plugins": ["@typescript-eslint", "react"],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:@typescript-eslint/recommended-requiring-type-checking",
|
||||
"plugin:react/recommended",
|
||||
"plugin:prettier/recommended"
|
||||
],
|
||||
"rules": {
|
||||
"max-len": ["error", {"code": 120, "ignoreComments": true, "ignoreTemplateLiterals": true}],
|
||||
"no-console": "error",
|
||||
"semi": [ "error", "always" ],
|
||||
"@typescript-eslint/no-unsafe-member-access": "error",
|
||||
"@typescript-eslint/no-unsafe-assignment": "off",
|
||||
"@typescript-eslint/no-unsafe-call": "error",
|
||||
"@typescript-eslint/no-unsafe-argument": "off",
|
||||
"@typescript-eslint/ban-types": "error",
|
||||
"@typescript-eslint/restrict-template-expressions": "error",
|
||||
"@typescript-eslint/no-misused-promises": "off",
|
||||
"@typescript-eslint/no-unsafe-return": "off",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"sort-imports": [
|
||||
"error",
|
||||
{
|
||||
"ignoreCase": false,
|
||||
"ignoreDeclarationSort": false,
|
||||
"ignoreMemberSort": false,
|
||||
"memberSyntaxSortOrder": ["none", "all", "multiple", "single"],
|
||||
"allowSeparatedGroups": false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
7
.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
.DS_Store
|
||||
.parcel-cache
|
||||
dist
|
||||
node_modules
|
||||
tmp
|
||||
test
|
||||
*.iml
|
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "@types"]
|
||||
path = @types
|
||||
url = git@github.com:pinmenote/types.git
|
6
.parcelrc
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "@parcel/config-webextension",
|
||||
"transformers": {
|
||||
"*.{ts,tsx}": ["@parcel/transformer-typescript-tsc"]
|
||||
}
|
||||
}
|
7
.prettierrc.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"endOfLine": "auto",
|
||||
"semi": true,
|
||||
"printWidth": 120
|
||||
}
|
1
@types
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 6d843ebd1164e7b9e5880068aceaa31d49808d34
|
674
LICENSE
Normal file
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. {http://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 {http://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:
|
||||
|
||||
{{project}} Copyright (C) {{year}} {{fullname}}
|
||||
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
|
||||
{http://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
|
||||
{http://www.gnu.org/philosophy/why-not-lgpl.html}.
|
5
README.md
Normal file
@ -0,0 +1,5 @@
|
||||
pinmenote-extension
|
||||
---
|
||||
|
||||
### Description
|
||||
Browser extension to capture internet content essentials
|
2
bin/build-chrome
Executable file
@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
npm run build
|
9
bin/build-firefox
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
# swap manifests
|
||||
mv src/manifest.json src/manifest.ch.json
|
||||
mv src/manifest.ff.json src/manifest.json
|
||||
# build
|
||||
npm run build:ff
|
||||
# swap manifests back
|
||||
mv src/manifest.json src/manifest.ff.json
|
||||
mv src/manifest.ch.json src/manifest.json
|
10974
package-lock.json
generated
Normal file
73
package.json
Normal file
@ -0,0 +1,73 @@
|
||||
{
|
||||
"name": "pinmenote-extension",
|
||||
"description": "Browser extension to capture internet content essentials",
|
||||
"version": "0.0.1",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"author": "Michal Szczepanski <michal@vane.pl>",
|
||||
"scripts": {
|
||||
"watch": "parcel watch src/manifest.json --host localhost --target pinmenote-dev --no-cache",
|
||||
"build": "parcel build src/manifest.json --target pinmenote-prod --no-content-hash --no-cache --detailed-report 0",
|
||||
"build:ff": "parcel build src/manifest.json --target pinmenote-firefox-prod --no-content-hash --no-cache --detailed-report 0",
|
||||
"lint": "eslint --ext .ts,.tsx src/",
|
||||
"lint:fix": "eslint --ext .ts,.tsx src/ --fix"
|
||||
},
|
||||
"pre-commit": [
|
||||
"lint"
|
||||
],
|
||||
"alias": {
|
||||
"@common/*": "./src/common/$1"
|
||||
},
|
||||
"targets": {
|
||||
"pinmenote-dev": {
|
||||
"sourceMap": {
|
||||
"inline": true,
|
||||
"inlineSources": true
|
||||
}
|
||||
},
|
||||
"pinmenote-prod": {},
|
||||
"pinmenote-firefox-prod": {}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@parcel/config-webextension": "^2.7.0",
|
||||
"@parcel/transformer-typescript-tsc": "^2.7.0",
|
||||
"@types/chrome": "^0.0.193",
|
||||
"@types/firefox-webext-browser": "^94.0.1",
|
||||
"@types/node": "^18.6.4",
|
||||
"@types/react": "^18.0.15",
|
||||
"@types/react-dom": "^18.0.6",
|
||||
"@typescript-eslint/eslint-plugin": "^5.32.0",
|
||||
"@typescript-eslint/parser": "^5.32.0",
|
||||
"buffer": "^6.0.3",
|
||||
"eslint": "^8.21.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"eslint-plugin-react": "^7.30.1",
|
||||
"parcel": "^2.7.0",
|
||||
"pre-commit": "^1.2.2",
|
||||
"process": "^0.11.10",
|
||||
"typescript": "^4.7.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@emotion/styled": "^11.10.0",
|
||||
"@fontsource/roboto": "^4.5.7",
|
||||
"@mui/icons-material": "^5.8.4",
|
||||
"@mui/material": "^5.9.3",
|
||||
"css": "^3.0.0",
|
||||
"jwt-decode": "^3.1.2",
|
||||
"nanoid": "^4.0.0",
|
||||
"openpgp": "^5.5.0",
|
||||
"prosemirror-commands": "^1.3.1",
|
||||
"prosemirror-dropcursor": "^1.6.1",
|
||||
"prosemirror-gapcursor": "^1.3.1",
|
||||
"prosemirror-history": "^1.3.0",
|
||||
"prosemirror-inputrules": "^1.2.0",
|
||||
"prosemirror-markdown": "^1.10.1",
|
||||
"prosemirror-model": "^1.18.1",
|
||||
"prosemirror-schema-basic": "^1.2.0",
|
||||
"prosemirror-schema-list": "^1.2.2",
|
||||
"prosemirror-state": "^1.4.2",
|
||||
"prosemirror-view": "^1.29.0",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0"
|
||||
}
|
||||
}
|
3
src/assets/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
Assets
|
||||
---
|
||||
Not GPL-3 licensed
|
BIN
src/assets/icon/128.png
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
src/assets/icon/16.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
src/assets/icon/24.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
src/assets/icon/256.png
Normal file
After Width: | Height: | Size: 5.9 KiB |
BIN
src/assets/icon/32.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
src/assets/icon/48.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
src/assets/icon/64.png
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
src/assets/icon/light/128.png
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
src/assets/icon/light/16.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
src/assets/icon/light/24.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
BIN
src/assets/icon/light/256.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
src/assets/icon/light/32.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
src/assets/icon/light/48.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
src/assets/icon/light/64.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
18
src/common/components/colors.ts
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
export const COLOR_DEFAULT_RED = '#d32f2f';
|
||||
export const COLOR_DEFAULT_GREY = '#eeeeee';
|
30
src/common/components/react/styled.input.ts
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { Input, styled } from '@mui/material';
|
||||
|
||||
export const StyledInput = styled(Input)({
|
||||
width: '100%',
|
||||
':before': {
|
||||
borderBottom: 'none'
|
||||
},
|
||||
':after': {
|
||||
borderBottom: 'none'
|
||||
},
|
||||
'&:hover:before': {
|
||||
borderBottom: 'none !important' // not working without !important cause @mui sucks
|
||||
}
|
||||
});
|
71
src/common/components/text-editor/text.editor.input.rules.ts
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { NodeType, Schema } from 'prosemirror-model';
|
||||
import {
|
||||
ellipsis,
|
||||
emDash,
|
||||
inputRules,
|
||||
smartQuotes,
|
||||
textblockTypeInputRule,
|
||||
wrappingInputRule
|
||||
} from 'prosemirror-inputrules';
|
||||
|
||||
/// Given a blockquote node type, returns an input rule that turns `"> "`
|
||||
/// at the start of a textblock into a blockquote.
|
||||
export function blockQuoteRule(nodeType: NodeType) {
|
||||
return wrappingInputRule(/^\s*>\s$/, nodeType);
|
||||
}
|
||||
|
||||
/// Given a list node type, returns an input rule that turns a number
|
||||
/// followed by a dot at the start of a textblock into an ordered list.
|
||||
export function orderedListRule(nodeType: NodeType) {
|
||||
return wrappingInputRule(
|
||||
/^(\d+)\.\s$/,
|
||||
nodeType,
|
||||
(match) => ({ order: +match[1] }),
|
||||
(match, node) => node.childCount + +node.attrs.order == +match[1]
|
||||
);
|
||||
}
|
||||
|
||||
/// Given a list node type, returns an input rule that turns a bullet
|
||||
/// (dash, plush, or asterisk) at the start of a textblock into a
|
||||
/// bullet list.
|
||||
export function bulletListRule(nodeType: NodeType) {
|
||||
return wrappingInputRule(/^\s*([-+*])\s$/, nodeType);
|
||||
}
|
||||
|
||||
/// Given a node type and a maximum level, creates an input rule that
|
||||
/// turns up to that number of `#` characters followed by a space at
|
||||
/// the start of a textblock into a heading whose level corresponds to
|
||||
/// the number of `#` signs.
|
||||
export function headingRule(nodeType: NodeType, maxLevel: number) {
|
||||
return textblockTypeInputRule(new RegExp(`^(#{1,${maxLevel}})\\s$`), nodeType, (match) => ({
|
||||
level: match[1].length
|
||||
}));
|
||||
}
|
||||
|
||||
/// A set of input rules for creating the basic block quotes, lists,
|
||||
/// code blocks, and heading.
|
||||
export function buildInputRules(schema: Schema) {
|
||||
const rules = smartQuotes.concat(ellipsis, emDash);
|
||||
let type;
|
||||
if ((type = schema.nodes.blockquote)) rules.push(blockQuoteRule(type));
|
||||
if ((type = schema.nodes.ordered_list)) rules.push(orderedListRule(type));
|
||||
if ((type = schema.nodes.bullet_list)) rules.push(bulletListRule(type));
|
||||
if ((type = schema.nodes.heading)) rules.push(headingRule(type, 6));
|
||||
return inputRules({ rules });
|
||||
}
|
126
src/common/components/text-editor/text.editor.keymap.ts
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {
|
||||
chainCommands,
|
||||
exitCode,
|
||||
joinDown,
|
||||
joinUp,
|
||||
lift,
|
||||
selectParentNode,
|
||||
setBlockType,
|
||||
toggleMark,
|
||||
wrapIn
|
||||
} from 'prosemirror-commands';
|
||||
import { liftListItem, sinkListItem, splitListItem, wrapInList } from 'prosemirror-schema-list';
|
||||
import { redo, undo } from 'prosemirror-history';
|
||||
import { Command } from 'prosemirror-state';
|
||||
import { Schema } from 'prosemirror-model';
|
||||
import { undoInputRule } from 'prosemirror-inputrules';
|
||||
|
||||
const mac = typeof navigator != 'undefined' ? /Mac|iP(hone|[oa]d)/.test(navigator.platform) : false;
|
||||
|
||||
/// Inspect the given schema looking for marks and nodes from the
|
||||
/// basic schema, and if found, add key bindings related to them.
|
||||
/// This will add:
|
||||
///
|
||||
/// * **Mod-b** for toggling [strong](#schema-basic.StrongMark)
|
||||
/// * **Mod-i** for toggling [emphasis](#schema-basic.EmMark)
|
||||
/// * **Mod-`** for toggling [code font](#schema-basic.CodeMark)
|
||||
/// * **Ctrl-Shift-0** for making the current textblock a paragraph
|
||||
/// * **Ctrl-Shift-1** to **Ctrl-Shift-Digit6** for making the current
|
||||
/// textblock a heading of the corresponding level
|
||||
/// * **Ctrl-Shift-Backslash** to make the current textblock a code block
|
||||
/// * **Ctrl-Shift-8** to wrap the selection in an ordered list
|
||||
/// * **Ctrl-Shift-9** to wrap the selection in a bullet list
|
||||
/// * **Ctrl->** to wrap the selection in a block quote
|
||||
/// * **Enter** to split a non-empty textblock in a list item while at
|
||||
/// the same time splitting the list item
|
||||
/// * **Mod-Enter** to insert a hard break
|
||||
/// * **Mod-_** to insert a horizontal rule
|
||||
/// * **Backspace** to undo an input rule
|
||||
/// * **Alt-ArrowUp** to `joinUp`
|
||||
/// * **Alt-ArrowDown** to `joinDown`
|
||||
/// * **Mod-BracketLeft** to `lift`
|
||||
/// * **Escape** to `selectParentNode`
|
||||
///
|
||||
/// You can suppress or map these bindings by passing a `mapKeys`
|
||||
/// argument, which maps key names (say `"Mod-B"` to either `false`, to
|
||||
/// remove the binding, or a new key name string.
|
||||
export function buildKeymap(schema: Schema, mapKeys?: { [key: string]: false | string }) {
|
||||
const keys: { [key: string]: Command } = {};
|
||||
let type;
|
||||
function bind(key: string, cmd: Command) {
|
||||
if (mapKeys) {
|
||||
const mapped = mapKeys[key];
|
||||
if (mapped === false) return;
|
||||
if (mapped) key = mapped;
|
||||
}
|
||||
keys[key] = cmd;
|
||||
}
|
||||
|
||||
bind('Mod-z', undo);
|
||||
bind('Shift-Mod-z', redo);
|
||||
bind('Backspace', undoInputRule);
|
||||
if (!mac) bind('Mod-y', redo);
|
||||
|
||||
bind('Alt-ArrowUp', joinUp);
|
||||
bind('Alt-ArrowDown', joinDown);
|
||||
bind('Mod-BracketLeft', lift);
|
||||
bind('Escape', selectParentNode);
|
||||
|
||||
if ((type = schema.marks.strong)) {
|
||||
bind('Mod-b', toggleMark(type));
|
||||
bind('Mod-B', toggleMark(type));
|
||||
}
|
||||
if ((type = schema.marks.em)) {
|
||||
bind('Mod-i', toggleMark(type));
|
||||
bind('Mod-I', toggleMark(type));
|
||||
}
|
||||
if ((type = schema.marks.code)) bind('Mod-`', toggleMark(type));
|
||||
|
||||
if ((type = schema.nodes.bullet_list)) bind('Shift-Ctrl-8', wrapInList(type));
|
||||
if ((type = schema.nodes.ordered_list)) bind('Shift-Ctrl-9', wrapInList(type));
|
||||
if ((type = schema.nodes.blockquote)) bind('Ctrl->', wrapIn(type));
|
||||
if ((type = schema.nodes.hard_break)) {
|
||||
const br = type,
|
||||
cmd = chainCommands(exitCode, (state, dispatch) => {
|
||||
if (dispatch) dispatch(state.tr.replaceSelectionWith(br.create()).scrollIntoView());
|
||||
return true;
|
||||
});
|
||||
bind('Mod-Enter', cmd);
|
||||
bind('Shift-Enter', cmd);
|
||||
if (mac) bind('Ctrl-Enter', cmd);
|
||||
}
|
||||
if ((type = schema.nodes.list_item)) {
|
||||
bind('Enter', splitListItem(type));
|
||||
bind('Mod-[', liftListItem(type));
|
||||
bind('Mod-]', sinkListItem(type));
|
||||
}
|
||||
if ((type = schema.nodes.paragraph)) bind('Shift-Ctrl-0', setBlockType(type));
|
||||
if ((type = schema.nodes.code_block)) bind('Shift-Ctrl-\\', setBlockType(type));
|
||||
if ((type = schema.nodes.heading))
|
||||
for (let i = 1; i <= 6; i++) bind(`Shift-Ctrl-${i}`, setBlockType(type, { level: i }));
|
||||
if ((type = schema.nodes.horizontal_rule)) {
|
||||
const hr = type;
|
||||
bind('Mod-_', (state, dispatch) => {
|
||||
if (dispatch) dispatch(state.tr.replaceSelectionWith(hr.create()).scrollIntoView());
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
40
src/common/components/text-editor/text.editor.state.ts
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { defaultMarkdownParser, schema } from 'prosemirror-markdown';
|
||||
import { EditorState } from 'prosemirror-state';
|
||||
import { history as baseHistory } from 'prosemirror-history';
|
||||
import { baseKeymap } from 'prosemirror-commands';
|
||||
import { buildInputRules } from './text.editor.input.rules';
|
||||
import { buildKeymap } from './text.editor.keymap';
|
||||
import { dropCursor } from 'prosemirror-dropcursor';
|
||||
import { gapCursor } from 'prosemirror-gapcursor';
|
||||
import { keymap } from 'prosemirror-keymap';
|
||||
|
||||
export const createTextEditorState = (content: string) => {
|
||||
const doc: any = defaultMarkdownParser.parse(content);
|
||||
return EditorState.create({
|
||||
doc,
|
||||
plugins: [
|
||||
gapCursor(),
|
||||
dropCursor(),
|
||||
keymap(buildKeymap(schema)), // custom keys
|
||||
keymap(baseKeymap),
|
||||
buildInputRules(schema), // custom rules
|
||||
baseHistory()
|
||||
]
|
||||
});
|
||||
};
|
42
src/common/environment.ts
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
interface EnvironmentConfig {
|
||||
showAckMessage: boolean;
|
||||
apiUrl: string;
|
||||
websiteUrl: string;
|
||||
shortUrl: string;
|
||||
isProduction: boolean;
|
||||
}
|
||||
|
||||
export const environmentConfig: EnvironmentConfig = {
|
||||
showAckMessage: false,
|
||||
apiUrl: 'https://pinmenote.com',
|
||||
websiteUrl: 'https://pinmenote.com',
|
||||
shortUrl: 'https://pmn.cl',
|
||||
isProduction: true
|
||||
};
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
environmentConfig.apiUrl = 'http://localhost:3000';
|
||||
environmentConfig.websiteUrl = 'http://localhost:4200';
|
||||
environmentConfig.shortUrl = 'http://localhost:8001';
|
||||
environmentConfig.isProduction = false;
|
||||
}
|
||||
|
||||
export function getWebsiteUrl(uri: string): string {
|
||||
return `${environmentConfig.websiteUrl}${uri}`;
|
||||
}
|
34
src/common/fn/b64.to.blob.fn.ts
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
export const fnB64toBlob = (b64Data: string, contentType = '', sliceSize = 512): Blob => {
|
||||
const byteCharacters = window.atob(b64Data.split(',')[1]);
|
||||
const byteArrays = [];
|
||||
|
||||
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
|
||||
const slice = byteCharacters.slice(offset, offset + sliceSize);
|
||||
|
||||
const byteNumbers = new Array(slice.length);
|
||||
for (let i = 0; i < slice.length; i++) {
|
||||
byteNumbers[i] = slice.charCodeAt(i);
|
||||
}
|
||||
|
||||
const byteArray = new Uint8Array(byteNumbers);
|
||||
byteArrays.push(byteArray);
|
||||
}
|
||||
|
||||
return new Blob(byteArrays, { type: contentType });
|
||||
};
|
147
src/common/fn/compute.element.fn.ts
Normal file
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { ContentVideoTime, CssData, HtmlIntermediateData } from '@common/model/html.model';
|
||||
import { fnConsoleLog } from './console.fn';
|
||||
import { fnGetKey } from '@common/kv.utils';
|
||||
import { fnXpath } from '@common/fn/xpath.fn';
|
||||
|
||||
type ComputeCssRule = CSSStyleRule & CSSRule & CSSGroupingRule & CSSConditionRule & CSSImportRule;
|
||||
|
||||
const computeSelectorRules = (cssRules: ComputeCssRule[], unique: Set<string>): string => {
|
||||
let output = '';
|
||||
cssRules.forEach((r: ComputeCssRule) => {
|
||||
if (fnGetKey(r, 'selectorText')) {
|
||||
unique.forEach((u) => {
|
||||
if (u.startsWith('.')) {
|
||||
if (r.selectorText.startsWith(`${u}:`) || r.selectorText.startsWith(`${u} `) || r.selectorText === u) {
|
||||
output += `${r.cssText}
|
||||
`;
|
||||
}
|
||||
} else {
|
||||
const selectors: string[] = r.selectorText.split(',');
|
||||
selectors.forEach((s) => {
|
||||
if (u === s || `* ${u}` === s) {
|
||||
output += `${r.cssText}
|
||||
`;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if (r.media) {
|
||||
const ruleText = computeSelectorRules(Array.from(r.cssRules) as ComputeCssRule[], unique);
|
||||
if (ruleText) {
|
||||
output += `@media ${r.conditionText} {
|
||||
${ruleText}
|
||||
}
|
||||
`;
|
||||
}
|
||||
} else {
|
||||
// TODO parse other rules ex CSSKeyFrameRules
|
||||
}
|
||||
});
|
||||
return output;
|
||||
};
|
||||
|
||||
export const fnComputeCssContent = (styles: string[]): CssData => {
|
||||
let css = '';
|
||||
const href: string[] = [];
|
||||
const unique = new Set(styles);
|
||||
const styleSheets = Array.from(document.styleSheets);
|
||||
styleSheets.forEach((s) => {
|
||||
if (s.href) {
|
||||
href.push(s.href);
|
||||
} else {
|
||||
css += computeSelectorRules(Array.from(s.cssRules) as ComputeCssRule[], unique);
|
||||
}
|
||||
});
|
||||
return {
|
||||
href,
|
||||
css
|
||||
};
|
||||
};
|
||||
|
||||
export const fnComputeHtmlContent = (ref: Element): HtmlIntermediateData => {
|
||||
const tagName = ref.tagName.toLowerCase();
|
||||
const cssStyles: string[] = [tagName];
|
||||
let html = `<${tagName} `;
|
||||
const videoTime: ContentVideoTime[] = [];
|
||||
|
||||
if (tagName === 'video') {
|
||||
// fnConsoleLog('VIDEO !!!', (el as HTMLVideoElement).currentTime);
|
||||
videoTime.push({
|
||||
xpath: fnXpath(ref as HTMLElement),
|
||||
currentTime: (ref as HTMLVideoElement).currentTime
|
||||
});
|
||||
// SET SECONDS (el as HTMLVideoElement).currentTime = 148;
|
||||
}
|
||||
|
||||
const attributes: Attr[] = Array.from(ref.attributes);
|
||||
for (const attr of attributes) {
|
||||
if (attr.name === 'class') {
|
||||
// CLASS CSS SELECTORS
|
||||
const a = attr.value.split(' ').filter((e) => !!e);
|
||||
cssStyles.push(...a.map((e) => `.${e}`));
|
||||
html += `${attr.name}="${attr.value}" `;
|
||||
} else if (attr.name === 'href') {
|
||||
// HREF
|
||||
if (attr.value.startsWith('/')) {
|
||||
html += `href="${window.location.origin}${attr.value}" `;
|
||||
} else if (!attr.value.startsWith('http')) {
|
||||
html += `src="${window.location.origin}/${attr.value}" `;
|
||||
} else {
|
||||
html += `href="${attr.value}" `;
|
||||
}
|
||||
html += `target="_blank" `;
|
||||
} else if (attr.name === 'target') {
|
||||
// Skip - we handle it inside href
|
||||
} else if (attr.name === 'src') {
|
||||
if (attr.value.startsWith('/')) {
|
||||
html += `src="${window.location.origin}${attr.value}" `;
|
||||
} else if (!attr.value.startsWith('http')) {
|
||||
html += `src="${window.location.origin}/${attr.value}" `;
|
||||
} else {
|
||||
html += `src="${attr.value}" `;
|
||||
}
|
||||
} else {
|
||||
html += `${attr.name}="${attr.value}" `;
|
||||
}
|
||||
}
|
||||
html = html.substring(0, html.length - 1) + '>';
|
||||
|
||||
const nodes = Array.from(ref.childNodes);
|
||||
|
||||
for (const node of nodes) {
|
||||
if (node.nodeType === Node.TEXT_NODE) {
|
||||
const nre = new RegExp(String.fromCharCode(160), 'g');
|
||||
html += node.textContent ? node.textContent.replace(nre, ' ') : '';
|
||||
} else if (node.nodeType === Node.ELEMENT_NODE) {
|
||||
const computed = fnComputeHtmlContent(node as Element);
|
||||
html += computed.html;
|
||||
cssStyles.push(...computed.cssStyles);
|
||||
videoTime.push(...computed.videoTime);
|
||||
} else {
|
||||
fnConsoleLog('PROBLEM !!!', node.nodeType);
|
||||
}
|
||||
}
|
||||
html += `</${tagName}>`;
|
||||
|
||||
return {
|
||||
cssStyles,
|
||||
html,
|
||||
videoTime
|
||||
};
|
||||
};
|
31
src/common/fn/console.fn.ts
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { environmentConfig } from '../environment';
|
||||
|
||||
export const fnConsoleLog = (...args: any[]) => {
|
||||
if (!environmentConfig.isProduction) {
|
||||
//eslint-disable-next-line no-console
|
||||
console.log(...args);
|
||||
}
|
||||
};
|
||||
|
||||
export const fnConsoleError = (...args: any[]) => {
|
||||
if (!environmentConfig.isProduction) {
|
||||
//eslint-disable-next-line no-console
|
||||
console.error(...args);
|
||||
}
|
||||
};
|
27
src/common/fn/date.fn.ts
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
export const fnIsoDateToUtcMiliseconds = (dt: string): number => {
|
||||
const date = new Date(dt);
|
||||
return Math.floor(date.getTime()) + date.getTimezoneOffset() * 60000;
|
||||
};
|
||||
|
||||
export const fnMilisecondsToUtcDate = (dt: number): Date => {
|
||||
const date = new Date(dt);
|
||||
date.setMinutes(date.getMinutes() - date.getTimezoneOffset() * 1000);
|
||||
return date;
|
||||
};
|
25
src/common/fn/date.format.fn.ts
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
const pad = (val: number): string => {
|
||||
return val < 10 ? `0${val}` : `${val}`;
|
||||
};
|
||||
|
||||
export const fnDateFormat = (dt: Date): string => {
|
||||
return `${dt.getFullYear()}-${pad(dt.getMonth() + 1)}-${pad(dt.getDate())} ${pad(dt.getHours())}:${pad(
|
||||
dt.getMinutes()
|
||||
)}:${pad(dt.getSeconds())}`;
|
||||
};
|
20
src/common/fn/diskspace.fn.ts
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
export const fnByteToMb = (value?: number): number => {
|
||||
if (!value) return 0;
|
||||
return Math.floor(value / 10000) / 100;
|
||||
};
|
54
src/common/fn/img.resize.fn.ts
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { PinObject } from '../model/pin.model';
|
||||
|
||||
export const fnImgResize = (dto: PinObject, b64image: string): Promise<string> => {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
try {
|
||||
const can = document.createElement('canvas');
|
||||
const { elementSize: rect } = dto.locator;
|
||||
if (rect.height <= img.naturalHeight) {
|
||||
can.width = rect.width;
|
||||
can.height = rect.height;
|
||||
const ctx = can.getContext('2d');
|
||||
ctx?.drawImage(img, rect.x * 2, rect.y * 2, rect.width * 2, rect.height * 2, 0, 0, rect.width, rect.height);
|
||||
} else {
|
||||
can.width = rect.width;
|
||||
can.height = img.naturalHeight / 2 - rect.y;
|
||||
const ctx = can.getContext('2d');
|
||||
ctx?.drawImage(img, rect.x * 2, rect.y * 2, rect.width * 2, rect.height * 2, 0, 0, rect.width, rect.height);
|
||||
}
|
||||
b64image = can.toDataURL('image/jpeg', 0.8);
|
||||
} finally {
|
||||
window.URL.revokeObjectURL(b64image);
|
||||
img.onerror = null;
|
||||
img.onload = null;
|
||||
// Resolve here
|
||||
resolve(b64image);
|
||||
}
|
||||
};
|
||||
img.onerror = (event, source, lineno, colno, error) => {
|
||||
window.URL.revokeObjectURL(b64image);
|
||||
img.onerror = null;
|
||||
img.onload = null;
|
||||
reject(error);
|
||||
};
|
||||
img.src = b64image;
|
||||
});
|
||||
};
|
34
src/common/fn/img.to.b64.fn.ts
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
export const fnImgToBase64 = (src: string): Promise<string> => {
|
||||
const img = new Image();
|
||||
return new Promise<string>((resolve) => {
|
||||
img.onload = () => {
|
||||
const can = document.createElement('canvas');
|
||||
can.width = img.naturalWidth;
|
||||
can.height = img.naturalHeight;
|
||||
const ctx = can.getContext('2d');
|
||||
ctx?.drawImage(img, 0, 0);
|
||||
resolve(can.toDataURL('image/jpeg', 0.8));
|
||||
};
|
||||
img.onerror = () => {
|
||||
resolve('');
|
||||
};
|
||||
img.crossOrigin = '';
|
||||
img.src = src;
|
||||
});
|
||||
};
|
77
src/common/fn/normalize.url.fn.ts
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
interface QueryParam {
|
||||
key: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export const fnNormalizeHref = (value: string): string => {
|
||||
const url = new URL(value);
|
||||
if (url.search) {
|
||||
const query = url.search.slice(1);
|
||||
const result: QueryParam[] = [];
|
||||
query.split('&').forEach(function (part) {
|
||||
const item = part.split('=');
|
||||
result.push({
|
||||
key: item[0],
|
||||
value: decodeURIComponent(item[1])
|
||||
});
|
||||
});
|
||||
const search = trimParams(url.host, result);
|
||||
if (search) {
|
||||
return `${url.origin}${url.pathname}?${search}`;
|
||||
}
|
||||
return `${url.origin}${url.pathname}`;
|
||||
}
|
||||
return `${url.origin}${url.pathname}`;
|
||||
};
|
||||
|
||||
const trimParams = (host: string, queryParams: QueryParam[]): string => {
|
||||
let out = '';
|
||||
const toDelete = ['referre'];
|
||||
if (host.startsWith('www.')) {
|
||||
host = host.slice(4);
|
||||
}
|
||||
if (host.startsWith('youtube')) {
|
||||
toDelete.push('t', 'start_radio', 'list');
|
||||
}
|
||||
if (host.startsWith('twitter')) {
|
||||
toDelete.push('src');
|
||||
}
|
||||
for (const param of queryParams) {
|
||||
// skip utm_ args https://en.wikipedia.org/wiki/UTM_parameters
|
||||
if (param.key.startsWith('utm_')) continue;
|
||||
// allegro.pl details
|
||||
if (param.key.startsWith('bi_')) continue;
|
||||
if (!toDelete.includes(param.key)) {
|
||||
out += `&${param.key}=${encodeURIComponent(param.value)}`;
|
||||
}
|
||||
}
|
||||
return out.slice(1);
|
||||
};
|
||||
|
||||
export const fnNormalizeOrigin = (value: string): string => {
|
||||
if (value.startsWith('https')) {
|
||||
value = value.substring(8);
|
||||
} else if (value.startsWith('http')) {
|
||||
value = value.substring(7);
|
||||
}
|
||||
if (value.startsWith('www')) {
|
||||
value = value.substring(4);
|
||||
}
|
||||
return value;
|
||||
};
|
19
src/common/fn/page.pin.list.fn.ts
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
export function fnPagePinList(): HTMLElement[] {
|
||||
return Array.from(document.querySelectorAll('div[id^=pinmenote-]'));
|
||||
}
|
27
src/common/fn/pin/content-pin-new-url.ts
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { fnNormalizeHref, fnNormalizeOrigin } from '@common/fn/normalize.url.fn';
|
||||
import PinUrl = Pinmenote.Pin.PinUrl;
|
||||
|
||||
export const contentPinNewUrl = (): PinUrl => {
|
||||
return {
|
||||
href: fnNormalizeHref(window.location.href),
|
||||
origin: fnNormalizeOrigin(window.location.origin),
|
||||
pathname: window.location.pathname,
|
||||
search: window.location.search
|
||||
};
|
||||
};
|
47
src/common/fn/pin/pin.iframe.fn.ts
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { HtmlContent } from '@common/model/html.model';
|
||||
|
||||
export const pinIframeFn = (content: HtmlContent, container?: HTMLElement): string | undefined => {
|
||||
const iframe = document.createElement('iframe');
|
||||
iframe.style.border = 'none';
|
||||
const { css, href } = content.css;
|
||||
let containerBodyStyle = '';
|
||||
if (container) containerBodyStyle = `;width: ${window.innerWidth}px`;
|
||||
|
||||
const html = `<html>
|
||||
<head>
|
||||
${href.map((h) => `<link rel="stylesheet" href="${h}" />`).join('')}
|
||||
<style>${css}</style>
|
||||
<body style="${content.bodyStyle || ''}${containerBodyStyle}">${content.html}</body>
|
||||
</head>
|
||||
</html>`;
|
||||
if (!container) return html;
|
||||
|
||||
container.appendChild(iframe);
|
||||
|
||||
if (!iframe.contentWindow) return;
|
||||
|
||||
const doc = iframe.contentWindow.document;
|
||||
doc.write(html);
|
||||
doc.close();
|
||||
|
||||
iframe.width = `${window.innerWidth - 350}px`;
|
||||
iframe.height = `${window.innerHeight - 350}px`;
|
||||
|
||||
return html;
|
||||
};
|
33
src/common/fn/sleep.fn.ts
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { BusMessageType, TimeoutMessage } from '../model/bus.model';
|
||||
import { TinyEventDispatcher } from '../service/tiny.event.dispatcher';
|
||||
import { fnUid } from './uid.fn';
|
||||
import { sendRuntimeMessage } from '../message/runtime.message';
|
||||
|
||||
export const fnSleep = async (ms: number): Promise<void> => {
|
||||
const id = fnUid();
|
||||
await sendRuntimeMessage<TimeoutMessage>({ type: BusMessageType.CONTENT_TIMEOUT, data: { id, ms } });
|
||||
return new Promise((resolve) => {
|
||||
TinyEventDispatcher.addListener<TimeoutMessage>(BusMessageType.CONTENT_TIMEOUT, (event, key, value) => {
|
||||
TinyEventDispatcher.removeListener(event, key);
|
||||
if (value.id === id) {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
22
src/common/fn/uid.fn.ts
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { customAlphabet } from 'nanoid';
|
||||
const alphabet = customAlphabet('abcdefghijklmnopqrstuwxyz0123456789');
|
||||
|
||||
export function fnUid(size = 10): string {
|
||||
return alphabet(size);
|
||||
}
|
55
src/common/fn/xpath.fn.ts
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
interface XPathElement {
|
||||
position: number;
|
||||
tagName: string;
|
||||
}
|
||||
|
||||
export function fnXpath(element: HTMLElement): string {
|
||||
let child = element;
|
||||
let parent = child.parentElement;
|
||||
let path: XPathElement[] = [];
|
||||
while (parent) {
|
||||
const position = findNodeNameIndex(Array.from(parent.childNodes), child);
|
||||
path.push({
|
||||
position,
|
||||
tagName: child.tagName
|
||||
});
|
||||
child = parent;
|
||||
parent = parent.parentElement;
|
||||
}
|
||||
path = path.reverse();
|
||||
path.splice(0, 1);
|
||||
return `/html/body/${path.map((p) => `${p.tagName}[${p.position}]`).join('/')}`;
|
||||
}
|
||||
|
||||
function findNodeNameIndex(nodes: ChildNode[], child: HTMLElement): number {
|
||||
let index = 1;
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
const node = nodes[i];
|
||||
if (node.nodeName === child.nodeName && child !== node) {
|
||||
index++;
|
||||
} else if (child === node) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
export function fnFindElementXpath(xpath: string): XPathResult {
|
||||
return document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE);
|
||||
}
|
23
src/common/kv.utils.ts
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
export function fnGetKey<T>(obj: any, key: string): T {
|
||||
return obj[key]; // eslint-disable-line @typescript-eslint/no-unsafe-member-access
|
||||
}
|
||||
|
||||
export function fnSetKeyValue(obj: any, key: string, value?: any): void {
|
||||
obj[key] = value; // eslint-disable-line @typescript-eslint/no-unsafe-member-access
|
||||
}
|
51
src/common/message/reload.content.script.ts
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { fnConsoleLog } from '@common/fn/console.fn';
|
||||
import { fnIsChrome } from '@common/service/browser.api.wrapper';
|
||||
|
||||
export const reloadContentScript = async (tabId: number): Promise<void> => {
|
||||
const scripts = chrome.runtime.getManifest().content_scripts;
|
||||
if (!scripts) return;
|
||||
try {
|
||||
await insertJsFiles(tabId, scripts[0]?.js);
|
||||
await insertCssFiles(tabId, scripts[0].css);
|
||||
} catch (e) {
|
||||
fnConsoleLog('Error', e);
|
||||
}
|
||||
};
|
||||
|
||||
const insertJsFiles = async (tabId: number, files: string[] | undefined): Promise<void> => {
|
||||
if (!files) return;
|
||||
if (fnIsChrome()) {
|
||||
await chrome.scripting.executeScript({ target: { tabId }, files });
|
||||
} else {
|
||||
for (const file of files) {
|
||||
await browser.tabs.executeScript(tabId, { file });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const insertCssFiles = async (tabId: number, files: string[] | undefined): Promise<void> => {
|
||||
if (!files) return;
|
||||
if (fnIsChrome()) {
|
||||
await chrome.scripting.insertCSS({ target: { tabId }, files });
|
||||
} else {
|
||||
for (const file of files) {
|
||||
await browser.tabs.insertCSS(tabId, { file });
|
||||
}
|
||||
}
|
||||
};
|
34
src/common/message/runtime.message.ts
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { BusMessage } from '@common/model/bus.model';
|
||||
import { environmentConfig } from '../environment';
|
||||
import { fnBrowserApi } from '@common/service/browser.api.wrapper';
|
||||
import { fnConsoleLog } from '@common/fn/console.fn';
|
||||
|
||||
export const sendRuntimeMessage = async <T>(msg: BusMessage<T>): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
fnBrowserApi().runtime.sendMessage(msg, (ack: any) => {
|
||||
if (environmentConfig.showAckMessage) fnConsoleLog(`${msg.type}->ack`);
|
||||
resolve(ack);
|
||||
});
|
||||
} catch (e) {
|
||||
fnConsoleLog('runtime.lastError', fnBrowserApi().runtime.lastError);
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
};
|
37
src/common/message/tab.message.ts
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { BusMessage } from '@common/model/bus.model';
|
||||
import { fnBrowserApi } from '@common/service/browser.api.wrapper';
|
||||
import { fnConsoleLog } from '../fn/console.fn';
|
||||
|
||||
export const sendTabMessage = <T>(msg: BusMessage<T>): Promise<void> => {
|
||||
return new Promise((resolve: (...arg: any) => void, reject: (...arg: any) => void) => {
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
/* eslint-disable @typescript-eslint/no-floating-promises */
|
||||
fnBrowserApi().tabs.query({ active: true, currentWindow: true }, (tabs: chrome.tabs.Tab[]) => {
|
||||
const currentTab: chrome.tabs.Tab | undefined = tabs[0];
|
||||
if (currentTab?.id) {
|
||||
try {
|
||||
fnBrowserApi().tabs.sendMessage(currentTab.id, msg, resolve);
|
||||
} catch (e) {
|
||||
fnConsoleLog('Error sendTabMessage', msg, e);
|
||||
reject(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
21
src/common/model/auth.model.ts
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
export interface RegisterFormData {
|
||||
email: string;
|
||||
username: string;
|
||||
acceptedVersion: string;
|
||||
}
|
98
src/common/model/bus.model.ts
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
export type BrowserGlobalSender = browser.runtime.MessageSender | chrome.runtime.MessageSender;
|
||||
|
||||
export interface BusMessage<T> {
|
||||
type: BusMessageType;
|
||||
data?: T;
|
||||
}
|
||||
|
||||
export interface TimeoutMessage {
|
||||
ms: number;
|
||||
id: string;
|
||||
}
|
||||
|
||||
export enum BusMessageType {
|
||||
// Internal content script
|
||||
CNT_SETTINGS = 'cnt.settings',
|
||||
// Internal options tab
|
||||
OPT_PIN_EDIT = 'opt.pin.edit',
|
||||
OPT_PIN_CANCEL_EDIT = 'opt.pin.cancel.edit',
|
||||
OPT_PIN_SAVE_EDIT = 'opt.pin.save.edit',
|
||||
OPT_PIN_SHOW_IMAGE = 'opt.pin.show.image',
|
||||
// Internal popup
|
||||
POP_CONSOLE_LOG = 'pop.console.log',
|
||||
POP_LOGIN_CLICK = 'pop.login.click',
|
||||
POP_ACCOUNT_CLICK = 'pop.account.click',
|
||||
POP_REGISTER_CLICK = 'pop.register.click',
|
||||
// Ack
|
||||
CONTENT_ACK = 'content.ack',
|
||||
WORKER_ACK = 'worker.ack',
|
||||
POPUP_ACK = 'popup.ack',
|
||||
// Popup
|
||||
POPUP_OPEN = 'popup.open',
|
||||
POPUP_INIT = 'popup.init',
|
||||
POPUP_PIN_START = 'popup.pin.start',
|
||||
POPUP_PIN_STOP = 'popup.pin.stop',
|
||||
POPUP_PIN_GET_HREF = 'popup.pin.get.href',
|
||||
POPUP_PIN_GET_ORIGIN = 'popup.pin.get.origin',
|
||||
POPUP_PIN_CLEANUP = 'popup.pin.cleanup',
|
||||
POPUP_PIN_REMOVE = 'popup.pin.remove',
|
||||
POPUP_PIN_SHARE = 'popup.pin.share',
|
||||
POPUP_PIN_UPDATE = 'popup.pin.update',
|
||||
POPUP_PIN_VISIBLE = 'popup.pin.visible',
|
||||
POPUP_ACCESS_TOKEN = 'popup.access.token',
|
||||
POPUP_API_ERROR = 'popup.api.error',
|
||||
POPUP_LOGIN = 'popup.login',
|
||||
POPUP_LOGOUT = 'popup.logout',
|
||||
POPUP_REGISTER = 'popup.register',
|
||||
POPUP_SYNC_PINS = 'popup.sync.pins',
|
||||
POPUP_SYNC_QUOTA = 'popup.sync.quota',
|
||||
POPUP_PRIVATE_KEY_GET = 'popup.private.key.get',
|
||||
POPUP_PRIVATE_KEY_IMPORT = 'popup.private.key.import',
|
||||
// Content script
|
||||
CONTENT_LOGIN = 'content.login',
|
||||
CONTENT_LOGIN_REFRESH = 'content.login.refresh',
|
||||
CONTENT_PIN_VISIBLE = 'content.pin.visible',
|
||||
CONTENT_PIN_FOCUS = 'content.pin.focus',
|
||||
CONTENT_PIN_CHANGED = 'content.pin.changed',
|
||||
CONTENT_PIN_NAVIGATE = 'content.pin.navigate',
|
||||
CONTENT_PIN_ID = 'content.pin.id',
|
||||
CONTENT_PIN_ADD = 'content.pin.add',
|
||||
CONTENT_LINK_ADD = 'content.link.add',
|
||||
CONTENT_PIN_UPDATE = 'content.pin.update',
|
||||
CONTENT_PIN_REMOVE = 'content.pin.remove',
|
||||
CONTENT_PIN_GET_HREF = 'content.pin.get.href',
|
||||
CONTENT_PIN_GET_ID = 'content.pin.get.id',
|
||||
CONTENT_PIN_SCREENSHOT = 'content.pin.screenshot',
|
||||
CONTENT_REFRESH_TOKEN = 'content.refresh.token',
|
||||
CONTENT_TIMEOUT = 'content.timeout',
|
||||
CONTENT_TIMEOUT_SET = 'content.timeout.set',
|
||||
CONTENT_SETTINGS = 'content.settings',
|
||||
// Options
|
||||
OPTIONS_SYNCHRONIZE_DATA = 'options.synchronize.data',
|
||||
OPTIONS_GET_SETTINGS = 'options.get.settings',
|
||||
OPTIONS_SET_SETTINGS = 'options.set.settings',
|
||||
OPTIONS_PIN_GET_HASH_LIST = 'options.pin.get.hash.list',
|
||||
OPTIONS_PIN_GET_RANGE = 'options.pin.get.range',
|
||||
OPTIONS_PIN_GET_LAST_ID = 'options.pin.get.last.id',
|
||||
OPTIONS_PIN_REMOVE = 'options.pin.remove',
|
||||
OPTIONS_PIN_SHARE = 'options.pin.share',
|
||||
OPTIONS_PIN_UPDATE = 'options.pin.update',
|
||||
OPTIONS_PIN_SEARCH = 'options.pin.search',
|
||||
OPTIONS_GET_ORIGIN_URLS = 'options.get.origin.urls'
|
||||
}
|
64
src/common/model/html.model.ts
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import LinkDto = Pinmenote.Pin.LinkDto;
|
||||
|
||||
export enum ObjectTypeDto {
|
||||
Pin = 1,
|
||||
Link = 2,
|
||||
Note
|
||||
}
|
||||
|
||||
export interface HtmlIntermediateData {
|
||||
cssStyles: string[];
|
||||
html: string;
|
||||
videoTime: ContentVideoTime[];
|
||||
}
|
||||
|
||||
export interface CssData {
|
||||
css: string;
|
||||
href: string[];
|
||||
}
|
||||
|
||||
export interface ContentVideoTime {
|
||||
currentTime: number;
|
||||
xpath: string;
|
||||
}
|
||||
|
||||
export interface HtmlContent {
|
||||
theme?: string;
|
||||
bodyStyle?: string;
|
||||
title: string;
|
||||
html: string;
|
||||
videoTime: ContentVideoTime[];
|
||||
css: CssData;
|
||||
elementText: string;
|
||||
}
|
||||
|
||||
export interface HtmlComponent {
|
||||
object: HtmlObject;
|
||||
ref: HTMLElement;
|
||||
get isDrag(): boolean;
|
||||
render(): HTMLElement;
|
||||
cleanup(): void;
|
||||
focus(goto: boolean): void;
|
||||
resize(): void;
|
||||
}
|
||||
|
||||
export interface HtmlObject extends LinkDto {
|
||||
uid: string;
|
||||
type: ObjectTypeDto;
|
||||
}
|
67
src/common/model/pin.model.ts
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { HtmlContent, HtmlObject } from '@common/model/html.model';
|
||||
import PinSize = Pinmenote.Pin.PinSize;
|
||||
import PinUrl = Pinmenote.Pin.PinUrl;
|
||||
import ShareUrlDto = Pinmenote.Share.ShareUrlDto;
|
||||
|
||||
export const PIN_HASHTAG_REGEX = new RegExp(/#(\w+)/g);
|
||||
|
||||
export enum PinViewType {
|
||||
SCREENSHOT = 1,
|
||||
CONTENT = 2
|
||||
}
|
||||
|
||||
export interface PinPopupInitData {
|
||||
url?: PinUrl;
|
||||
isAddingNote: boolean;
|
||||
}
|
||||
|
||||
/* CONTENT */
|
||||
|
||||
export interface PinObject extends HtmlObject {
|
||||
id: number;
|
||||
version: number;
|
||||
createdDate: string;
|
||||
updatedDate: string;
|
||||
visible: boolean;
|
||||
screenshot?: string;
|
||||
content: HtmlContent;
|
||||
viewType: PinViewType;
|
||||
size: PinSize;
|
||||
share?: ShareUrlDto;
|
||||
border: {
|
||||
radius: string;
|
||||
style: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface PinUpdateObject {
|
||||
pin: PinObject;
|
||||
oldHashtag?: string[];
|
||||
newHashtag?: string[];
|
||||
}
|
||||
|
||||
export interface PinRangeRequest {
|
||||
from: number;
|
||||
limit?: number;
|
||||
search?: string;
|
||||
}
|
||||
|
||||
export interface PinByIdRequest {
|
||||
id: number;
|
||||
}
|
33
src/common/model/settings.model.ts
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import LinkDto = Pinmenote.Pin.LinkDto;
|
||||
|
||||
export enum ExtensionTheme {
|
||||
LIGHT = 'light',
|
||||
DARK = 'dark'
|
||||
}
|
||||
|
||||
export interface ContentExtensionData {
|
||||
href: string;
|
||||
theme: ExtensionTheme;
|
||||
}
|
||||
|
||||
export interface ContentSettingsData {
|
||||
borderStyle: string;
|
||||
borderRadius: string;
|
||||
link?: LinkDto;
|
||||
}
|
36
src/common/popup/log.manager.ts
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { BusMessageType } from '@common/model/bus.model';
|
||||
import { TinyEventDispatcher } from '@common/service/tiny.event.dispatcher';
|
||||
|
||||
export class LogManager {
|
||||
private static logValue = '';
|
||||
|
||||
static log = (value: string): void => {
|
||||
this.logValue = '<span>' + value + '</span><br />' + this.logValue;
|
||||
TinyEventDispatcher.dispatch(BusMessageType.POP_CONSOLE_LOG, this.logValue);
|
||||
};
|
||||
|
||||
static get logs(): string {
|
||||
return this.logValue;
|
||||
}
|
||||
|
||||
static clear(): void {
|
||||
this.logValue = '';
|
||||
TinyEventDispatcher.dispatch(BusMessageType.POP_CONSOLE_LOG, this.logValue);
|
||||
}
|
||||
}
|
55
src/common/service/browser.api.wrapper.ts
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
export type BrowserGlobal = typeof chrome | typeof browser;
|
||||
|
||||
let pinMeBrowserApi: BrowserGlobal;
|
||||
let isChrome = false;
|
||||
try {
|
||||
pinMeBrowserApi = browser;
|
||||
} catch (e) {
|
||||
pinMeBrowserApi = chrome;
|
||||
isChrome = true;
|
||||
}
|
||||
|
||||
export function fnBrowserApi(): BrowserGlobal {
|
||||
return pinMeBrowserApi;
|
||||
}
|
||||
|
||||
export function fnExtensionStartUrl(): string {
|
||||
return isChrome ? 'chrome-extension' : 'moz-extension';
|
||||
}
|
||||
|
||||
export function fnOpenOptionsPage(subpage = ''): void {
|
||||
if (isChrome) {
|
||||
const optionsPage = chrome.runtime.getManifest().options_ui?.page;
|
||||
if (optionsPage) window.open(`chrome-extension://${chrome.runtime.id}/${optionsPage}${subpage}`);
|
||||
return;
|
||||
}
|
||||
window.open(browser.runtime.getManifest().options_ui?.page);
|
||||
window.close();
|
||||
}
|
||||
|
||||
export function fnRuntimeUrl(): string {
|
||||
if (isChrome) {
|
||||
return `chrome-extension://${chrome.runtime.id}`;
|
||||
}
|
||||
return 'moz-extension://';
|
||||
}
|
||||
|
||||
export function fnIsChrome(): boolean {
|
||||
return isChrome;
|
||||
}
|
50
src/common/service/browser.storage.wrapper.ts
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { fnBrowserApi } from './browser.api.wrapper';
|
||||
|
||||
export class BrowserStorageWrapper {
|
||||
private static get api(): chrome.storage.LocalStorageArea | browser.storage.StorageArea {
|
||||
return fnBrowserApi().storage.local;
|
||||
}
|
||||
|
||||
static async get<T>(key: string): Promise<T> {
|
||||
const value = await this.api.get(key);
|
||||
return value[key];
|
||||
}
|
||||
|
||||
static async getAll(): Promise<any> {
|
||||
return await this.api.get();
|
||||
}
|
||||
|
||||
static async getBytesInUse(key?: string): Promise<number> {
|
||||
return await this.api.getBytesInUse(key);
|
||||
}
|
||||
|
||||
static async set<T>(key: string, value: T): Promise<void> {
|
||||
const v: { [key: string]: any } = {};
|
||||
v[key] = value;
|
||||
await this.api.set(v);
|
||||
}
|
||||
|
||||
static async remove(key: string): Promise<void> {
|
||||
await this.api.remove(key);
|
||||
}
|
||||
|
||||
static async clear(): Promise<void> {
|
||||
await this.api.clear();
|
||||
}
|
||||
}
|
60
src/common/service/tiny.event.dispatcher.ts
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { fnUid } from '@common/fn/uid.fn';
|
||||
|
||||
export class TinyEventDispatcher {
|
||||
private static listeners: { [key: string]: { [key: string]: any } } = {};
|
||||
|
||||
static addListener<T>(event: string, handler: (event: string, key: string, value: T) => void): string {
|
||||
if (!this.listeners[event]) {
|
||||
this.listeners[event] = {};
|
||||
}
|
||||
const key = fnUid();
|
||||
this.listeners[event][key] = handler;
|
||||
// LogManager.log(`Add listener ${event} ${key} ${JSON.stringify(Object.keys(this.listeners[event]))}`);
|
||||
return key;
|
||||
}
|
||||
|
||||
static dispatch<T>(event: string, value: T): void {
|
||||
if (this.listeners[event]) {
|
||||
for (const key in this.listeners[event]) {
|
||||
this.listeners[event][key](event, key, value); // eslint-disable-line @typescript-eslint/no-unsafe-call
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static removeListener(event: string, key: string): boolean {
|
||||
// LogManager.log(`Remove listener ${event} ${key}`);
|
||||
if (!this.listeners[event]) return false;
|
||||
if (this.listeners[event][key]) {
|
||||
delete this.listeners[event][key];
|
||||
return true;
|
||||
}
|
||||
// LogManager.log(`Not Removed ${JSON.stringify(this.listeners[event])}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
static removeAllListener(event: string): boolean {
|
||||
if (!this.listeners[event]) return false;
|
||||
delete this.listeners[event];
|
||||
return true;
|
||||
}
|
||||
|
||||
static cleanup() {
|
||||
this.listeners = {};
|
||||
}
|
||||
}
|
22
src/common/style.utils.ts
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
export function applyStylesToElement(element: HTMLElement, styles: { [key: string]: string }): void {
|
||||
for (const key in styles) {
|
||||
const value = styles[key];
|
||||
element.style.setProperty(key, value);
|
||||
}
|
||||
}
|
46
src/content-script/command/link/create-link.command.ts
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { HtmlLinkComponent } from '../../components/html-link.component';
|
||||
import { ObjectTypeDto } from '@common/model/html.model';
|
||||
import { PinPendingStore } from '../../store/pin-pending.store';
|
||||
import { fnConsoleLog } from '@common/fn/console.fn';
|
||||
import { fnFindElementXpath } from '@common/fn/xpath.fn';
|
||||
import { fnUid } from '@common/fn/uid.fn';
|
||||
import { isElementHidden } from '../../fn/is-element-hidden';
|
||||
import ICommand = Pinmenote.Common.ICommand;
|
||||
import LinkDto = Pinmenote.Pin.LinkDto;
|
||||
|
||||
export class CreateLinkCommand implements ICommand<boolean> {
|
||||
constructor(private link: LinkDto) {}
|
||||
execute(): boolean {
|
||||
const value = fnFindElementXpath(this.link.locator.xpath);
|
||||
const ref = value.singleNodeValue as HTMLElement;
|
||||
const uid = fnUid();
|
||||
const object = { uid, type: ObjectTypeDto.Link, ...this.link };
|
||||
fnConsoleLog('CreateLinkCommand->ref', ref, this.link);
|
||||
if (!ref || isElementHidden(ref)) {
|
||||
PinPendingStore.add(object);
|
||||
return false;
|
||||
}
|
||||
const pinComponent = new HtmlLinkComponent(ref, object);
|
||||
document.body.appendChild(pinComponent.render());
|
||||
setTimeout(() => {
|
||||
pinComponent.focus(true);
|
||||
}, 500);
|
||||
return true;
|
||||
}
|
||||
}
|
48
src/content-script/command/pin/create-pin-data.command.ts
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { BorderStore } from '../../store/border.store';
|
||||
import { DocumentMediator } from '../../mediator/document.mediator';
|
||||
import { HtmlComponent } from '@common/model/html.model';
|
||||
import { PinComponent } from '../../components/pin.component';
|
||||
import { PinObject } from '@common/model/pin.model';
|
||||
import { PinStore } from '../../store/pin.store';
|
||||
import { contentPinNew } from '../../fn/content-pin-new';
|
||||
import ICommand = Pinmenote.Common.ICommand;
|
||||
import PinPoint = Pinmenote.Pin.PinPoint;
|
||||
|
||||
export class CreatePinDataCommand implements ICommand<Promise<HtmlComponent | undefined>> {
|
||||
constructor(private ref: HTMLElement, private offset: PinPoint, private dto?: PinObject) {}
|
||||
async execute(): Promise<HtmlComponent | undefined> {
|
||||
let shouldFocus = false;
|
||||
if (!this.dto) {
|
||||
this.dto = await contentPinNew(this.ref, this.offset);
|
||||
shouldFocus = true;
|
||||
DocumentMediator.stopListeners();
|
||||
}
|
||||
// TODO !!! CHANGE HTMLElements to interfaces
|
||||
const pinComponent = new PinComponent(this.ref, this.dto);
|
||||
document.body.appendChild(pinComponent.render());
|
||||
|
||||
if (shouldFocus) pinComponent.focus();
|
||||
|
||||
this.ref.style.border = BorderStore.borderStyle;
|
||||
this.ref.style.borderRadius = BorderStore.borderRadius;
|
||||
|
||||
// Add Pin data
|
||||
return PinStore.add(pinComponent);
|
||||
}
|
||||
}
|
40
src/content-script/command/pin/create-pin-xpath.command.ts
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { CreatePinDataCommand } from './create-pin-data.command';
|
||||
import { PinObject } from '@common/model/pin.model';
|
||||
import { PinPendingStore } from '../../store/pin-pending.store';
|
||||
import { fnFindElementXpath } from '@common/fn/xpath.fn';
|
||||
import { isElementHidden } from '../../fn/is-element-hidden';
|
||||
import ICommand = Pinmenote.Common.ICommand;
|
||||
|
||||
export class CreatePinXpathCommand implements ICommand<Promise<boolean>> {
|
||||
constructor(private pin: PinObject) {}
|
||||
async execute(): Promise<boolean> {
|
||||
const value = fnFindElementXpath(this.pin.locator.xpath);
|
||||
const node = value.singleNodeValue as HTMLElement;
|
||||
if (!this.pin.visible || !node || isElementHidden(node)) {
|
||||
// will be created on invalidate
|
||||
PinPendingStore.add(this.pin);
|
||||
return false;
|
||||
}
|
||||
const pinData = await new CreatePinDataCommand(node, this.pin.locator.offset, this.pin).execute();
|
||||
// CHECK IF CREATED
|
||||
if (pinData) return true;
|
||||
PinPendingStore.add(this.pin);
|
||||
return false;
|
||||
}
|
||||
}
|
67
src/content-script/command/pin/invalidate-pins.command.ts
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { CreateLinkCommand } from '../link/create-link.command';
|
||||
import { CreatePinXpathCommand } from './create-pin-xpath.command';
|
||||
import { ObjectTypeDto } from '@common/model/html.model';
|
||||
import { PinObject } from '@common/model/pin.model';
|
||||
import { PinPendingStore } from '../../store/pin-pending.store';
|
||||
import { PinStore } from '../../store/pin.store';
|
||||
import { RuntimePinGetHrefCommand } from '../runtime/runtime-pin-get-href.command';
|
||||
import { fnConsoleLog } from '@common/fn/console.fn';
|
||||
import { fnNormalizeHref } from '@common/fn/normalize.url.fn';
|
||||
import { isElementHidden } from '../../fn/is-element-hidden';
|
||||
import ICommand = Pinmenote.Common.ICommand;
|
||||
|
||||
export class InvalidatePinsCommand implements ICommand<Promise<void>> {
|
||||
constructor(private href: string) {}
|
||||
async execute(): Promise<void> {
|
||||
// TODO invalidate if pin element exists and show hide pins based on it
|
||||
// Sometimes location is changed without popstate event ex. click on youtube video
|
||||
const href = fnNormalizeHref(window.location.href);
|
||||
if (this.href !== href) {
|
||||
fnConsoleLog('PinManager->invalidatePins->CLEAR href changed');
|
||||
await new RuntimePinGetHrefCommand().execute();
|
||||
PinStore.clear();
|
||||
return;
|
||||
}
|
||||
// Check for pending pins that should be on page but are not displayed
|
||||
// might be deferred rendering and stuff like that
|
||||
const pinList = PinPendingStore.values;
|
||||
for (const pin of pinList) {
|
||||
switch (pin.type) {
|
||||
case ObjectTypeDto.Pin:
|
||||
if (await new CreatePinXpathCommand(pin as PinObject).execute()) {
|
||||
PinPendingStore.remove(pin.uid);
|
||||
}
|
||||
break;
|
||||
case ObjectTypeDto.Link:
|
||||
if (new CreateLinkCommand(pin).execute()) {
|
||||
PinPendingStore.remove(pin.uid);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Ok so check if we displayed on some elements that are not visible
|
||||
PinStore.each((pinData) => {
|
||||
if (isElementHidden(pinData.ref)) {
|
||||
const data = PinStore.delByUid(pinData.object.uid);
|
||||
if (data) PinPendingStore.add(data.object);
|
||||
}
|
||||
if (!pinData.isDrag) pinData.resize();
|
||||
});
|
||||
}
|
||||
}
|
30
src/content-script/command/pin/pin-focus.command.ts
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { PinObject } from '@common/model/pin.model';
|
||||
import { PinStore } from '../../store/pin.store';
|
||||
import { resolveVideoTime } from '../../fn/resolve-video-time';
|
||||
import ICommand = Pinmenote.Common.ICommand;
|
||||
|
||||
export class PinFocusCommand implements ICommand<void> {
|
||||
constructor(private data?: PinObject) {}
|
||||
execute(): void {
|
||||
if (!this.data) return;
|
||||
PinStore.focusPin(this.data);
|
||||
// TODO fixme
|
||||
setTimeout(() => resolveVideoTime(this.data?.content.videoTime), 1000);
|
||||
}
|
||||
}
|
34
src/content-script/command/pin/pin-get-href.command.ts
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { CreatePinXpathCommand } from './create-pin-xpath.command';
|
||||
import { PinObject } from '@common/model/pin.model';
|
||||
import { PinStore } from '../../store/pin.store';
|
||||
import { RuntimePinFocusCommand } from '../runtime/runtime-pin-focus.command';
|
||||
import { fnConsoleLog } from '@common/fn/console.fn';
|
||||
import ICommand = Pinmenote.Common.ICommand;
|
||||
|
||||
export class PinGetHrefCommand implements ICommand<Promise<void>> {
|
||||
constructor(private pins: PinObject[]) {}
|
||||
async execute(): Promise<void> {
|
||||
fnConsoleLog('pin.manager->handlePinGetHref');
|
||||
PinStore.clear();
|
||||
for (const pin of this.pins) {
|
||||
await new CreatePinXpathCommand(pin).execute();
|
||||
}
|
||||
await new RuntimePinFocusCommand().execute();
|
||||
}
|
||||
}
|
28
src/content-script/command/pin/pin-get-id.command.ts
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { CreatePinXpathCommand } from './create-pin-xpath.command';
|
||||
import { PinObject } from '@common/model/pin.model';
|
||||
import ICommand = Pinmenote.Common.ICommand;
|
||||
import { PinStore } from '../../store/pin.store';
|
||||
|
||||
export class PinGetIdCommand implements ICommand<Promise<void>> {
|
||||
constructor(private pin: PinObject) {}
|
||||
async execute(): Promise<void> {
|
||||
PinStore.delByUid(this.pin.uid);
|
||||
await new CreatePinXpathCommand(this.pin).execute();
|
||||
}
|
||||
}
|
34
src/content-script/command/pin/pin-navigate.command.ts
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { PinObject } from '@common/model/pin.model';
|
||||
import { PinStore } from '../../store/pin.store';
|
||||
import { fnNormalizeHref } from '@common/fn/normalize.url.fn';
|
||||
import { resolveVideoTime } from '../../fn/resolve-video-time';
|
||||
import ICommand = Pinmenote.Common.ICommand;
|
||||
|
||||
export class PinNavigateCommand implements ICommand<void> {
|
||||
constructor(private data: PinObject) {}
|
||||
execute(): void {
|
||||
const url = fnNormalizeHref(window.location.href);
|
||||
if (this.data.url.href === url) {
|
||||
PinStore.focusPin(this.data);
|
||||
resolveVideoTime(this.data.content.videoTime);
|
||||
} else {
|
||||
window.location.href = this.data.url.href;
|
||||
}
|
||||
}
|
||||
}
|
33
src/content-script/command/pin/pin-visible.command.ts
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { CreatePinXpathCommand } from './create-pin-xpath.command';
|
||||
import { PinObject } from '@common/model/pin.model';
|
||||
import { PinPendingStore } from '../../store/pin-pending.store';
|
||||
import { PinStore } from '../../store/pin.store';
|
||||
import ICommand = Pinmenote.Common.ICommand;
|
||||
|
||||
export class PinVisibleCommand implements ICommand<Promise<void>> {
|
||||
constructor(private pin: PinObject) {}
|
||||
async execute(): Promise<void> {
|
||||
if (!this.pin.visible) {
|
||||
PinStore.delByUid(this.pin.uid);
|
||||
PinPendingStore.add(this.pin);
|
||||
} else {
|
||||
await new CreatePinXpathCommand(this.pin).execute();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { BusMessageType } from '@common/model/bus.model';
|
||||
import { fnConsoleLog } from '@common/fn/console.fn';
|
||||
import { sendRuntimeMessage } from '@common/message/runtime.message';
|
||||
import ICommand = Pinmenote.Common.ICommand;
|
||||
|
||||
export class RuntimeLoginRefreshCommand implements ICommand<Promise<void>> {
|
||||
async execute(): Promise<void> {
|
||||
fnConsoleLog('handleContentLoginRefresh');
|
||||
await sendRuntimeMessage<string>({ type: BusMessageType.CONTENT_LOGIN, data: window.location.origin });
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { BusMessageType } from '@common/model/bus.model';
|
||||
import { sendRuntimeMessage } from '@common/message/runtime.message';
|
||||
import ICommand = Pinmenote.Common.ICommand;
|
||||
|
||||
export class RuntimePinChangedCommand implements ICommand<void> {
|
||||
constructor(private changedIds: number[]) {}
|
||||
async execute(): Promise<void> {
|
||||
for (const id of this.changedIds) {
|
||||
await sendRuntimeMessage<{ id: number }>({
|
||||
type: BusMessageType.CONTENT_PIN_GET_ID,
|
||||
data: { id }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { BusMessageType } from '@common/model/bus.model';
|
||||
import { fnConsoleLog } from '@common/fn/console.fn';
|
||||
import { sendRuntimeMessage } from '@common/message/runtime.message';
|
||||
import ICommand = Pinmenote.Common.ICommand;
|
||||
|
||||
export class RuntimePinFocusCommand implements ICommand<Promise<void>> {
|
||||
async execute(): Promise<void> {
|
||||
try {
|
||||
await sendRuntimeMessage<undefined>({
|
||||
type: BusMessageType.CONTENT_PIN_FOCUS
|
||||
});
|
||||
} catch (e: unknown) {
|
||||
fnConsoleLog('PinNavigationManager->focus', e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { BusMessageType } from '@common/model/bus.model';
|
||||
import { contentPinNewUrl } from '@common/fn/pin/content-pin-new-url';
|
||||
import { sendRuntimeMessage } from '@common/message/runtime.message';
|
||||
import ICommand = Pinmenote.Common.ICommand;
|
||||
import PinUrl = Pinmenote.Pin.PinUrl;
|
||||
|
||||
export class RuntimePinGetHrefCommand implements ICommand<Promise<void>> {
|
||||
async execute(): Promise<void> {
|
||||
await sendRuntimeMessage<PinUrl>({
|
||||
type: BusMessageType.CONTENT_PIN_GET_HREF,
|
||||
data: contentPinNewUrl()
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { MoveIconComponent } from './move-icon.component';
|
||||
import { ParentIconComponent } from './parent-icon.component';
|
||||
import { PinObject } from '@common/model/pin.model';
|
||||
import { RemoveIconComponent } from './remove-icon.component';
|
||||
import { applyStylesToElement } from '@common/style.utils';
|
||||
|
||||
const actionBtnStyles = {
|
||||
display: 'flex',
|
||||
'min-height': '15px',
|
||||
'max-height': '15px',
|
||||
'background-color': '#ffffff',
|
||||
color: '#000000',
|
||||
'justify-content': 'flex-end'
|
||||
};
|
||||
|
||||
export class ActionBarComponent {
|
||||
private moveIcon: MoveIconComponent;
|
||||
private parentIcon: ParentIconComponent;
|
||||
private removeIcon: RemoveIconComponent;
|
||||
|
||||
constructor(private pin: PinObject, private ref: HTMLElement) {
|
||||
this.moveIcon = new MoveIconComponent(pin);
|
||||
this.parentIcon = new ParentIconComponent(pin, ref);
|
||||
this.removeIcon = new RemoveIconComponent(pin);
|
||||
}
|
||||
render(): HTMLElement {
|
||||
const el = document.createElement('div');
|
||||
applyStylesToElement(el, actionBtnStyles);
|
||||
/* TODO drag drop
|
||||
el.draggable = true;
|
||||
el.addEventListener('dragstart', () => {
|
||||
fnConsoleLog('drag');
|
||||
})
|
||||
*/
|
||||
el.appendChild(this.moveIcon.render());
|
||||
el.appendChild(this.parentIcon.render());
|
||||
el.appendChild(this.removeIcon.render());
|
||||
return el;
|
||||
}
|
||||
|
||||
cleanup(): void {
|
||||
this.moveIcon.cleanup();
|
||||
this.parentIcon.cleanup();
|
||||
this.removeIcon.cleanup();
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { PinDragStore } from '../../store/pin-drag.store';
|
||||
import { PinObject } from '@common/model/pin.model';
|
||||
import { applyStylesToElement } from '@common/style.utils';
|
||||
import { iconButtonStyles } from '../styles/icon-button.styles';
|
||||
|
||||
export class MoveIconComponent {
|
||||
private start = { x: 0, y: 0 };
|
||||
private last = { x: 0, y: 0 };
|
||||
private el = document.createElement('div');
|
||||
constructor(private pin: PinObject) {}
|
||||
|
||||
render(): HTMLElement {
|
||||
this.el.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" height="12" viewBox="0 0 24 24" width="12">
|
||||
<path d="M0 0h24v24H0z" fill="none"/>
|
||||
<path d="M10 9h4V6h3l-5-5-5 5h3v3zm-1 1H6V7l-5 5 5 5v-3h3v-4zm14 2l-5-5v3h-3v4h3v3l5-5zm-9 3h-4v3H7l5 5 5-5h-3v-3z"/>
|
||||
</svg>`;
|
||||
|
||||
this.el.addEventListener('mousedown', this.handleMouseDown);
|
||||
applyStylesToElement(this.el, iconButtonStyles);
|
||||
this.el.style.marginRight = '5px';
|
||||
return this.el;
|
||||
}
|
||||
|
||||
private handleMouseDown = (e: MouseEvent) => {
|
||||
this.start.x = e.clientX;
|
||||
this.start.y = e.clientY;
|
||||
PinDragStore.startDragPin(this.pin);
|
||||
if (PinDragStore.isDrag) {
|
||||
document.addEventListener('mousemove', this.handleMouseMove);
|
||||
document.addEventListener('mouseup', this.handleMouseUp);
|
||||
}
|
||||
};
|
||||
|
||||
private handleMouseMove = (e: MouseEvent) => {
|
||||
this.last.x = e.clientX - this.start.x;
|
||||
this.last.y = e.clientY - this.start.y;
|
||||
PinDragStore.dragPin(this.last);
|
||||
};
|
||||
|
||||
private handleMouseUp = async () => {
|
||||
await PinDragStore.stopDragPin(this.last);
|
||||
document.removeEventListener('mousemove', this.handleMouseMove);
|
||||
document.removeEventListener('mouseup', this.handleMouseUp);
|
||||
};
|
||||
|
||||
cleanup(): void {
|
||||
this.el.removeEventListener('mousedown', this.handleMouseDown);
|
||||
document.removeEventListener('mousemove', this.handleMouseMove);
|
||||
document.removeEventListener('mouseup', this.handleMouseUp);
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { PinObject } from '@common/model/pin.model';
|
||||
import { PinStore } from '../../store/pin.store';
|
||||
import { applyStylesToElement } from '@common/style.utils';
|
||||
import { fnConsoleLog } from '@common/fn/console.fn';
|
||||
import { iconButtonStyles } from '../styles/icon-button.styles';
|
||||
|
||||
export class ParentIconComponent {
|
||||
private el = document.createElement('div');
|
||||
constructor(private pin: PinObject, private ref: HTMLElement) {}
|
||||
render(): HTMLElement {
|
||||
this.el.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" height="12" viewBox="0 0 24 24" width="12">
|
||||
<path d="M0 0h24v24H0z" fill="none"/>
|
||||
<path d="M19 19H5V5h7V3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z"/>
|
||||
</svg>`;
|
||||
|
||||
this.el.addEventListener('click', this.handleClick);
|
||||
|
||||
applyStylesToElement(this.el, iconButtonStyles);
|
||||
|
||||
this.el.style.marginRight = '5px';
|
||||
|
||||
return this.el;
|
||||
}
|
||||
|
||||
private handleClick = async (): Promise<void> => {
|
||||
if (this.ref.parentElement?.tagName === 'BODY') {
|
||||
fnConsoleLog(`No parent for note ${this.pin.uid}`);
|
||||
return;
|
||||
}
|
||||
await PinStore.pinToParent(this.pin, this.ref.parentElement);
|
||||
if (this.ref.parentElement) {
|
||||
this.ref = this.ref.parentElement;
|
||||
}
|
||||
};
|
||||
|
||||
cleanup(): void {
|
||||
this.el.removeEventListener('click', this.handleClick);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { BusMessageType } from '@common/model/bus.model';
|
||||
import { PinObject } from '@common/model/pin.model';
|
||||
import { applyStylesToElement } from '@common/style.utils';
|
||||
import { iconButtonStyles } from '../styles/icon-button.styles';
|
||||
import { sendRuntimeMessage } from '@common/message/runtime.message';
|
||||
|
||||
export class RemoveIconComponent {
|
||||
private el = document.createElement('div');
|
||||
constructor(private pin: PinObject) {}
|
||||
|
||||
render(): HTMLElement {
|
||||
this.el.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" height="12" viewBox="0 0 24 24" width="12">
|
||||
<path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/>
|
||||
</svg>`;
|
||||
this.el.addEventListener('click', this.handleClick);
|
||||
applyStylesToElement(this.el, iconButtonStyles);
|
||||
return this.el;
|
||||
}
|
||||
|
||||
cleanup(): void {
|
||||
this.el.removeEventListener('click', this.handleClick);
|
||||
}
|
||||
|
||||
private handleClick = async () => {
|
||||
this.el.removeEventListener('click', this.handleClick);
|
||||
await sendRuntimeMessage<PinObject>({ type: BusMessageType.CONTENT_PIN_REMOVE, data: this.pin });
|
||||
};
|
||||
}
|
113
src/content-script/components/editor.component.ts
Normal file
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { PIN_HASHTAG_REGEX, PinObject, PinUpdateObject } from '@common/model/pin.model';
|
||||
import { BusMessageType } from '@common/model/bus.model';
|
||||
import { EditorView } from 'prosemirror-view';
|
||||
import { createTextEditorState } from '@common/components/text-editor/text.editor.state';
|
||||
import { defaultMarkdownSerializer } from 'prosemirror-markdown';
|
||||
import { fnConsoleLog } from '@common/fn/console.fn';
|
||||
import { scrollToElementFn } from '../fn/scroll-to-element.fn';
|
||||
import { sendRuntimeMessage } from '@common/message/runtime.message';
|
||||
|
||||
export class EditorComponent {
|
||||
private el = document.createElement('div');
|
||||
|
||||
private editorView?: EditorView;
|
||||
|
||||
constructor(private pin: PinObject) {}
|
||||
|
||||
render(): HTMLElement {
|
||||
this.el.style.width = `${this.pin.size.width}px`;
|
||||
this.el.style.height = `${this.pin.size.height}px`;
|
||||
|
||||
this.editorView = this.createEditor();
|
||||
// FIXME resize prosemirror element differently
|
||||
setTimeout(this.deferredResize, 0);
|
||||
|
||||
this.el.addEventListener('mouseup', this.handleMouseUp);
|
||||
return this.el;
|
||||
}
|
||||
|
||||
cleanup(): void {
|
||||
this.editorView?.destroy();
|
||||
this.el.removeEventListener('mouseup', this.handleMouseUp);
|
||||
}
|
||||
|
||||
focus(goto = false): void {
|
||||
if (goto) scrollToElementFn(this.editorView?.dom, this.pin.size.height);
|
||||
this.editorView?.focus();
|
||||
}
|
||||
|
||||
private deferredResize = () => {
|
||||
const div: HTMLDivElement = this.el.getElementsByClassName('ProseMirror')[0] as HTMLDivElement;
|
||||
if (!div) return;
|
||||
div.style.width = `${this.pin.size.width}px`;
|
||||
div.style.height = `${this.pin.size.height}px`;
|
||||
};
|
||||
|
||||
private handleMouseUp = async () => {
|
||||
await this.resizeTextArea();
|
||||
};
|
||||
|
||||
private createEditor(): EditorView {
|
||||
let state = createTextEditorState(this.pin.value);
|
||||
return new EditorView(this.el, {
|
||||
state,
|
||||
handleKeyDown: (view: EditorView, event: KeyboardEvent) => {
|
||||
event.stopImmediatePropagation();
|
||||
},
|
||||
dispatchTransaction: async (tx) => {
|
||||
state = state.apply(tx);
|
||||
this.editorView?.updateState(state);
|
||||
await this.resizeTextArea();
|
||||
const value = defaultMarkdownSerializer.serialize(state.doc);
|
||||
/// TODO calculate old -> new hash list here
|
||||
const oldMatch = this.pin.value.match(PIN_HASHTAG_REGEX);
|
||||
const newMatch = value.match(PIN_HASHTAG_REGEX);
|
||||
fnConsoleLog('old', oldMatch, 'new', newMatch);
|
||||
this.pin.value = value;
|
||||
try {
|
||||
await sendRuntimeMessage<PinUpdateObject>({
|
||||
type: BusMessageType.CONTENT_PIN_UPDATE,
|
||||
data: {
|
||||
pin: this.pin,
|
||||
oldHashtag: oldMatch ? Array.from(oldMatch) : [],
|
||||
newHashtag: newMatch ? Array.from(newMatch) : []
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
fnConsoleLog('ERROR UPDATE PIN', e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private resizeTextArea = async () => {
|
||||
const div: HTMLDivElement = this.el.getElementsByClassName('ProseMirror')[0] as HTMLDivElement;
|
||||
if (div) {
|
||||
this.pin.size.width = Math.round(div.offsetWidth);
|
||||
this.pin.size.height = Math.round(div.offsetHeight);
|
||||
this.el.style.width = `${this.pin.size.width}px`;
|
||||
this.el.style.height = `${this.pin.size.height}px`;
|
||||
}
|
||||
try {
|
||||
await sendRuntimeMessage<PinUpdateObject>({ type: BusMessageType.CONTENT_PIN_UPDATE, data: { pin: this.pin } });
|
||||
} catch (e) {
|
||||
fnConsoleLog(e);
|
||||
}
|
||||
};
|
||||
}
|
115
src/content-script/components/html-link.component.ts
Normal file
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { HtmlComponent, HtmlObject } from '@common/model/html.model';
|
||||
import { BorderStore } from '../store/border.store';
|
||||
import { applyStylesToElement } from '@common/style.utils';
|
||||
import { contentCalculatePinPoint } from '../fn/content-calculate-pin-point';
|
||||
import { fnConsoleLog } from '@common/fn/console.fn';
|
||||
import { pinStyles } from './styles/pin.styles';
|
||||
import { scrollToElementFn } from '../fn/scroll-to-element.fn';
|
||||
import PinPoint = Pinmenote.Pin.PinPoint;
|
||||
|
||||
class ScrollCheck {
|
||||
private lastPosition = 0;
|
||||
private noChanged = 0;
|
||||
private maxNoChanged = 5;
|
||||
constructor(private targetPosition: number) {}
|
||||
|
||||
get isTarget(): boolean {
|
||||
const scrollY = window.scrollY;
|
||||
|
||||
// Check if changed and if not increase security mark for infinite setInterval
|
||||
scrollY === this.lastPosition ? this.noChanged++ : (this.noChanged = 0);
|
||||
if (this.noChanged >= this.maxNoChanged) return true;
|
||||
|
||||
this.lastPosition = scrollY;
|
||||
|
||||
return this.targetPosition > 0 && Math.abs(scrollY - this.targetPosition) > 5;
|
||||
}
|
||||
}
|
||||
|
||||
export class HtmlLinkComponent implements HtmlComponent {
|
||||
private el = document.createElement('div');
|
||||
private xy?: PinPoint;
|
||||
private scrollCheck?: ScrollCheck;
|
||||
|
||||
ref: HTMLElement;
|
||||
readonly object: HtmlObject;
|
||||
private readonly size = {
|
||||
width: 163,
|
||||
height: 34
|
||||
};
|
||||
|
||||
constructor(ref: HTMLElement, object: HtmlObject) {
|
||||
this.el.id = object.uid;
|
||||
this.ref = ref;
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
get isDrag(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
render(): HTMLElement {
|
||||
this.ref.style.border = BorderStore.borderStyle;
|
||||
this.ref.style.borderRadius = BorderStore.borderRadius;
|
||||
const s = document.createElement('div');
|
||||
s.innerText = this.object.value;
|
||||
this.el.appendChild(s);
|
||||
return this.el;
|
||||
}
|
||||
|
||||
private apply = (): void => {
|
||||
if (!this.scrollCheck?.isTarget) {
|
||||
setTimeout(this.apply, 100);
|
||||
} else {
|
||||
this.xy = contentCalculatePinPoint(
|
||||
this.ref,
|
||||
this.size,
|
||||
this.object.locator.elementSize,
|
||||
this.object.locator.offset
|
||||
);
|
||||
const styles = Object.assign(
|
||||
{
|
||||
left: `${Math.floor(this.xy.x)}px`,
|
||||
top: `${Math.floor(this.xy.y)}px`,
|
||||
border: BorderStore.borderStyle,
|
||||
'border-radius': BorderStore.borderRadius
|
||||
},
|
||||
pinStyles
|
||||
);
|
||||
applyStylesToElement(this.el, styles);
|
||||
}
|
||||
};
|
||||
|
||||
cleanup(): void {
|
||||
this.el.remove();
|
||||
}
|
||||
|
||||
focus(goto: boolean): void {
|
||||
if (goto) {
|
||||
const position = scrollToElementFn(this.ref, this.size.height);
|
||||
this.scrollCheck = new ScrollCheck(position);
|
||||
}
|
||||
this.el.focus();
|
||||
this.apply();
|
||||
}
|
||||
|
||||
resize(): void {
|
||||
fnConsoleLog('resize');
|
||||
}
|
||||
}
|
111
src/content-script/components/pin.component.ts
Normal file
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { ActionBarComponent } from './action-bar/action-bar.component';
|
||||
import { BorderStore } from '../store/border.store';
|
||||
import { EditorComponent } from './editor.component';
|
||||
import { HtmlComponent } from '@common/model/html.model';
|
||||
import { PinObject } from '@common/model/pin.model';
|
||||
import { applyStylesToElement } from '@common/style.utils';
|
||||
import { contentCalculatePinPoint } from '../fn/content-calculate-pin-point';
|
||||
import { pinStyles } from './styles/pin.styles';
|
||||
import PinPoint = Pinmenote.Pin.PinPoint;
|
||||
|
||||
export class PinComponent implements HtmlComponent {
|
||||
private el = document.createElement('div');
|
||||
private editor: EditorComponent;
|
||||
private actionbar: ActionBarComponent;
|
||||
private xy: PinPoint;
|
||||
private drag = false;
|
||||
|
||||
ref: HTMLElement;
|
||||
readonly object: PinObject;
|
||||
|
||||
constructor(ref: HTMLElement, pin: PinObject) {
|
||||
this.el.id = pin.uid;
|
||||
this.ref = ref;
|
||||
this.object = pin;
|
||||
this.xy = contentCalculatePinPoint(this.ref, pin.size, pin.locator.elementSize, pin.locator.offset);
|
||||
this.actionbar = new ActionBarComponent(pin, ref);
|
||||
this.editor = new EditorComponent(this.object);
|
||||
}
|
||||
|
||||
focus(goto = false): void {
|
||||
this.editor.focus(goto);
|
||||
}
|
||||
|
||||
get container(): HTMLElement {
|
||||
return this.el;
|
||||
}
|
||||
|
||||
render(): HTMLElement {
|
||||
const styles = Object.assign(
|
||||
{
|
||||
left: `${this.xy.x}px`,
|
||||
top: `${this.xy.y}px`,
|
||||
border: BorderStore.borderStyle,
|
||||
'border-radius': BorderStore.borderRadius
|
||||
},
|
||||
pinStyles
|
||||
);
|
||||
|
||||
applyStylesToElement(this.el, styles);
|
||||
this.el.appendChild(this.actionbar.render());
|
||||
|
||||
this.el.appendChild(this.editor.render());
|
||||
|
||||
return this.el;
|
||||
}
|
||||
|
||||
startDrag(): void {
|
||||
this.drag = true;
|
||||
}
|
||||
|
||||
updateDrag(value: PinPoint): void {
|
||||
const newX = this.xy.x + value.x;
|
||||
const newY = this.xy.y + value.y;
|
||||
this.el.style.left = `${newX}px`;
|
||||
this.el.style.top = `${newY}px`;
|
||||
}
|
||||
|
||||
stopDrag(value: PinPoint): void {
|
||||
const { offset, elementSize } = this.object.locator;
|
||||
offset.x = offset.x + value.x;
|
||||
offset.y = offset.y + value.y;
|
||||
this.object.locator.offset = offset;
|
||||
this.xy = contentCalculatePinPoint(this.ref, this.object.size, elementSize, offset);
|
||||
this.drag = false;
|
||||
}
|
||||
|
||||
get isDrag(): boolean {
|
||||
return this.drag;
|
||||
}
|
||||
|
||||
resize(): void {
|
||||
const { elementSize, offset } = this.object.locator;
|
||||
this.xy = contentCalculatePinPoint(this.ref, this.object.size, elementSize, offset);
|
||||
this.el.style.left = `${this.xy.x}px`;
|
||||
this.el.style.top = `${this.xy.y}px`;
|
||||
}
|
||||
|
||||
cleanup(): void {
|
||||
this.ref.style.border = this.object.border.style;
|
||||
this.ref.style.borderRadius = this.object.border.radius;
|
||||
this.actionbar.cleanup();
|
||||
this.editor.cleanup();
|
||||
this.el.remove();
|
||||
}
|
||||
}
|
29
src/content-script/components/styles/icon-button.styles.ts
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
export const iconButtonStyles = {
|
||||
border: '0px',
|
||||
'border-radius': '0px',
|
||||
color: '#000000',
|
||||
'font-family': 'Roboto,serif',
|
||||
'font-weight': 'normal',
|
||||
'text-transform': 'none',
|
||||
'line-height': '100%',
|
||||
'background-color': '#ffffff',
|
||||
padding: '0',
|
||||
margin: '0',
|
||||
cursor: 'pointer'
|
||||
};
|
29
src/content-script/components/styles/pin.styles.ts
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
export const pinStyles = {
|
||||
'box-sizing': 'border-box',
|
||||
'background-color': '#ffffff',
|
||||
'border-alpha': '0.5',
|
||||
padding: '5px',
|
||||
minWidth: '200px',
|
||||
minHeight: '50px',
|
||||
position: 'absolute',
|
||||
'font-family': 'Roboto,serif',
|
||||
'z-index': 'calc(9e999)', // https://stackoverflow.com/questions/1118198/how-can-you-figure-out-the-highest-z-index-in-your-document
|
||||
display: 'flex',
|
||||
'flex-direction': 'column'
|
||||
};
|
99
src/content-script/content-message.handler.ts
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { BrowserGlobalSender, BusMessage, BusMessageType } from '@common/model/bus.model';
|
||||
import { DocumentMediator } from './mediator/document.mediator';
|
||||
import { HtmlObject } from '@common/model/html.model';
|
||||
import { PinAddElementStore } from './store/pin-add-element.store';
|
||||
import { PinFocusCommand } from './command/pin/pin-focus.command';
|
||||
import { PinGetHrefCommand } from './command/pin/pin-get-href.command';
|
||||
import { PinGetIdCommand } from './command/pin/pin-get-id.command';
|
||||
import { PinNavigateCommand } from './command/pin/pin-navigate.command';
|
||||
import { PinPopupInitData } from '@common/model/pin.model';
|
||||
import { PinStore } from './store/pin.store';
|
||||
import { PinVisibleCommand } from './command/pin/pin-visible.command';
|
||||
import { RuntimeLoginRefreshCommand } from './command/runtime/runtime-login-refresh.command';
|
||||
import { RuntimePinChangedCommand } from './command/runtime/runtime-pin-changed.command';
|
||||
import { TinyEventDispatcher } from '@common/service/tiny.event.dispatcher';
|
||||
import { contentPinNewUrl } from '@common/fn/pin/content-pin-new-url';
|
||||
import { fnBrowserApi } from '@common/service/browser.api.wrapper';
|
||||
import { fnConsoleLog } from '@common/fn/console.fn';
|
||||
import { sendRuntimeMessage } from '@common/message/runtime.message';
|
||||
|
||||
export class ContentMessageHandler {
|
||||
static start(): void {
|
||||
fnBrowserApi().runtime.onMessage.addListener(this.handleMessage);
|
||||
TinyEventDispatcher.addListener(BusMessageType.POPUP_OPEN, this.handlePopupOpen);
|
||||
}
|
||||
|
||||
static cleanup(): void {
|
||||
fnBrowserApi().runtime.onMessage.removeListener(this.handleMessage);
|
||||
}
|
||||
|
||||
private static handleMessage = async (
|
||||
msg: BusMessage<any>,
|
||||
runtime: BrowserGlobalSender,
|
||||
sendResponse: (response: BusMessage<undefined>) => void
|
||||
): Promise<void> => {
|
||||
if (![BusMessageType.CONTENT_TIMEOUT, BusMessageType.CONTENT_TIMEOUT_SET].includes(msg.type)) {
|
||||
fnConsoleLog('content-script->msg', Date.now(), msg);
|
||||
}
|
||||
sendResponse({
|
||||
type: BusMessageType.CONTENT_ACK
|
||||
});
|
||||
switch (msg.type) {
|
||||
case BusMessageType.POPUP_PIN_START:
|
||||
DocumentMediator.startListeners();
|
||||
break;
|
||||
case BusMessageType.POPUP_PIN_STOP:
|
||||
DocumentMediator.stopListeners();
|
||||
break;
|
||||
case BusMessageType.CONTENT_PIN_CHANGED:
|
||||
await new RuntimePinChangedCommand(msg.data).execute();
|
||||
break;
|
||||
case BusMessageType.CONTENT_PIN_NAVIGATE:
|
||||
new PinNavigateCommand(msg.data).execute();
|
||||
break;
|
||||
case BusMessageType.CONTENT_PIN_FOCUS:
|
||||
new PinFocusCommand(msg.data).execute();
|
||||
break;
|
||||
case BusMessageType.CONTENT_PIN_GET_HREF:
|
||||
await new PinGetHrefCommand(msg.data).execute();
|
||||
break;
|
||||
case BusMessageType.CONTENT_PIN_REMOVE:
|
||||
PinStore.delByUid((msg.data as HtmlObject).uid);
|
||||
break;
|
||||
case BusMessageType.CONTENT_PIN_GET_ID:
|
||||
await new PinGetIdCommand(msg.data).execute();
|
||||
break;
|
||||
case BusMessageType.CONTENT_PIN_VISIBLE:
|
||||
await new PinVisibleCommand(msg.data).execute();
|
||||
break;
|
||||
case BusMessageType.CONTENT_LOGIN_REFRESH:
|
||||
await new RuntimeLoginRefreshCommand().execute();
|
||||
break;
|
||||
default:
|
||||
TinyEventDispatcher.dispatch(msg.type, msg.data);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
private static handlePopupOpen = async (): Promise<void> => {
|
||||
const url = contentPinNewUrl();
|
||||
const data: PinPopupInitData = { url, isAddingNote: PinAddElementStore.hasElement };
|
||||
await sendRuntimeMessage<PinPopupInitData>({ type: BusMessageType.POPUP_INIT, data });
|
||||
};
|
||||
}
|
169
src/content-script/content-script.ts
Normal file
@ -0,0 +1,169 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* URL-s Not transformed correctly
|
||||
import '@fontsource/roboto/300.css';
|
||||
import '@fontsource/roboto/400.css';
|
||||
import '@fontsource/roboto/500.css';
|
||||
import '@fontsource/roboto/700.css';
|
||||
*/
|
||||
|
||||
import '../css/prosemirror.css';
|
||||
|
||||
import { BusMessageType, TimeoutMessage } from '@common/model/bus.model';
|
||||
import { ContentExtensionData, ContentSettingsData, ExtensionTheme } from '@common/model/settings.model';
|
||||
import { fnConsoleError, fnConsoleLog } from '@common/fn/console.fn';
|
||||
import { BorderStore } from './store/border.store';
|
||||
import { ContentMessageHandler } from './content-message.handler';
|
||||
import { CreateLinkCommand } from './command/link/create-link.command';
|
||||
import { DocumentMediator } from './mediator/document.mediator';
|
||||
import { InvalidatePinsCommand } from './command/pin/invalidate-pins.command';
|
||||
import { PinStore } from './store/pin.store';
|
||||
import { RuntimePinGetHrefCommand } from './command/runtime/runtime-pin-get-href.command';
|
||||
import { TinyEventDispatcher } from '@common/service/tiny.event.dispatcher';
|
||||
import { WindowMediator } from './mediator/window.mediator';
|
||||
import { environmentConfig } from '@common/environment';
|
||||
import { fnNormalizeHref } from '@common/fn/normalize.url.fn';
|
||||
import { fnUid } from '@common/fn/uid.fn';
|
||||
import { sendRuntimeMessage } from '@common/message/runtime.message';
|
||||
import LinkDto = Pinmenote.Pin.LinkDto;
|
||||
|
||||
class PinMeScript {
|
||||
private href: string;
|
||||
private redirectInterval = 0;
|
||||
|
||||
constructor(private readonly id: string, private ms: number) {
|
||||
this.href = fnNormalizeHref(window.location.href);
|
||||
WindowMediator.start();
|
||||
ContentMessageHandler.start();
|
||||
document.addEventListener('visibilitychange', this.handleVisibilityChange);
|
||||
TinyEventDispatcher.addListener<ContentSettingsData>(BusMessageType.CONTENT_SETTINGS, this.handleContentSettings);
|
||||
TinyEventDispatcher.addListener<number[]>(BusMessageType.CNT_SETTINGS, this.handlePinSettings);
|
||||
TinyEventDispatcher.dispatch(BusMessageType.CNT_SETTINGS, {});
|
||||
|
||||
TinyEventDispatcher.addListener<TimeoutMessage>(BusMessageType.CONTENT_TIMEOUT, this.handleContentTimeout);
|
||||
TinyEventDispatcher.addListener<LinkDto>(BusMessageType.CONTENT_LINK_ADD, (event, key, value) => {
|
||||
location.href = value.url.href;
|
||||
});
|
||||
}
|
||||
|
||||
private handleContentTimeout = async (event: string, key: string, value: TimeoutMessage) => {
|
||||
if (value.id === this.id) {
|
||||
await new InvalidatePinsCommand(this.href).execute();
|
||||
this.href = fnNormalizeHref(window.location.href);
|
||||
await sendRuntimeMessage<TimeoutMessage>({
|
||||
type: BusMessageType.CONTENT_TIMEOUT,
|
||||
data: { id: this.id, ms: this.ms }
|
||||
});
|
||||
this.adaptIntervalMs();
|
||||
}
|
||||
};
|
||||
|
||||
private handleContentSettings = async (event: string, key: string, data: ContentSettingsData) => {
|
||||
BorderStore.setBorderSettings(data);
|
||||
if (data.link) new CreateLinkCommand(data.link).execute();
|
||||
await new RuntimePinGetHrefCommand().execute();
|
||||
await this.initialTimeout();
|
||||
};
|
||||
|
||||
private handlePinSettings = async (event: string, key: string): Promise<void> => {
|
||||
this.checkForLink();
|
||||
TinyEventDispatcher.removeListener(event, key);
|
||||
const theme = window.matchMedia('(prefers-color-scheme: light)').matches
|
||||
? ExtensionTheme.LIGHT
|
||||
: ExtensionTheme.DARK;
|
||||
await sendRuntimeMessage<ContentExtensionData>({
|
||||
type: BusMessageType.CONTENT_SETTINGS,
|
||||
data: {
|
||||
href: this.href,
|
||||
theme
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
private checkForLink(): void {
|
||||
if (!window.location.href.startsWith(environmentConfig.shortUrl)) return;
|
||||
this.redirectInterval = window.setInterval(this.redirect, 100);
|
||||
}
|
||||
|
||||
private redirect = async (): Promise<void> => {
|
||||
const urlData = document.getElementById('urlData');
|
||||
if (urlData) {
|
||||
clearInterval(this.redirectInterval);
|
||||
if (urlData.innerText) {
|
||||
const { data } = JSON.parse(urlData.innerText);
|
||||
await sendRuntimeMessage<LinkDto>({ type: BusMessageType.CONTENT_LINK_ADD, data });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private handleVisibilityChange = async (e: Event): Promise<void> => {
|
||||
fnConsoleLog('visibilitychange', e);
|
||||
await this.initialTimeout();
|
||||
try {
|
||||
await sendRuntimeMessage<undefined>({
|
||||
type: BusMessageType.CONTENT_PIN_CHANGED
|
||||
});
|
||||
} catch (e) {
|
||||
fnConsoleLog('PROBLEM->handleVisibilityChange !!!', e);
|
||||
this.cleanup();
|
||||
}
|
||||
};
|
||||
|
||||
private async initialTimeout(): Promise<void> {
|
||||
fnConsoleLog('initialTimeout');
|
||||
try {
|
||||
// TODO move to settings
|
||||
await sendRuntimeMessage<TimeoutMessage>({
|
||||
type: BusMessageType.CONTENT_TIMEOUT,
|
||||
data: { id: this.id, ms: this.ms }
|
||||
});
|
||||
this.adaptIntervalMs();
|
||||
} catch (e) {
|
||||
fnConsoleLog('PROBLEM->initialTimeout !!!', e);
|
||||
this.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
private cleanup(): void {
|
||||
document.removeEventListener('visibilitychange', this.handleVisibilityChange);
|
||||
TinyEventDispatcher.cleanup();
|
||||
DocumentMediator.stopListeners();
|
||||
PinStore.clear();
|
||||
WindowMediator.cleanup();
|
||||
ContentMessageHandler.cleanup();
|
||||
}
|
||||
|
||||
private adaptIntervalMs() {
|
||||
switch (this.ms) {
|
||||
case 250:
|
||||
this.ms = 500;
|
||||
break;
|
||||
case 500:
|
||||
this.ms = 1000;
|
||||
break;
|
||||
default:
|
||||
this.ms = 2000;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
new PinMeScript(fnUid(), 250);
|
||||
fnConsoleLog('PinMeScript -> STARTED !!!');
|
||||
} catch (e: unknown) {
|
||||
fnConsoleError('PROBLEM !!!', e);
|
||||
}
|
41
src/content-script/fn/content-calculate-pin-point.ts
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import PinSize = Pinmenote.Pin.PinSize;
|
||||
import PinRectangle = Pinmenote.Pin.PinRectangle;
|
||||
import PinPoint = Pinmenote.Pin.PinPoint;
|
||||
|
||||
export const contentCalculatePinPoint = (
|
||||
ref: HTMLElement,
|
||||
pinSize: PinSize,
|
||||
elementSize: PinRectangle,
|
||||
offset: PinPoint
|
||||
): PinPoint => {
|
||||
const rect = ref.getBoundingClientRect();
|
||||
const offsetScaleX = rect.width / elementSize.width;
|
||||
const offsetScaleY = rect.height / elementSize.height;
|
||||
let x = rect.left + offset.x * offsetScaleX + window.scrollX;
|
||||
const y = rect.top + offset.y * offsetScaleY + window.scrollY;
|
||||
// TODO move only required width to fit
|
||||
if (x + pinSize.width > window.innerWidth) {
|
||||
x = rect.right - pinSize.width;
|
||||
}
|
||||
/* NOT WORKING
|
||||
if (y + dto.size.height > window.innerHeight + document.body.scrollHeight) {
|
||||
y = rect.bottom;
|
||||
}*/
|
||||
return { x, y };
|
||||
};
|
169
src/content-script/fn/content-pin-new.ts
Normal file
@ -0,0 +1,169 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { HtmlContent, ObjectTypeDto } from '@common/model/html.model';
|
||||
import { PinObject, PinViewType } from '@common/model/pin.model';
|
||||
import { fnComputeCssContent, fnComputeHtmlContent } from '@common/fn/compute.element.fn';
|
||||
import { BusMessageType } from '@common/model/bus.model';
|
||||
import { TinyEventDispatcher } from '@common/service/tiny.event.dispatcher';
|
||||
import { contentPinNewUrl } from '@common/fn/pin/content-pin-new-url';
|
||||
import { fnImgResize } from '@common/fn/img.resize.fn';
|
||||
import { fnUid } from '@common/fn/uid.fn';
|
||||
import { fnXpath } from '@common/fn/xpath.fn';
|
||||
import { sendRuntimeMessage } from '@common/message/runtime.message';
|
||||
import LinkLocator = Pinmenote.Pin.LinkLocator;
|
||||
import PinPoint = Pinmenote.Pin.PinPoint;
|
||||
|
||||
export const contentPinNew = async (ref: HTMLElement, offset: PinPoint): Promise<PinObject> => {
|
||||
// Roll back border to take snapshot
|
||||
const uid = fnUid();
|
||||
const locator: LinkLocator = computeLinkLocator(ref, offset);
|
||||
const content: HtmlContent = computePinContent(ref);
|
||||
const dt = new Date().toISOString();
|
||||
const dto: PinObject = {
|
||||
id: -1,
|
||||
uid,
|
||||
type: ObjectTypeDto.Pin,
|
||||
version: 1,
|
||||
visible: true,
|
||||
createdDate: dt,
|
||||
updatedDate: dt,
|
||||
viewType: PinViewType.SCREENSHOT,
|
||||
url: contentPinNewUrl(),
|
||||
locator,
|
||||
content,
|
||||
value: '',
|
||||
size: {
|
||||
width: 163,
|
||||
height: 34
|
||||
},
|
||||
border: {
|
||||
radius: ref.style.borderRadius,
|
||||
style: ref.style.border
|
||||
}
|
||||
};
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
// Crop screenshot function
|
||||
let id = -1;
|
||||
TinyEventDispatcher.addListener<string>(
|
||||
BusMessageType.CONTENT_PIN_SCREENSHOT,
|
||||
async (event: string, key: string, value: string) => {
|
||||
TinyEventDispatcher.removeListener(event, key);
|
||||
// add pin with screenshot
|
||||
dto.id = id;
|
||||
await addNewPinWithScreenshot(dto, value, resolve);
|
||||
}
|
||||
);
|
||||
TinyEventDispatcher.addListener<number>(BusMessageType.CONTENT_PIN_ID, (event, key, value) => {
|
||||
TinyEventDispatcher.removeListener(event, key);
|
||||
id = value;
|
||||
sendGetPinTakeScreenshot(reject);
|
||||
});
|
||||
sendGetPinNextId(reject);
|
||||
});
|
||||
};
|
||||
|
||||
const computeLinkLocator = (ref: HTMLElement, offset: PinPoint): LinkLocator => {
|
||||
const rect = ref.getBoundingClientRect();
|
||||
const xpath = fnXpath(ref);
|
||||
return {
|
||||
xpath,
|
||||
offset,
|
||||
elementSize: {
|
||||
x: Math.round(rect.x),
|
||||
y: Math.round(rect.y),
|
||||
width: Math.round(rect.width),
|
||||
height: Math.round(rect.height)
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const computePinContent = (ref: HTMLElement): HtmlContent => {
|
||||
const bodyStyle = document.body.getAttribute('style') || undefined;
|
||||
const title = document.title;
|
||||
const htmlContent = fnComputeHtmlContent(ref);
|
||||
// fnConsoleLog('HTML :', htmlContent);
|
||||
let parent = ref.parentElement;
|
||||
// MAYBE WILL HELP - COMPUTE PARENT STYLES UP TO BODY
|
||||
// fnConsoleLog('1: ', htmlContent.cssStyles, parent);
|
||||
while (parent && parent.tagName.toLowerCase() !== 'html') {
|
||||
const attr = parent.getAttributeNode('class');
|
||||
if (attr) {
|
||||
const a = attr.value.split(' ').filter((e) => !!e);
|
||||
htmlContent.cssStyles.push(...a.map((e) => `.${e}`));
|
||||
}
|
||||
// fnConsoleLog('ADD : ', parent.tagName);
|
||||
htmlContent.cssStyles.push(parent.tagName);
|
||||
parent = parent.parentElement;
|
||||
}
|
||||
// fnConsoleLog('2:', htmlContent.cssStyles, parent);
|
||||
|
||||
const css = fnComputeCssContent(htmlContent.cssStyles);
|
||||
const elementText = ref.innerText;
|
||||
const isLightTheme = window.matchMedia('(prefers-color-scheme: light)').matches;
|
||||
return {
|
||||
theme: isLightTheme ? 'light' : 'dark',
|
||||
bodyStyle,
|
||||
title,
|
||||
html: htmlContent.html,
|
||||
videoTime: htmlContent.videoTime,
|
||||
css,
|
||||
elementText
|
||||
};
|
||||
};
|
||||
|
||||
const sendGetPinNextId = (reject: (value: string) => void) => {
|
||||
sendRuntimeMessage<undefined>({
|
||||
type: BusMessageType.CONTENT_PIN_ID
|
||||
})
|
||||
.then(() => {
|
||||
// We handle it above, inside dispatcher
|
||||
})
|
||||
.catch(() => {
|
||||
reject('PROBLEM !!!');
|
||||
});
|
||||
};
|
||||
|
||||
const sendGetPinTakeScreenshot = (reject: (value: string) => void) => {
|
||||
sendRuntimeMessage<undefined>({
|
||||
type: BusMessageType.CONTENT_PIN_SCREENSHOT
|
||||
})
|
||||
.then(() => {
|
||||
// We handle it above, inside dispatcher
|
||||
})
|
||||
.catch(() => {
|
||||
reject('PROBLEM !!!');
|
||||
});
|
||||
};
|
||||
|
||||
const addNewPinWithScreenshot = async (
|
||||
dto: PinObject,
|
||||
screenshot: string,
|
||||
resolve: (value: PinObject) => void
|
||||
): Promise<void> => {
|
||||
// Let's resize screenshot and resolve promise
|
||||
try {
|
||||
screenshot = await fnImgResize(dto, screenshot);
|
||||
} finally {
|
||||
dto.screenshot = screenshot;
|
||||
}
|
||||
await sendRuntimeMessage<PinObject>({
|
||||
type: BusMessageType.CONTENT_PIN_ADD,
|
||||
data: dto
|
||||
});
|
||||
resolve(dto);
|
||||
};
|
82
src/content-script/fn/content-swap-pin.ts
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { fnComputeCssContent, fnComputeHtmlContent } from '@common/fn/compute.element.fn';
|
||||
import { BorderStore } from '../store/border.store';
|
||||
import { BusMessageType } from '@common/model/bus.model';
|
||||
import { PinComponent } from '../components/pin.component';
|
||||
import { PinUpdateObject } from '@common/model/pin.model';
|
||||
import { TinyEventDispatcher } from '@common/service/tiny.event.dispatcher';
|
||||
import { fnImgResize } from '@common/fn/img.resize.fn';
|
||||
import { fnSleep } from '@common/fn/sleep.fn';
|
||||
import { fnXpath } from '@common/fn/xpath.fn';
|
||||
import { sendRuntimeMessage } from '@common/message/runtime.message';
|
||||
|
||||
export const contentSwapPin = async (pinData: PinComponent, element: HTMLElement): Promise<void> => {
|
||||
pinData.container.style.display = 'none';
|
||||
pinData.ref.style.border = pinData.object.border.style;
|
||||
pinData.ref.style.borderRadius = pinData.object.border.radius;
|
||||
await fnSleep(100);
|
||||
pinData.ref = element;
|
||||
pinData.object.locator.xpath = fnXpath(element);
|
||||
pinData.object.content.elementText = element.innerText;
|
||||
|
||||
const htmlContent = fnComputeHtmlContent(element);
|
||||
const css = fnComputeCssContent(htmlContent.cssStyles);
|
||||
|
||||
pinData.object.content.html = htmlContent.html;
|
||||
pinData.object.content.videoTime = htmlContent.videoTime;
|
||||
pinData.object.content.css = css;
|
||||
|
||||
const rect = element.getBoundingClientRect();
|
||||
pinData.object.locator.elementSize = {
|
||||
x: Math.round(rect.x),
|
||||
y: Math.round(rect.y),
|
||||
width: Math.round(rect.width),
|
||||
height: Math.round(rect.height)
|
||||
};
|
||||
pinData.object.locator.offset = { x: 0, y: 0 };
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
sendRuntimeMessage<undefined>({
|
||||
type: BusMessageType.CONTENT_PIN_SCREENSHOT
|
||||
})
|
||||
.then(() => {
|
||||
// We handle it above, inside dispatcher
|
||||
})
|
||||
.catch(() => {
|
||||
pinData.container.style.display = 'inline-block';
|
||||
reject('PROBLEM !!!');
|
||||
});
|
||||
TinyEventDispatcher.addListener<string>(BusMessageType.CONTENT_PIN_SCREENSHOT, async (event, key, value) => {
|
||||
// After taking screenshot let's go back to note styles
|
||||
pinData.container.style.display = 'inline-block';
|
||||
element.style.border = BorderStore.borderStyle;
|
||||
element.style.borderRadius = BorderStore.borderRadius;
|
||||
|
||||
TinyEventDispatcher.removeListener(event, key);
|
||||
|
||||
pinData.object.screenshot = await fnImgResize(pinData.object, value);
|
||||
|
||||
await sendRuntimeMessage<PinUpdateObject>({
|
||||
type: BusMessageType.CONTENT_PIN_UPDATE,
|
||||
data: { pin: pinData.object }
|
||||
});
|
||||
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
};
|
20
src/content-script/fn/is-element-hidden.ts
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
export const isElementHidden = (el: HTMLElement): boolean => {
|
||||
const style = window.getComputedStyle(el);
|
||||
return style.display === 'none' || el.offsetParent === null; // !document.body.contains(el);
|
||||
};
|
29
src/content-script/fn/resolve-video-time.ts
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { ContentVideoTime } from '@common/model/html.model';
|
||||
import { fnFindElementXpath } from '@common/fn/xpath.fn';
|
||||
|
||||
export const resolveVideoTime = (videoTime?: ContentVideoTime[]): void => {
|
||||
if (!videoTime) return;
|
||||
for (const video of videoTime) {
|
||||
const value = fnFindElementXpath(video.xpath);
|
||||
const node = value.singleNodeValue as HTMLVideoElement;
|
||||
if (!node) continue;
|
||||
node.currentTime = video.currentTime;
|
||||
node.pause();
|
||||
}
|
||||
};
|
26
src/content-script/fn/scroll-to-element.fn.ts
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
export const scrollToElementFn = (view?: HTMLElement, offset?: number): number => {
|
||||
if (!view) return -1;
|
||||
const rect = view.getBoundingClientRect();
|
||||
const top = Math.max(rect.y - (offset || 0), 0);
|
||||
window.scrollTo({
|
||||
top,
|
||||
behavior: 'smooth'
|
||||
});
|
||||
return top;
|
||||
};
|
45
src/content-script/mediator/document.mediator.ts
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { PinAddElementStore } from '../store/pin-add-element.store';
|
||||
|
||||
export class DocumentMediator {
|
||||
static startListeners(): void {
|
||||
document.addEventListener('keydown', this.handleKeyDown);
|
||||
document.addEventListener('mouseover', this.handleMouseOver);
|
||||
}
|
||||
|
||||
static stopListeners(): void {
|
||||
document.removeEventListener('keydown', this.handleKeyDown);
|
||||
document.removeEventListener('mouseover', this.handleMouseOver);
|
||||
PinAddElementStore.clearElement();
|
||||
}
|
||||
|
||||
private static handleKeyDown = (event: KeyboardEvent): void => {
|
||||
if (event.key === 'Escape') {
|
||||
this.stopListeners();
|
||||
}
|
||||
};
|
||||
|
||||
private static handleMouseOver = (event: MouseEvent): void => {
|
||||
if (PinAddElementStore.hasElement) {
|
||||
PinAddElementStore.clearElement();
|
||||
}
|
||||
if (event.target instanceof HTMLElement) {
|
||||
PinAddElementStore.updateElement(event.target);
|
||||
}
|
||||
};
|
||||
}
|
72
src/content-script/mediator/window.mediator.ts
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { BusMessageType } from '@common/model/bus.model';
|
||||
import { PinStore } from '../store/pin.store';
|
||||
import { RuntimeLoginRefreshCommand } from '../command/runtime/runtime-login-refresh.command';
|
||||
import { TinyEventDispatcher } from '@common/service/tiny.event.dispatcher';
|
||||
import { fnConsoleLog } from '@common/fn/console.fn';
|
||||
import { sendRuntimeMessage } from '@common/message/runtime.message';
|
||||
import AccessTokenDto = Pinmenote.Auth.AccessTokenDto;
|
||||
|
||||
export class WindowMediator {
|
||||
private static readonly ACCESS_TOKEN_EVENT = 'pinmenote.access.token';
|
||||
private static readonly REFRESH_TOKEN_RESPONSE_EVENT = 'pinmenote.refresh.token.response';
|
||||
private static readonly REFRESH_TOKEN_EVENT = 'pinmenote.refresh.token';
|
||||
|
||||
private static readonly LOGIN_EVENT = 'pinmenote.login';
|
||||
|
||||
static start(): void {
|
||||
window.addEventListener(this.LOGIN_EVENT, this.handleContentLoginRefresh);
|
||||
window.addEventListener(this.REFRESH_TOKEN_EVENT, this.handleRefreshToken);
|
||||
window.addEventListener('resize', this.handleResize);
|
||||
|
||||
TinyEventDispatcher.addListener<AccessTokenDto | undefined>(BusMessageType.CONTENT_LOGIN, this.handleLogin);
|
||||
TinyEventDispatcher.addListener<void>(BusMessageType.CONTENT_REFRESH_TOKEN, this.handleContentRefreshToken);
|
||||
}
|
||||
|
||||
static cleanup(): void {
|
||||
window.removeEventListener(this.LOGIN_EVENT, this.handleContentLoginRefresh);
|
||||
window.removeEventListener(this.REFRESH_TOKEN_EVENT, this.handleRefreshToken);
|
||||
window.removeEventListener('resize', this.handleResize);
|
||||
}
|
||||
|
||||
private static handleContentLoginRefresh = async () => {
|
||||
await new RuntimeLoginRefreshCommand().execute();
|
||||
};
|
||||
|
||||
private static handleRefreshToken = async () => {
|
||||
fnConsoleLog('handleRefreshToken');
|
||||
await sendRuntimeMessage<string>({ type: BusMessageType.CONTENT_REFRESH_TOKEN, data: window.location.origin });
|
||||
};
|
||||
|
||||
// Move to message manager
|
||||
private static handleContentRefreshToken = () => {
|
||||
fnConsoleLog('content-script->handleContentRefrehToken');
|
||||
window.dispatchEvent(new Event(this.REFRESH_TOKEN_RESPONSE_EVENT));
|
||||
};
|
||||
|
||||
private static handleLogin = (event: string, key: string, value: AccessTokenDto | undefined) => {
|
||||
fnConsoleLog('content-script->handleLogin', event, value);
|
||||
window.dispatchEvent(new MessageEvent(this.ACCESS_TOKEN_EVENT, { data: value }));
|
||||
};
|
||||
|
||||
private static handleResize = (): void => {
|
||||
PinStore.each((pin) => {
|
||||
pin.resize();
|
||||
});
|
||||
};
|
||||
}
|
35
src/content-script/store/border.store.ts
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { ContentSettingsData } from '@common/model/settings.model';
|
||||
|
||||
export class BorderStore {
|
||||
private static borderStyleValue = '2px solid #90caf9'; // TODO make it customizable
|
||||
private static borderRadiusValue = '5px'; // TODO make it customizable
|
||||
|
||||
static get borderStyle(): string {
|
||||
return this.borderStyleValue;
|
||||
}
|
||||
|
||||
static get borderRadius(): string {
|
||||
return this.borderRadiusValue;
|
||||
}
|
||||
|
||||
static setBorderSettings(data: ContentSettingsData) {
|
||||
this.borderRadiusValue = data.borderRadius;
|
||||
this.borderStyleValue = data.borderStyle;
|
||||
}
|
||||
}
|
75
src/content-script/store/pin-add-element.store.ts
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { BorderStore } from './border.store';
|
||||
import { CreatePinDataCommand } from '../command/pin/create-pin-data.command';
|
||||
import { DocumentMediator } from '../mediator/document.mediator';
|
||||
import { fnConsoleLog } from '@common/fn/console.fn';
|
||||
|
||||
export class PinAddElementStore {
|
||||
private static currentElement: HTMLElement | null = null;
|
||||
private static currentElementBorderStyle = '';
|
||||
private static currentElementBorderRadius = '';
|
||||
|
||||
static get hasElement(): boolean {
|
||||
return !!this.currentElement;
|
||||
}
|
||||
|
||||
static get borderStyle(): string {
|
||||
return this.currentElementBorderStyle;
|
||||
}
|
||||
|
||||
static get borderRadius(): string {
|
||||
return this.currentElementBorderRadius;
|
||||
}
|
||||
|
||||
static clearElement(): void {
|
||||
if (!this.currentElement) return;
|
||||
this.currentElement.removeEventListener('click', this.handleElementClick);
|
||||
this.currentElement.style.border = this.currentElementBorderStyle;
|
||||
this.currentElement.style.borderRadius = this.currentElementBorderRadius;
|
||||
this.currentElementBorderStyle = '';
|
||||
this.currentElementBorderRadius = '';
|
||||
this.currentElement = null;
|
||||
}
|
||||
|
||||
static updateElement(element: HTMLElement): void {
|
||||
if (this.currentElement !== element) {
|
||||
this.currentElement = element;
|
||||
this.currentElement.addEventListener('click', this.handleElementClick);
|
||||
this.currentElementBorderStyle = this.currentElement.style.border;
|
||||
this.currentElementBorderRadius = this.currentElement.style.borderRadius;
|
||||
this.currentElement.style.border = BorderStore.borderStyle;
|
||||
this.currentElement.style.borderRadius = BorderStore.borderRadius;
|
||||
}
|
||||
}
|
||||
|
||||
private static handleElementClick = async (event: MouseEvent): Promise<void> => {
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
fnConsoleLog('CLick', event);
|
||||
if (this.currentElement) {
|
||||
const element = event.target as HTMLElement;
|
||||
this.currentElement.style.border = this.currentElementBorderStyle;
|
||||
this.currentElement.style.borderRadius = this.currentElementBorderRadius;
|
||||
await new CreatePinDataCommand(element, {
|
||||
x: event.offsetX,
|
||||
y: event.offsetY
|
||||
}).execute();
|
||||
}
|
||||
DocumentMediator.stopListeners();
|
||||
};
|
||||
}
|
54
src/content-script/store/pin-drag.store.ts
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { PinObject, PinUpdateObject } from '@common/model/pin.model';
|
||||
import { BusMessageType } from '@common/model/bus.model';
|
||||
import { ObjectTypeDto } from '@common/model/html.model';
|
||||
import { PinComponent } from '../components/pin.component';
|
||||
import { PinStore } from './pin.store';
|
||||
import { sendRuntimeMessage } from '@common/message/runtime.message';
|
||||
import PinPoint = Pinmenote.Pin.PinPoint;
|
||||
|
||||
export class PinDragStore {
|
||||
private static dragValue?: PinComponent;
|
||||
|
||||
public static startDragPin(pin: PinObject): void {
|
||||
if (pin.type !== ObjectTypeDto.Pin) return;
|
||||
this.dragValue = PinStore.getByUid(pin.uid) as PinComponent;
|
||||
this.dragValue?.startDrag();
|
||||
}
|
||||
|
||||
public static dragPin(value: PinPoint): void {
|
||||
if (!this.dragValue) return;
|
||||
this.dragValue.updateDrag(value);
|
||||
}
|
||||
|
||||
public static async stopDragPin(value: PinPoint): Promise<void> {
|
||||
if (!this.dragValue) return;
|
||||
this.dragValue.stopDrag(value);
|
||||
await sendRuntimeMessage<PinUpdateObject>({
|
||||
type: BusMessageType.CONTENT_PIN_UPDATE,
|
||||
data: { pin: this.dragValue.object }
|
||||
});
|
||||
if (this.dragValue) {
|
||||
this.dragValue = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
public static get isDrag(): boolean {
|
||||
return !!this.dragValue;
|
||||
}
|
||||
}
|
34
src/content-script/store/pin-pending.store.ts
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { HtmlObject } from '@common/model/html.model';
|
||||
|
||||
export class PinPendingStore {
|
||||
// Map of pending pins
|
||||
private static pendingPins: { [key: string]: HtmlObject } = {};
|
||||
|
||||
static get values(): HtmlObject[] {
|
||||
return Object.values(PinPendingStore.pendingPins);
|
||||
}
|
||||
|
||||
static add(pin: HtmlObject): void {
|
||||
this.pendingPins[pin.uid] = pin;
|
||||
}
|
||||
|
||||
static remove(key: string): void {
|
||||
delete this.pendingPins[key];
|
||||
}
|
||||
}
|
84
src/content-script/store/pin.store.ts
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* This file is part of the pinmenote-extension distribution (https://github.com/pinmenote/pinmenote-extension).
|
||||
* Copyright (c) 2022 Michal Szczepanski.
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { HtmlComponent, ObjectTypeDto } from '@common/model/html.model';
|
||||
import { PinComponent } from '../components/pin.component';
|
||||
import { PinObject } from '@common/model/pin.model';
|
||||
import { contentSwapPin } from '../fn/content-swap-pin';
|
||||
import { fnConsoleLog } from '@common/fn/console.fn';
|
||||
|
||||
export class PinStore {
|
||||
private static pinData: HtmlComponent[] = [];
|
||||
|
||||
public static getByUid(uid: string): HtmlComponent | undefined {
|
||||
const index = this.pinData.findIndex((p) => p.object.uid === uid);
|
||||
if (index > -1) {
|
||||
return this.pinData[index];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public static add(data: HtmlComponent): HtmlComponent {
|
||||
if (this.pinData.findIndex((c) => c.object.uid === data.object.uid) === -1) {
|
||||
this.pinData.push(data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static delByUid(uid: string): HtmlComponent | undefined {
|
||||
fnConsoleLog('PinStore->delByUid', uid);
|
||||
const index = this.pinData.findIndex((c) => c.object.uid === uid);
|
||||
if (index > -1) {
|
||||
const data = this.pinData.splice(index, 1)[0];
|
||||
// Cleanup component
|
||||
data.cleanup();
|
||||
return data;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public static clear(): void {
|
||||
for (const pinData of this.pinData) {
|
||||
this.delByUid(pinData.object.uid);
|
||||
}
|
||||
this.pinData = [];
|
||||
}
|
||||
|
||||
public static each(fn: (value: HtmlComponent, index: number, array: HtmlComponent[]) => void): void {
|
||||
this.pinData.forEach(fn);
|
||||
}
|
||||
|
||||
public static focusPin(pin: PinObject): void {
|
||||
const obj = this.getByUid(pin.uid);
|
||||
if (!obj) return;
|
||||
obj.focus(true);
|
||||
}
|
||||
|
||||
public static async pinToParent(pin: PinObject, ref: HTMLElement | null): Promise<void> {
|
||||
// Only pin
|
||||
if (pin.type !== ObjectTypeDto.Pin) return;
|
||||
const obj = this.getByUid(pin.uid);
|
||||
if (!obj || !ref) return;
|
||||
await contentSwapPin(obj as PinComponent, ref);
|
||||
const rect = (obj as PinComponent).ref.getBoundingClientRect();
|
||||
obj.object.locator.offset.x = 0;
|
||||
obj.object.locator.offset.y = 0;
|
||||
obj.object.locator.elementSize.x = rect.x;
|
||||
obj.object.locator.elementSize.y = rect.y;
|
||||
obj.object.locator.elementSize.width = rect.width;
|
||||
obj.object.locator.elementSize.height = rect.height;
|
||||
}
|
||||
}
|