Compare commits
73 commits
Author | SHA1 | Date | |
---|---|---|---|
b12f | 2ea2444e84 | ||
b12f | 4fe03486eb | ||
b12f | a51aad42ee | ||
b12f | 9ff091bd39 | ||
b12f | aa2cbbde5b | ||
b12f | e55202bc67 | ||
b12f | 63ba5859ff | ||
Benjamin Bädorf | 2ad72bbf61 | ||
Benjamin Bädorf | 3ee4418ef3 | ||
Benjamin Bädorf | a6b162eddb | ||
Benjamin Bädorf | 649957c544 | ||
Benjamin Bädorf | 7142cb40d7 | ||
Benjamin Bädorf | 66086318e5 | ||
Benjamin Bädorf | fb9baa1d88 | ||
Benjamin Bädorf | 44c32f89ee | ||
Benjamin Bädorf | b9de87f8c1 | ||
Benjamin Bädorf | 59b01e3e88 | ||
Benjamin Bädorf | fdb8ffcf2d | ||
Benjamin Bädorf | 4f870c63a6 | ||
Benjamin Bädorf | 7b9c598756 | ||
Benjamin Bädorf | 6dce0e47fd | ||
Benjamin Bädorf | 77a7d74157 | ||
Benjamin Bädorf | c3ef4f7f87 | ||
Benjamin Bädorf | c5109dba75 | ||
Benjamin Bädorf | 7b82b88c5a | ||
Benjamin Bädorf | 516c82d5c0 | ||
Benjamin Bädorf | b699a39b0f | ||
Benjamin Bädorf | ada6cbf461 | ||
Benjamin Bädorf | 5b9e531efc | ||
Benjamin Bädorf | 2976e1fa95 | ||
Benjamin Bädorf | ceadc8ad80 | ||
Benjamin Bädorf | 412f26d71d | ||
Benjamin Bädorf | b587e9a6ef | ||
Benjamin Bädorf | 084c5c15bb | ||
Benjamin Bädorf | a1a6a54d89 | ||
Benjamin Bädorf | 26c2395b9e | ||
Benjamin Bädorf | 54c71ff81c | ||
Benjamin Bädorf | ff668eff31 | ||
Benjamin Bädorf | 190a8be207 | ||
fe85fab1c0 | |||
83e450fe7d | |||
Benjamin Bädorf | ca8d26ccc9 | ||
Benjamin Bädorf | 47b3bda84d | ||
Benjamin Bädorf | db2190f832 | ||
Benjamin Bädorf | f8f6564b60 | ||
Benjamin Bädorf | b4919d6c3e | ||
Benjamin Bädorf | 4ffafd4bb5 | ||
Benjamin Bädorf | 01c2644a36 | ||
5b5d07dca1 | |||
Benjamin Bädorf | 583aa62749 | ||
d0baa857db | |||
Benjamin Bädorf | 9689a0e3fe | ||
6f341462f6 | |||
Benjamin Bädorf | 1bb7e2e94e | ||
ee6b27105f | |||
Benjamin Bädorf | da93d2b104 | ||
de2e5dbcab | |||
Benjamin Bädorf | 9289083a59 | ||
Benjamin Bädorf | bd3152c00e | ||
Benjamin Bädorf | 65dfc3f7cd | ||
Benjamin Bädorf | 3f93f77602 | ||
Benjamin Bädorf | 99320b77e2 | ||
Benjamin Bädorf | c5c32be397 | ||
Benjamin Bädorf | 4fc087a752 | ||
Benjamin Bädorf | 869c4d1a28 | ||
Benjamin Bädorf | 136218995a | ||
Benjamin Bädorf | fd44ea67a3 | ||
Benjamin Bädorf | b96f8cb5f7 | ||
Benjamin Bädorf | 16e0ffdd99 | ||
Benjamin Bädorf | 7d6a3730c6 | ||
Benjamin Bädorf | d76f40cf7d | ||
Benjamin Bädorf | d64d9e4af7 | ||
bc49cbfd30 |
|
@ -1,7 +1,24 @@
|
|||
[*.{js,jsx,ts,tsx,vue}]
|
||||
# Editor configuration, see http://editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
max_line_length = 100
|
||||
|
||||
# Ignore diffs/patches
|
||||
[*.{diff,patch}]
|
||||
end_of_line = unset
|
||||
insert_final_newline = unset
|
||||
trim_trailing_whitespace = unset
|
||||
indent_size = unset
|
||||
charset = unset
|
||||
indent_style = unset
|
||||
indent_size = unset
|
||||
|
||||
[*.md]
|
||||
max_line_length = off
|
||||
trim_trailing_whitespace = false
|
||||
|
|
8
.gitignore
vendored
8
.gitignore
vendored
|
@ -1,5 +1,13 @@
|
|||
.direnv
|
||||
node_modules
|
||||
.DS_Store
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
tags
|
||||
.temp
|
||||
.cache
|
||||
docs/.vitepress/cache
|
||||
docs/.vitepress/dist
|
||||
__screenshots__
|
||||
__snapshots__
|
||||
|
|
660
LICENSE.md
Normal file
660
LICENSE.md
Normal file
|
@ -0,0 +1,660 @@
|
|||
### GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc.
|
||||
<https://fsf.org/>
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this
|
||||
license document, but changing it is not allowed.
|
||||
|
||||
### Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are 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.
|
||||
|
||||
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.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing
|
||||
under this license.
|
||||
|
||||
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 Affero 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. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your
|
||||
version supports such interaction) an opportunity to receive the
|
||||
Corresponding Source of your version by providing access to the
|
||||
Corresponding Source from a network server at no charge, through some
|
||||
standard or customary means of facilitating copying of software. This
|
||||
Corresponding Source shall include the Corresponding Source for any
|
||||
work covered by version 3 of the GNU General Public License that is
|
||||
incorporated pursuant to the following paragraph.
|
||||
|
||||
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 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 work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
#### 14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Affero 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 Affero 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 Affero 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 Affero 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 Affero 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 Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper
|
||||
mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for
|
||||
the specific requirements.
|
||||
|
||||
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 AGPL, see <https://www.gnu.org/licenses/>.
|
47
docs/.vitepress/config.mts
Normal file
47
docs/.vitepress/config.mts
Normal file
|
@ -0,0 +1,47 @@
|
|||
import { defineConfig } from 'vitepress';
|
||||
import { defineConfig as defineViteConfig } from 'vite';
|
||||
import vueJsx from '@vitejs/plugin-vue-jsx'
|
||||
import { join } from 'path';
|
||||
|
||||
export default defineConfig({
|
||||
lang: 'en-US',
|
||||
title: 'Schlechtenburg',
|
||||
description: 'Experimental WYSIWYG editor framework made with Vue 3 and TypeScript',
|
||||
lastUpdated: true,
|
||||
|
||||
themeConfig: {
|
||||
sidebar: [
|
||||
{
|
||||
text: 'User Guide',
|
||||
items: [
|
||||
{ text: 'Introduction', link: '/' },
|
||||
{ text: 'Try it out', link: '/try' },
|
||||
{ text: 'Why Schlechtenburg?', link: '/why' },
|
||||
{ text: 'Installation and usage', link: '/installation' },
|
||||
]
|
||||
},
|
||||
{
|
||||
text: 'Creating Blocks',
|
||||
items: [
|
||||
{ text: 'Basics', link: '/creating-blocks/' },
|
||||
{ text: 'Examples', link: '/creating-blocks/examples' },
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
vite: defineViteConfig({
|
||||
plugins: [
|
||||
vueJsx(),
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@schlechtenburg/core': join(__dirname, '../../packages/core/lib/index.ts'),
|
||||
'@schlechtenburg/paragraph': join(__dirname, '../../packages/paragraph/lib/index.ts'),
|
||||
'@schlechtenburg/heading': join(__dirname, '../../packages/heading/lib/index.ts'),
|
||||
'@schlechtenburg/image': join(__dirname, '../../packages/image/lib/index.ts'),
|
||||
'@schlechtenburg/layout': join(__dirname, '../../packages/layout/lib/index.ts'),
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
42
docs/ExampleEditor.scss
Normal file
42
docs/ExampleEditor.scss
Normal file
|
@ -0,0 +1,42 @@
|
|||
.example-editor {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-left: 4rem;
|
||||
|
||||
&--mode {
|
||||
display: flex;
|
||||
justify-content: stretch;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
&--mode-tab {
|
||||
display: flex;
|
||||
margin-top: 1px;
|
||||
padding: 0.25rem 1rem;
|
||||
border-top: 1px solid var(--vp-c-divider-light);
|
||||
border-right: 1px solid var(--vp-c-divider-light);
|
||||
|
||||
input {
|
||||
display: none;
|
||||
}
|
||||
|
||||
&_checked {
|
||||
color: var(--vp-c-brand);
|
||||
}
|
||||
}
|
||||
|
||||
&--sb {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border: 1px solid var(--vp-c-divider-light);
|
||||
}
|
||||
|
||||
&--json {
|
||||
margin: 0;
|
||||
border: 1px solid var(--vp-c-divider-light);
|
||||
|
||||
background-color: var(--vp-c-text-1);
|
||||
color: var(--vp-c-bg);
|
||||
overflow: scroll;
|
||||
}
|
||||
}
|
102
docs/ExampleEditor.tsx
Normal file
102
docs/ExampleEditor.tsx
Normal file
|
@ -0,0 +1,102 @@
|
|||
import {
|
||||
computed,
|
||||
defineComponent,
|
||||
reactive,
|
||||
ref,
|
||||
} from 'vue';
|
||||
|
||||
import { SbMain, IBlockData, SbMode } from '@schlechtenburg/core';
|
||||
|
||||
import SbLayout from '@schlechtenburg/layout';
|
||||
import SbHeading from '@schlechtenburg/heading';
|
||||
import SbParagraph from '@schlechtenburg/paragraph';
|
||||
import SbImage from '@schlechtenburg/image';
|
||||
|
||||
import exampleData from './example-data';
|
||||
|
||||
import './ExampleEditor.scss';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ExampleEditor',
|
||||
|
||||
setup() {
|
||||
const activeTab = ref('edit');
|
||||
const block: IBlockData<any> = reactive({ ...exampleData });
|
||||
const dateID = +(new Date());
|
||||
|
||||
const displayedElement = computed(() => {
|
||||
switch (activeTab.value) {
|
||||
case 'data':
|
||||
return <pre class="example-editor--json"><code>{ JSON.stringify(block, null, 2) }</code></pre>;
|
||||
default:
|
||||
return <SbMain
|
||||
class="example-editor--sb"
|
||||
block={block}
|
||||
availableBlocks={[
|
||||
SbLayout,
|
||||
SbHeading,
|
||||
SbImage,
|
||||
SbParagraph,
|
||||
]}
|
||||
mode={activeTab.value as SbMode}
|
||||
eventUpdate={(data:IBlockData<any>) => {
|
||||
block.id = data.id;
|
||||
block.name = data.name;
|
||||
block.data = data.data;
|
||||
}}
|
||||
/>;
|
||||
}
|
||||
});
|
||||
|
||||
const onModeChange = ($event: Event) => {
|
||||
activeTab.value = ($event.target as HTMLSelectElement).value;
|
||||
};
|
||||
|
||||
return () => {
|
||||
return <div class="example-editor">
|
||||
<div class="example-editor--mode">
|
||||
<label class={{
|
||||
'example-editor--mode-tab': true,
|
||||
'example-editor--mode-tab_checked': activeTab.value === SbMode.Edit,
|
||||
}}>
|
||||
<input
|
||||
type="radio"
|
||||
name={`example-editor-${dateID}`}
|
||||
value={SbMode.Edit}
|
||||
checked={activeTab.value === SbMode.Edit}
|
||||
onChange={onModeChange}
|
||||
/>
|
||||
Editor mode
|
||||
</label>
|
||||
<label class={{
|
||||
'example-editor--mode-tab': true,
|
||||
'example-editor--mode-tab_checked': activeTab.value === SbMode.View,
|
||||
}}>
|
||||
<input
|
||||
type="radio"
|
||||
name={`example-editor-${dateID}`}
|
||||
value={SbMode.View}
|
||||
checked={activeTab.value === SbMode.View}
|
||||
onChange={onModeChange}
|
||||
/>
|
||||
View mode
|
||||
</label>
|
||||
<label class={{
|
||||
'example-editor--mode-tab': true,
|
||||
'example-editor--mode-tab_checked': activeTab.value === "data",
|
||||
}}>
|
||||
<input
|
||||
type="radio"
|
||||
name={`example-editor-${dateID}`}
|
||||
value="data"
|
||||
checked={activeTab.value === "data"}
|
||||
onChange={onModeChange}
|
||||
/>
|
||||
JSON Data structure
|
||||
</label>
|
||||
</div>
|
||||
{displayedElement.value}
|
||||
</div>;
|
||||
};
|
||||
},
|
||||
});
|
51
docs/ExampleStandaloneEditor.tsx
Normal file
51
docs/ExampleStandaloneEditor.tsx
Normal file
|
@ -0,0 +1,51 @@
|
|||
import {
|
||||
defineComponent,
|
||||
onMounted,
|
||||
} from 'vue';
|
||||
|
||||
import { startSchlechtenburg } from '@schlechtenburg/standalone';
|
||||
import { SbMode } from '@schlechtenburg/core';
|
||||
|
||||
import SbLayout from '@schlechtenburg/layout';
|
||||
import SbHeading from '@schlechtenburg/heading';
|
||||
import SbParagraph from '@schlechtenburg/paragraph';
|
||||
import SbImage from '@schlechtenburg/image';
|
||||
|
||||
import exampleData from './example-data';
|
||||
|
||||
import './ExampleEditor.scss';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ExampleStandaloneEditor',
|
||||
|
||||
setup() {
|
||||
const block = exampleData;
|
||||
|
||||
onMounted(async () => {
|
||||
// getBlock could be used to access the block data inside the editor
|
||||
const { getBlock } = await startSchlechtenburg(
|
||||
'#example-editor',
|
||||
{
|
||||
// The input block data
|
||||
block,
|
||||
|
||||
mode: SbMode.Edit,
|
||||
// The list of available blocks in this editor instance
|
||||
availableBlocks: [
|
||||
SbLayout,
|
||||
SbHeading,
|
||||
SbParagraph,
|
||||
SbImage,
|
||||
],
|
||||
|
||||
// This callback will be alled any time the block data gets updated
|
||||
onUpdate: (blockData) => {
|
||||
console.log('got update', blockData);
|
||||
}
|
||||
},
|
||||
)
|
||||
});
|
||||
|
||||
return () => <div id="example-editor"></div>;
|
||||
},
|
||||
});
|
165
docs/api.json
Normal file
165
docs/api.json
Normal file
|
@ -0,0 +1,165 @@
|
|||
{
|
||||
"id": 6,
|
||||
"name": "Documentation",
|
||||
"variant": "project",
|
||||
"kind": 1,
|
||||
"flags": {},
|
||||
"children": [
|
||||
{
|
||||
"id": 7,
|
||||
"name": "@schlechtenburg/core",
|
||||
"variant": "declaration",
|
||||
"kind": 2,
|
||||
"flags": {},
|
||||
"readme": [
|
||||
{
|
||||
"kind": "text",
|
||||
"text": "# "
|
||||
},
|
||||
{
|
||||
"kind": "code",
|
||||
"text": "`@schlechtenburg/core`"
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"text": "\n\n> TODO: description\n\n## Usage\n\n"
|
||||
},
|
||||
{
|
||||
"kind": "code",
|
||||
"text": "```\nconst core = require('@schlechtenburg/core');\n\n// TODO: DEMONSTRATE API\n```"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
"name": "@schlechtenburg/heading",
|
||||
"variant": "declaration",
|
||||
"kind": 2,
|
||||
"flags": {},
|
||||
"readme": [
|
||||
{
|
||||
"kind": "text",
|
||||
"text": "# "
|
||||
},
|
||||
{
|
||||
"kind": "code",
|
||||
"text": "`@schlechtenburg/heading`"
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"text": "\n\n> TODO: description\n\n## Usage\n\n"
|
||||
},
|
||||
{
|
||||
"kind": "code",
|
||||
"text": "```\nconst heading = require('@schlechtenburg/heading');\n\n// TODO: DEMONSTRATE API\n```"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
"name": "@schlechtenburg/standalone",
|
||||
"variant": "declaration",
|
||||
"kind": 2,
|
||||
"flags": {},
|
||||
"readme": [
|
||||
{
|
||||
"kind": "text",
|
||||
"text": "# "
|
||||
},
|
||||
{
|
||||
"kind": "code",
|
||||
"text": "`@schlechtenburg/core`"
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"text": "\n\n> TODO: description\n\n## Usage\n\n"
|
||||
},
|
||||
{
|
||||
"kind": "code",
|
||||
"text": "```\nconst core = require('@schlechtenburg/core');\n\n// TODO: DEMONSTRATE API\n```"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
"name": "@schlechtenburg/paragraph",
|
||||
"variant": "declaration",
|
||||
"kind": 2,
|
||||
"flags": {},
|
||||
"readme": [
|
||||
{
|
||||
"kind": "text",
|
||||
"text": "# "
|
||||
},
|
||||
{
|
||||
"kind": "code",
|
||||
"text": "`@schlechtenburg/paragraph`"
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"text": "\n\n> TODO: description\n\n## Usage\n\n"
|
||||
},
|
||||
{
|
||||
"kind": "code",
|
||||
"text": "```\nconst paragraph = require('@schlechtenburg/paragraph');\n\n// TODO: DEMONSTRATE API\n```"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 11,
|
||||
"name": "@schlechtenburg/layout",
|
||||
"variant": "declaration",
|
||||
"kind": 2,
|
||||
"flags": {},
|
||||
"readme": [
|
||||
{
|
||||
"kind": "text",
|
||||
"text": "# "
|
||||
},
|
||||
{
|
||||
"kind": "code",
|
||||
"text": "`@schlechtenburg/layout`"
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"text": "\n\n> TODO: description\n\n## Usage\n\n"
|
||||
},
|
||||
{
|
||||
"kind": "code",
|
||||
"text": "```\nconst layout = require('@schlechtenburg/layout');\n\n// TODO: DEMONSTRATE API\n```"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 12,
|
||||
"name": "@schlechtenburg/image",
|
||||
"variant": "declaration",
|
||||
"kind": 2,
|
||||
"flags": {},
|
||||
"readme": [
|
||||
{
|
||||
"kind": "text",
|
||||
"text": "# "
|
||||
},
|
||||
{
|
||||
"kind": "code",
|
||||
"text": "`@schlechtenburg/image`"
|
||||
},
|
||||
{
|
||||
"kind": "text",
|
||||
"text": "\n\n> TODO: description\n\n## Usage\n\n"
|
||||
},
|
||||
{
|
||||
"kind": "code",
|
||||
"text": "```\nconst image = require('@schlechtenburg/image');\n\n// TODO: DEMONSTRATE API\n```"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"packageName": "schlechtenburg",
|
||||
"symbolIdMap": {},
|
||||
"files": {
|
||||
"entries": {},
|
||||
"reflections": {}
|
||||
}
|
||||
}
|
3
docs/creating-blocks/examples.md
Normal file
3
docs/creating-blocks/examples.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Example blocks
|
||||
|
||||
As Schlechtenburg is still in active development, it's good to check out the official blocks to see what they look like.
|
23
docs/creating-blocks/index.md
Normal file
23
docs/creating-blocks/index.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Creating blocks
|
||||
|
||||
After you've been using Schlechtenburg for a short while, you'll probably end up wanting to create your own blocks.
|
||||
|
||||
## The anatomy of a block
|
||||
|
||||
In general, a block is a javascript object that implements the `IBlockDefinition<T>` interface.
|
||||
|
||||
A functional block contains all of the following:
|
||||
|
||||
1. A unique name. This will be used to assign JSON data to your specific block. It's good practice to prefix these so you don't run into conflicts with other blocks. Official Schlechtenburg block names are prefixed with `sb-`.
|
||||
2. A function that returns a JSON structure representing an "empty" or "default" instance of your block.
|
||||
3. A component for the edit mode.
|
||||
4. A component for the view mode.
|
||||
|
||||
```ts
|
||||
export default {
|
||||
name,
|
||||
getDefaultData,
|
||||
edit: defineAsyncComponent(() => import('./edit')),
|
||||
view: defineAsyncComponent(() => import('./view')),
|
||||
} as IBlockDefinition<any>;
|
||||
```
|
86
docs/example-data.ts
Normal file
86
docs/example-data.ts
Normal file
File diff suppressed because one or more lines are too long
20
docs/examples.md
Normal file
20
docs/examples.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
<script setup>
|
||||
import ExampleEditor from './ExampleEditor'
|
||||
import ExampleStandaloneEditor from './ExampleStandaloneEditor'
|
||||
</script>
|
||||
|
||||
# Examples
|
||||
|
||||
## As a View Component
|
||||
|
||||
This documentation website already uses Vue under the hood, so Schlechtenburg can just imported as
|
||||
any other component:
|
||||
|
||||
<ExampleEditor></ExampleEditor>
|
||||
|
||||
## Standalone
|
||||
|
||||
`@schlechtenburg/standalone` gives you a wrapped version of the editor in case you don't have Vue
|
||||
already installed in your application
|
||||
|
||||
<ExampleStandaloneEditor></ExampleStandaloneEditor>
|
19
docs/index.md
Normal file
19
docs/index.md
Normal file
|
@ -0,0 +1,19 @@
|
|||
---
|
||||
layout: home
|
||||
|
||||
hero:
|
||||
name: Schlechtenburg
|
||||
text: WYSIWYG that's fun.
|
||||
tagline: What-you-see-is-what-you-get editors are unfortunately still really hard to deal with on the web. The default functionality is usually quickly deployed, but the honeymoon does not last long.
|
||||
|
||||
|
||||
Changes to editor behavior are always needed in the real-world, a fact that Schlechtenburg embraces.
|
||||
|
||||
actions:
|
||||
- theme: brand
|
||||
text: Try it out
|
||||
link: /try
|
||||
- theme: alt
|
||||
text: View Code
|
||||
link: https://git.b12f.io/b12f/schlechtenburg
|
||||
---
|
120
docs/installation.md
Normal file
120
docs/installation.md
Normal file
|
@ -0,0 +1,120 @@
|
|||
# Installation and usage
|
||||
|
||||
Schlechtenburg is very modular; consisting of one core package and multiple blocks. All packages are versioned together,
|
||||
meaning that v2.0.3 of one package is guaranteed to work with v2.0.3 of another schlechtenburg package.
|
||||
|
||||
Schlechtenburg is basically one Vue component, so if you're already using Vue you can import and use it directly.
|
||||
Otherwise, there's the standalone version that comes prepackaged with Vue.
|
||||
|
||||
[Projects without Vue 3](#your-project-does-not-use-vue-3) | [Projects with Vue 3](#your-project-uses-vue-3)
|
||||
|
||||
## Your project does not use Vue 3
|
||||
|
||||
### Install npm packages
|
||||
|
||||
Install the standalone editor and any blocks you want to use:
|
||||
|
||||
```ts
|
||||
npm i --save @schlechtenburg/standalone \
|
||||
@schlechtenburg/layout \
|
||||
@schlechtenburg/heading \
|
||||
@schlechtenburg/paragraph
|
||||
```
|
||||
|
||||
### Initializing the editor
|
||||
|
||||
```ts
|
||||
// Import the initialization function
|
||||
import { startSchlechtenburg } from '@schlechtenburg/standalone';
|
||||
import { SbMode } from '@schlechtenburg/core';
|
||||
|
||||
// The following are some Schlechtenburg blocks that
|
||||
// will be available when editing or viewing
|
||||
import {
|
||||
SbLayout,
|
||||
getDefaultData as getEmptyLayoutBlock,
|
||||
} from '@schlechtenburg/layout';
|
||||
import { SbHeading } from '@schlechtenburg/heading';
|
||||
import { SbParagraph } from '@schlechtenburg/paragraph';
|
||||
import { SbImage } from '@schlechtenburg/image';
|
||||
|
||||
// This will be our input state
|
||||
const emptyLayout = getEmptyLayoutBlock();
|
||||
|
||||
// This call initializes the Schlechtenburg editor and viewer.
|
||||
useSchlechtenburg(
|
||||
// Selector of the element the editor should bind to.
|
||||
// Can also the an `HTMLElement` reference.
|
||||
'#editor',
|
||||
{
|
||||
// The input block data
|
||||
block: emptyLayout,
|
||||
|
||||
// Whether Schlechtenburg is in what-you-see (editing)
|
||||
// or in what-you-get (viewing)
|
||||
mode: SbMode.Edit,
|
||||
|
||||
// The list of available blocks in this editor instance
|
||||
availableBlocks: [
|
||||
SbLayout,
|
||||
SbHeading,
|
||||
SbParagraph,
|
||||
SbImage,
|
||||
],
|
||||
|
||||
// This callback will be alled any time the block data gets updated
|
||||
onUpdate: (blockData) => {
|
||||
console.log('Got new block data', blockData);
|
||||
}
|
||||
}, //
|
||||
)
|
||||
|
||||
```
|
||||
|
||||
**Note:** You need to provide both a root node
|
||||
|
||||
## Your project uses Vue 3
|
||||
|
||||
|
||||
### Install npm packages
|
||||
|
||||
Install the editor core and any blocks you want to use:
|
||||
|
||||
```
|
||||
npm i --save @schlechtenburg/core \
|
||||
@schlechtenburg/layout \
|
||||
@schlechtenburg/heading \
|
||||
@schlechtenburg/paragraph
|
||||
```
|
||||
|
||||
|
||||
### Using the editor component
|
||||
|
||||
The following example uses TSX, but `SbMain` is just a Vue component here and can be imported and used just like any other vue component.
|
||||
|
||||
You need to provide a root
|
||||
|
||||
```tsx
|
||||
// This is the main Schlechtenburg component
|
||||
import { SbMain } from '@schlechtenburg/core';
|
||||
|
||||
// The following are some Schlechtenburg blocks that will be available when editing or viewing
|
||||
import { SbLayout } from '@schlechtenburg/layout';
|
||||
import { SbHeading } from '@schlechtenburg/heading';
|
||||
import { SbParagraph } from '@schlechtenburg/paragraph';
|
||||
import { SbImage } from '@schlechtenburg/image';
|
||||
|
||||
// In your component
|
||||
setup () {
|
||||
// ..
|
||||
|
||||
return () => <SbMain
|
||||
availableBlocks={[
|
||||
SbLayout,
|
||||
SbHeading,
|
||||
SbParagraph,
|
||||
SbImage,
|
||||
]}
|
||||
/>;
|
||||
}
|
||||
```
|
72
docs/main.scss
Normal file
72
docs/main.scss
Normal file
|
@ -0,0 +1,72 @@
|
|||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html {
|
||||
--grey-0: white;
|
||||
--grey-1-t: rgba(0, 0, 0, 0.05);
|
||||
--grey-1: rgb(242, 242, 242);
|
||||
--grey-2-t: rgba(0, 0, 0, 0.1);
|
||||
--grey-2: rgb(230, 230, 230);
|
||||
--grey-3-t: rgba(0, 0, 0, 0.2);
|
||||
--grey-3: rgb(205, 205, 205);
|
||||
--grey-4-t: rgba(0, 0, 0, 0.4);
|
||||
--grey-4: rgb(155, 155, 155);
|
||||
--grey-5-t: rgba(0, 0, 0, 0.7);
|
||||
--grey-5: rgb(75, 75, 75);
|
||||
--black: rgba(0, 0, 0, 0.9);
|
||||
|
||||
--bg: var(--grey-1);
|
||||
--fg: var(--black);
|
||||
|
||||
--interact: #3f9cff;
|
||||
--interact-lite: #3f9cff;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.sb-doc h1,
|
||||
.sb-doc h2,
|
||||
.sb-doc h3,
|
||||
.sb-doc h4,
|
||||
.sb-doc h5,
|
||||
.sb-doc h6 {
|
||||
position: relative;
|
||||
font-weight: 600;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.sb-doc h1 {
|
||||
letter-spacing: -0.02em;
|
||||
line-height: 40px;
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.sb-doc h2 {
|
||||
margin: 48px 0 16px;
|
||||
border-top: 1px solid var(--vp-c-divider-light);
|
||||
padding-top: 24px;
|
||||
letter-spacing: -0.02em;
|
||||
line-height: 32px;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.sb-doc h3 {
|
||||
margin: 32px 0 0;
|
||||
letter-spacing: -0.01em;
|
||||
line-height: 28px;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.sb-doc h1 {
|
||||
letter-spacing: -0.02em;
|
||||
line-height: 40px;
|
||||
font-size: 32px;
|
||||
}
|
||||
}
|
21
docs/main.ts
Normal file
21
docs/main.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { createApp } from 'vue'
|
||||
import { createRouter, createWebHistory } from 'vue-router';
|
||||
import routes from './routes';
|
||||
import App from './App';
|
||||
import './main.scss';
|
||||
|
||||
const router = createRouter({
|
||||
routes,
|
||||
history: createWebHistory(),
|
||||
scrollBehavior(to) {
|
||||
if (to.hash) {
|
||||
return { el: to.hash };
|
||||
}
|
||||
|
||||
return { top: 0 };
|
||||
}
|
||||
});
|
||||
|
||||
const app = createApp(App);
|
||||
app.use(router);
|
||||
app.mount('#app');
|
8
docs/try.md
Normal file
8
docs/try.md
Normal file
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
layout: page
|
||||
---
|
||||
<script setup>
|
||||
import ExampleEditor from './ExampleEditor';
|
||||
</script>
|
||||
|
||||
<ExampleEditor></ExampleEditor>
|
1
docs/usage.md
Normal file
1
docs/usage.md
Normal file
|
@ -0,0 +1 @@
|
|||
# Usage
|
81
docs/why.md
Normal file
81
docs/why.md
Normal file
|
@ -0,0 +1,81 @@
|
|||
# Why Schlechtenburg?
|
||||
|
||||
Installing a WYSIWYG editor in your application or on your website is often the easy part. The hard
|
||||
part comes afterwards: extending and customizing the editor to fit your specific needs. There are
|
||||
currently a couple of very good editors, but after reading this text I think you'll agree there's
|
||||
still room for improvement. We'll be looking at the following alternative WYSIWYG editors:
|
||||
|
||||
* [Quill](https://quilljs.com/)
|
||||
* [CKEditor](https://ckeditor.com/ckeditor-5/)
|
||||
* [Gutenberg](https://wordpress.org/gutenberg/)
|
||||
|
||||
## Block based
|
||||
|
||||
Though all three are meant for text editing, Quill and CKEditor are a bit more explicit about this
|
||||
in their architecture:
|
||||
|
||||
* They input and output a string
|
||||
* They have one global toolbar
|
||||
|
||||
Gutenberg is a bit more involved, literally using building "blocks" to create its editor. Instead
|
||||
of seeing the content as a long string it takes a more component-esque approach. For example, the
|
||||
following things are all their own blocks in the gutenberg editor, which a specific react component
|
||||
that handles the editing mode, and one that handles the display mode:
|
||||
|
||||
* Paragraph
|
||||
* Heading
|
||||
* List
|
||||
* Image
|
||||
* Column-based layout
|
||||
* External media embeds like YouTube videos
|
||||
|
||||
When editing, you are editing, adding or removing one specific block at a time. Blocks can contain
|
||||
other blocks in a tree structure, and they all have their own (but uniform) editing UI.
|
||||
|
||||
Schlechtenburg takes a block based approach, just like its namesake Gutenberg. This has a couple of advantages:
|
||||
|
||||
* You can take strong control over the final rendered HTML of a block that you create
|
||||
* Blocks are easily published as reusable JS modules
|
||||
* You very rarely need blocks inside text, but the reverse has abundant usecases
|
||||
* The mental model is closer to how actual HTML works
|
||||
* Very complex pages can be handled by the editor
|
||||
* If you know React or Vue, you understand a lot about how to write blocks for the editor
|
||||
|
||||
## Design system with standardized components
|
||||
|
||||
Making sure the final rendered data looks correct is always easier than making sure the editing
|
||||
experience is great. Schlechtenburg aims to offer a vast library of reusable components, patterns,
|
||||
variables, and rules for the editing UI. We call this **SBUI**. Complex blocks require complex editing forms and UIs so
|
||||
most of the work goes into creating this UI. A good Design System should help ease the pain.
|
||||
|
||||
## Accessible
|
||||
|
||||
Toolbars and editing elements are in the correct tab order, **SBUI** elements are all fully
|
||||
accessible.
|
||||
|
||||
## JSON only
|
||||
|
||||
Input and Output is one standardized, typed, JSON-stringifyable object. For example, a paragraph
|
||||
looks like this:
|
||||
|
||||
```
|
||||
{
|
||||
id: '1590592116800',
|
||||
name: 'sb-paragraph',
|
||||
data: {
|
||||
value: 'This is the second paragraph<br>',
|
||||
align: 'left'
|
||||
}
|
||||
},
|
||||
```
|
||||
|
||||
The main advantage here is that it enables you to write your own tooling around the format, since
|
||||
you don't have to deal with HTML or the DOM directly. This also enables really easy subtree rendering,
|
||||
by just taking that subtree of the JSON and feeding it to a Schlechtenburg instance. if instead of
|
||||
rendering a full page you'd only want to render the images, you could find all of the `sb-image` nodes
|
||||
in the tree and rendering them all inside an `sb-layout` block.
|
||||
|
||||
## So why not Gutenberg?
|
||||
|
||||
Gutenberg is tied heavily into the Wordpress ecosystem, making its inclusion in other sites harder
|
||||
than necessary.
|
116
flake.lock
Normal file
116
flake.lock
Normal file
|
@ -0,0 +1,116 @@
|
|||
{
|
||||
"nodes": {
|
||||
"devshell": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1713195852,
|
||||
"narHash": "sha256-MEb4Hx/Aw7pcsmcHXBuldFsrVTfl9Q9dz1JSlxUanmE=",
|
||||
"owner": "numtide",
|
||||
"repo": "devshell",
|
||||
"rev": "2c8e04e5c29299bec53c2e5a73da0f9afa8dabb5",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "devshell",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1701680307,
|
||||
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils_2": {
|
||||
"inputs": {
|
||||
"systems": "systems_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1710146030,
|
||||
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1728018373,
|
||||
"narHash": "sha256-NOiTvBbRLIOe5F6RbHaAh6++BNjsb149fGZd1T4+KBg=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "bc947f541ae55e999ffdb4013441347d83b00feb",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"devshell": "devshell",
|
||||
"flake-utils": "flake-utils_2",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems_2": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
34
flake.nix
Normal file
34
flake.nix
Normal file
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
description = "Schlechtenburg";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
|
||||
devshell.url = "github:numtide/devshell";
|
||||
devshell.inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
outputs = { self, flake-utils, devshell, nixpkgs }:
|
||||
flake-utils.lib.simpleFlake {
|
||||
inherit self nixpkgs;
|
||||
name = "schlechtenburg";
|
||||
preOverlays = [ devshell.overlays.default ];
|
||||
shell = { pkgs }: pkgs.devshell.mkShell {
|
||||
devshell.packages = with pkgs; [
|
||||
nodejs
|
||||
nodePackages.typescript
|
||||
nodePackages.typescript-language-server
|
||||
nodePackages.vue-language-server
|
||||
playwright
|
||||
];
|
||||
|
||||
env = [
|
||||
{ name = "PLAYWRIGHT_NODEJS_PATH"; value = "${pkgs.nodejs}/bin/node"; }
|
||||
{ name = "PLAYWRIGHT_BROWSERS_PATH"; value = "${pkgs.playwright-driver.browsers}"; }
|
||||
{ name = "PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS"; value = "true"; }
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
13
index.html
13
index.html
|
@ -1,13 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Vite App</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -2,5 +2,6 @@
|
|||
"packages": [
|
||||
"packages/*"
|
||||
],
|
||||
"version": "0.0.0"
|
||||
"version": "0.0.0",
|
||||
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
|
||||
}
|
||||
|
|
4
notes.md
Normal file
4
notes.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
## Events & type safety
|
||||
|
||||
To maintain full type safety, we're not using events via $emit, instead relying on callback
|
||||
functions handed in by the parent.
|
21461
package-lock.json
generated
21461
package-lock.json
generated
File diff suppressed because it is too large
Load diff
48
package.json
48
package.json
|
@ -1,22 +1,40 @@
|
|||
{
|
||||
"name": "schlechtenburg",
|
||||
"version": "0.0.0",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vuedx-typecheck . && vite build"
|
||||
},
|
||||
"dependencies": {
|
||||
"lodash-es": "^4.17.20",
|
||||
"vue": "^3.0.4"
|
||||
"docs:type:build": "npx typedoc --json ./docs/api.json --entryPointStrategy packages --readme none packages/core packages/heading packages/standalone packages/paragraph packages/layout packages/image",
|
||||
"typecheck": "lerna run --stream typecheck",
|
||||
"docs:dev": "vitepress dev docs",
|
||||
"docs:build": "vitepress build docs",
|
||||
"docs:serve": "vitepress serve docs",
|
||||
"test:browser": "vitest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vue/compiler-sfc": "^3.0.4",
|
||||
"@vuedx/typecheck": "^0.3.1-insiders-1606311019.0",
|
||||
"@vuedx/typescript-plugin-vue": "^0.3.1-insiders-1606311019.0",
|
||||
"lerna": "^3.22.1",
|
||||
"sass": "^1.30.0",
|
||||
"typescript": "^4.1.2",
|
||||
"vite": "^1.0.0-rc.13"
|
||||
}
|
||||
"@types/jsdom": "^21.1.7",
|
||||
"@vitejs/plugin-vue": "^5.1.4",
|
||||
"@vitejs/plugin-vue-jsx": "^3.1.0",
|
||||
"@vitest/browser": "^2.1.2",
|
||||
"@vue/test-utils": "^2.4.6",
|
||||
"deep-freeze": "^0.0.1",
|
||||
"lerna": "^8.1.8",
|
||||
"sass": "^1.75.0",
|
||||
"typedoc": "^0.26.7",
|
||||
"typescript": "^5.6.2",
|
||||
"vitepress": "^1.3.4",
|
||||
"vitest": "^2.1.2",
|
||||
"vitest-browser-vue": "^0.0.1",
|
||||
"vue": "^3.5.10"
|
||||
},
|
||||
"dependencies": {
|
||||
"lodash-es": "^4.17.21"
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/core",
|
||||
"packages/heading",
|
||||
"packages/image",
|
||||
"packages/paragraph",
|
||||
"packages/layout",
|
||||
"packages/rich-text"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
const core = require('..');
|
||||
|
||||
describe('@schlechtenburg/core', () => {
|
||||
it('needs tests');
|
||||
});
|
33
packages/core/__tests__/core.test.ts
Normal file
33
packages/core/__tests__/core.test.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
import { describe, expect, it } from 'vitest'
|
||||
import { withSetup } from '../../../test';
|
||||
import { useActivation } from '..';
|
||||
|
||||
describe('@schlechtenburg/core', () => {
|
||||
const a = 'a';
|
||||
const b = 'b';
|
||||
|
||||
it('Should activate', async () => {
|
||||
const {
|
||||
activeBlockId,
|
||||
isActive,
|
||||
activate,
|
||||
deactivate,
|
||||
} = await withSetup(() => useActivation(a));
|
||||
|
||||
activate(a);
|
||||
expect(activeBlockId.value).toBe(a);
|
||||
expect(isActive.value).toBeTruthy();
|
||||
|
||||
activate(b);
|
||||
expect(activeBlockId.value).toBe(b);
|
||||
expect(isActive.value).toBeFalsy();
|
||||
|
||||
deactivate(activeBlockId.value);
|
||||
expect(isActive.value).toBeFalsy();
|
||||
expect(activeBlockId.value).toBe(null);
|
||||
|
||||
activate();
|
||||
expect(activeBlockId.value).toBe(a);
|
||||
expect(isActive.value).toBeTruthy();
|
||||
});
|
||||
});
|
298
packages/core/docs/components.json
Normal file
298
packages/core/docs/components.json
Normal file
|
@ -0,0 +1,298 @@
|
|||
[
|
||||
{
|
||||
"displayName": "sb-block",
|
||||
"description": "Displays a Schlechtenburg block either the mode of the schlechtenburg instance.\nYou can use this to display child blocks inside your own blocks.",
|
||||
"tags": {},
|
||||
"exportName": "SbBlock",
|
||||
"props": [
|
||||
{
|
||||
"name": "block",
|
||||
"description": "The state for the block.",
|
||||
"type": {
|
||||
"name": "IBlockData<any>"
|
||||
},
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "onUpdate",
|
||||
"description": "Called when the block should be updated.",
|
||||
"type": {
|
||||
"name": "OnUpdateBlockCb"
|
||||
},
|
||||
"defaultValue": {
|
||||
"func": true,
|
||||
"value": "() => {}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "onPrependBlock",
|
||||
"description": "Called when a sibling block should be inserted before the block",
|
||||
"type": {
|
||||
"name": "OnPrependBlockCb"
|
||||
},
|
||||
"defaultValue": {
|
||||
"func": true,
|
||||
"value": "() => {}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "onAppendBlock",
|
||||
"description": "Called when a sibling block should be inserted after the block",
|
||||
"type": {
|
||||
"name": "OnAppendBlockCb"
|
||||
},
|
||||
"defaultValue": {
|
||||
"func": true,
|
||||
"value": "() => {}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "onRemoveSelf",
|
||||
"description": "Called when the block should be removed",
|
||||
"type": {
|
||||
"name": "OnRemoveSelfCb"
|
||||
},
|
||||
"defaultValue": {
|
||||
"func": true,
|
||||
"value": "() => {}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "onActivatePrevious",
|
||||
"description": "Called when the previous sibling block should be activated",
|
||||
"type": {
|
||||
"name": "OnActivatePreviousCb"
|
||||
},
|
||||
"defaultValue": {
|
||||
"func": true,
|
||||
"value": "() => {}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "onActivateNext",
|
||||
"description": "Called when the next sibling block should be activated",
|
||||
"type": {
|
||||
"name": "OnActivateNextCb"
|
||||
},
|
||||
"defaultValue": {
|
||||
"func": true,
|
||||
"value": "() => {}"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"displayName": "sb-block-ordering",
|
||||
"exportName": "SbBlockOrdering",
|
||||
"description": "",
|
||||
"tags": {},
|
||||
"props": [
|
||||
{
|
||||
"name": "orientation",
|
||||
"type": {
|
||||
"name": "string"
|
||||
},
|
||||
"defaultValue": {
|
||||
"func": false,
|
||||
"value": "null"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "onRemove",
|
||||
"type": {
|
||||
"name": "func"
|
||||
},
|
||||
"defaultValue": {
|
||||
"func": true,
|
||||
"value": "() => {}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "onMoveBackward",
|
||||
"type": {
|
||||
"name": "func"
|
||||
},
|
||||
"defaultValue": {
|
||||
"func": true,
|
||||
"value": "() => {}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "onMoveForward",
|
||||
"type": {
|
||||
"name": "func"
|
||||
},
|
||||
"defaultValue": {
|
||||
"func": true,
|
||||
"value": "() => {}"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"displayName": "sb-block-picker",
|
||||
"exportName": "SbBlockPicker",
|
||||
"description": "",
|
||||
"tags": {},
|
||||
"props": [
|
||||
{
|
||||
"name": "onPickedBlock",
|
||||
"type": {
|
||||
"name": "func"
|
||||
},
|
||||
"defaultValue": {
|
||||
"func": true,
|
||||
"value": "() => {}"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"displayName": "sb-block-placeholder",
|
||||
"description": "A placeholder for a block.\nDisplays a placeholder for a block, allowing the user to select a block to insert.",
|
||||
"tags": {
|
||||
"sbui": [
|
||||
{
|
||||
"description": true,
|
||||
"title": "sbui"
|
||||
}
|
||||
]
|
||||
},
|
||||
"exportName": "SbBlockPlaceholder",
|
||||
"props": [
|
||||
{
|
||||
"name": "onInsertBlock",
|
||||
"description": "Called when the user picked a block that should be inserted here.",
|
||||
"type": {
|
||||
"name": "func"
|
||||
},
|
||||
"defaultValue": {
|
||||
"func": true,
|
||||
"value": "() => {}"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"displayName": "sb-block-toolbar",
|
||||
"exportName": "SbBlockToolbar",
|
||||
"description": "",
|
||||
"tags": {}
|
||||
},
|
||||
{
|
||||
"displayName": "sb-button",
|
||||
"description": "A button in the schlechtenburg theme",
|
||||
"tags": {
|
||||
"sbui": [
|
||||
{
|
||||
"description": true,
|
||||
"title": "sbui"
|
||||
}
|
||||
]
|
||||
},
|
||||
"exportName": "SbButton"
|
||||
},
|
||||
{
|
||||
"displayName": "sb-context-menu",
|
||||
"exportName": "SbContextMenu",
|
||||
"description": "",
|
||||
"tags": {},
|
||||
"props": [
|
||||
{
|
||||
"name": "onClose",
|
||||
"type": {
|
||||
"name": "func"
|
||||
},
|
||||
"defaultValue": {
|
||||
"func": true,
|
||||
"value": "() => {}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "onOpen",
|
||||
"type": {
|
||||
"name": "func"
|
||||
},
|
||||
"defaultValue": {
|
||||
"func": true,
|
||||
"value": "() => {}"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"displayName": "sb-main-menu",
|
||||
"exportName": "SbMainMenu",
|
||||
"description": "",
|
||||
"tags": {},
|
||||
"props": [
|
||||
{
|
||||
"name": "block",
|
||||
"type": {
|
||||
"name": "IBlockData<any>"
|
||||
},
|
||||
"required": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"displayName": "sb-modal",
|
||||
"exportName": "SbModal",
|
||||
"description": "",
|
||||
"tags": {},
|
||||
"props": [
|
||||
{
|
||||
"name": "open",
|
||||
"type": {
|
||||
"name": "boolean"
|
||||
},
|
||||
"defaultValue": {
|
||||
"func": false,
|
||||
"value": "false"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "onClose",
|
||||
"type": {
|
||||
"name": "func"
|
||||
},
|
||||
"defaultValue": {
|
||||
"func": true,
|
||||
"value": "() => {}"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"displayName": "sb-select",
|
||||
"description": "A select input in the schlechtenburg theme",
|
||||
"tags": {
|
||||
"sbui": [
|
||||
{
|
||||
"description": true,
|
||||
"title": "sbui"
|
||||
}
|
||||
]
|
||||
},
|
||||
"exportName": "SbSelect"
|
||||
},
|
||||
{
|
||||
"displayName": "sb-toolbar",
|
||||
"description": "Toolbar in the schlechtenburg theme",
|
||||
"tags": {
|
||||
"sbui": [
|
||||
{
|
||||
"description": true,
|
||||
"title": "sbui"
|
||||
}
|
||||
]
|
||||
},
|
||||
"exportName": "SbToolbar"
|
||||
},
|
||||
{
|
||||
"displayName": "sb-main-menu",
|
||||
"exportName": "SbTreeBlockSelect",
|
||||
"description": "",
|
||||
"tags": {}
|
||||
}
|
||||
]
|
6903
packages/core/docs/lib.json
Normal file
6903
packages/core/docs/lib.json
Normal file
File diff suppressed because it is too large
Load diff
242
packages/core/lib/ResizeObserver.d.ts
vendored
242
packages/core/lib/ResizeObserver.d.ts
vendored
|
@ -1,242 +0,0 @@
|
|||
/**
|
||||
* The **ResizeObserver** interface reports changes to the dimensions of an
|
||||
* [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element)'s content
|
||||
* or border box, or the bounding box of an
|
||||
* [SVGElement](https://developer.mozilla.org/en-US/docs/Web/API/SVGElement).
|
||||
*
|
||||
* > **Note**: The content box is the box in which content can be placed,
|
||||
* > meaning the border box minus the padding and border width. The border box
|
||||
* > encompasses the content, padding, and border. See
|
||||
* > [The box model](https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model)
|
||||
* > for further explanation.
|
||||
*
|
||||
* `ResizeObserver` avoids infinite callback loops and cyclic dependencies that
|
||||
* are often created when resizing via a callback function. It does this by only
|
||||
* processing elements deeper in the DOM in subsequent frames. Implementations
|
||||
* should, if they follow the specification, invoke resize events before paint
|
||||
* and after layout.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver
|
||||
*/
|
||||
declare class ResizeObserver {
|
||||
/**
|
||||
* The **ResizeObserver** constructor creates a new `ResizeObserver` object,
|
||||
* which can be used to report changes to the content or border box of an
|
||||
* `Element` or the bounding box of an `SVGElement`.
|
||||
*
|
||||
* @example
|
||||
* var ResizeObserver = new ResizeObserver(callback)
|
||||
*
|
||||
* @param callback
|
||||
* The function called whenever an observed resize occurs. The function is
|
||||
* called with two parameters:
|
||||
* * **entries**
|
||||
* An array of
|
||||
* [ResizeObserverEntry](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry)
|
||||
* objects that can be used to access the new dimensions of the element
|
||||
* after each change.
|
||||
* * **observer**
|
||||
* A reference to the `ResizeObserver` itself, so it will definitely be
|
||||
* accessible from inside the callback, should you need it. This could be
|
||||
* used for example to automatically unobserve the observer when a certain
|
||||
* condition is reached, but you can omit it if you don't need it.
|
||||
*
|
||||
* The callback will generally follow a pattern along the lines of:
|
||||
* ```js
|
||||
* function(entries, observer) {
|
||||
* for (let entry of entries) {
|
||||
* // Do something to each entry
|
||||
* // and possibly something to the observer itself
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* The following snippet is taken from the
|
||||
* [resize-observer-text.html](https://mdn.github.io/dom-examples/resize-observer/resize-observer-text.html)
|
||||
* ([see source](https://github.com/mdn/dom-examples/blob/master/resize-observer/resize-observer-text.html))
|
||||
* example:
|
||||
* @example
|
||||
* const resizeObserver = new ResizeObserver(entries => {
|
||||
* for (let entry of entries) {
|
||||
* if(entry.contentBoxSize) {
|
||||
* h1Elem.style.fontSize = Math.max(1.5, entry.contentBoxSize.inlineSize/200) + 'rem';
|
||||
* pElem.style.fontSize = Math.max(1, entry.contentBoxSize.inlineSize/600) + 'rem';
|
||||
* } else {
|
||||
* h1Elem.style.fontSize = Math.max(1.5, entry.contentRect.width/200) + 'rem';
|
||||
* pElem.style.fontSize = Math.max(1, entry.contentRect.width/600) + 'rem';
|
||||
* }
|
||||
* }
|
||||
* });
|
||||
*
|
||||
* resizeObserver.observe(divElem);
|
||||
*/
|
||||
constructor(callback: ResizeObserverCallback);
|
||||
|
||||
/**
|
||||
* The **disconnect()** method of the
|
||||
* [ResizeObserver](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)
|
||||
* interface unobserves all observed
|
||||
* [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) or
|
||||
* [SVGElement](https://developer.mozilla.org/en-US/docs/Web/API/SVGElement)
|
||||
* targets.
|
||||
*/
|
||||
disconnect: () => void;
|
||||
|
||||
/**
|
||||
* The `observe()` method of the
|
||||
* [ResizeObserver](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)
|
||||
* interface starts observing the specified
|
||||
* [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) or
|
||||
* [SVGElement](https://developer.mozilla.org/en-US/docs/Web/API/SVGElement).
|
||||
*
|
||||
* @example
|
||||
* resizeObserver.observe(target, options);
|
||||
*
|
||||
* @param target
|
||||
* A reference to an
|
||||
* [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) or
|
||||
* [SVGElement](https://developer.mozilla.org/en-US/docs/Web/API/SVGElement)
|
||||
* to be observed.
|
||||
*
|
||||
* @param options
|
||||
* An options object allowing you to set options for the observation.
|
||||
* Currently this only has one possible option that can be set.
|
||||
*/
|
||||
observe: (target: Element, options?: ResizeObserverObserveOptions) => void;
|
||||
|
||||
/**
|
||||
* The **unobserve()** method of the
|
||||
* [ResizeObserver](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)
|
||||
* interface ends the observing of a specified
|
||||
* [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) or
|
||||
* [SVGElement](https://developer.mozilla.org/en-US/docs/Web/API/SVGElement).
|
||||
*/
|
||||
unobserve: (target: Element) => void;
|
||||
}
|
||||
|
||||
interface ResizeObserverObserveOptions {
|
||||
/**
|
||||
* Sets which box model the observer will observe changes to. Possible values
|
||||
* are `content-box` (the default), and `border-box`.
|
||||
*
|
||||
* @default "content-box"
|
||||
*/
|
||||
box?: "content-box" | "border-box";
|
||||
}
|
||||
|
||||
/**
|
||||
* The function called whenever an observed resize occurs. The function is
|
||||
* called with two parameters:
|
||||
*
|
||||
* @param entries
|
||||
* An array of
|
||||
* [ResizeObserverEntry](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry)
|
||||
* objects that can be used to access the new dimensions of the element after
|
||||
* each change.
|
||||
*
|
||||
* @param observer
|
||||
* A reference to the `ResizeObserver` itself, so it will definitely be
|
||||
* accessible from inside the callback, should you need it. This could be used
|
||||
* for example to automatically unobserve the observer when a certain condition
|
||||
* is reached, but you can omit it if you don't need it.
|
||||
*
|
||||
* The callback will generally follow a pattern along the lines of:
|
||||
* @example
|
||||
* function(entries, observer) {
|
||||
* for (let entry of entries) {
|
||||
* // Do something to each entry
|
||||
* // and possibly something to the observer itself
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @example
|
||||
* const resizeObserver = new ResizeObserver(entries => {
|
||||
* for (let entry of entries) {
|
||||
* if(entry.contentBoxSize) {
|
||||
* h1Elem.style.fontSize = Math.max(1.5, entry.contentBoxSize.inlineSize/200) + 'rem';
|
||||
* pElem.style.fontSize = Math.max(1, entry.contentBoxSize.inlineSize/600) + 'rem';
|
||||
* } else {
|
||||
* h1Elem.style.fontSize = Math.max(1.5, entry.contentRect.width/200) + 'rem';
|
||||
* pElem.style.fontSize = Math.max(1, entry.contentRect.width/600) + 'rem';
|
||||
* }
|
||||
* }
|
||||
* });
|
||||
*
|
||||
* resizeObserver.observe(divElem);
|
||||
*/
|
||||
type ResizeObserverCallback = (
|
||||
entries: ResizeObserverEntry[],
|
||||
observer: ResizeObserver,
|
||||
) => void;
|
||||
|
||||
/**
|
||||
* The **ResizeObserverEntry** interface represents the object passed to the
|
||||
* [ResizeObserver()](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver)
|
||||
* constructor's callback function, which allows you to access the new
|
||||
* dimensions of the
|
||||
* [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) or
|
||||
* [SVGElement](https://developer.mozilla.org/en-US/docs/Web/API/SVGElement)
|
||||
* being observed.
|
||||
*/
|
||||
interface ResizeObserverEntry {
|
||||
/**
|
||||
* An object containing the new border box size of the observed element when
|
||||
* the callback is run.
|
||||
*/
|
||||
readonly borderBoxSize: ResizeObserverEntryBoxSize;
|
||||
|
||||
/**
|
||||
* An object containing the new content box size of the observed element when
|
||||
* the callback is run.
|
||||
*/
|
||||
readonly contentBoxSize: ResizeObserverEntryBoxSize;
|
||||
|
||||
/**
|
||||
* A [DOMRectReadOnly](https://developer.mozilla.org/en-US/docs/Web/API/DOMRectReadOnly)
|
||||
* object containing the new size of the observed element when the callback is
|
||||
* run. Note that this is better supported than the above two properties, but
|
||||
* it is left over from an earlier implementation of the Resize Observer API,
|
||||
* is still included in the spec for web compat reasons, and may be deprecated
|
||||
* in future versions.
|
||||
*/
|
||||
// node_modules/typescript/lib/lib.dom.d.ts
|
||||
readonly contentRect: DOMRectReadOnly;
|
||||
|
||||
/**
|
||||
* A reference to the
|
||||
* [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) or
|
||||
* [SVGElement](https://developer.mozilla.org/en-US/docs/Web/API/SVGElement)
|
||||
* being observed.
|
||||
*/
|
||||
readonly target: Element;
|
||||
}
|
||||
|
||||
/**
|
||||
* The **borderBoxSize** read-only property of the
|
||||
* [ResizeObserverEntry](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry)
|
||||
* interface returns an object containing the new border box size of the
|
||||
* observed element when the callback is run.
|
||||
*/
|
||||
interface ResizeObserverEntryBoxSize {
|
||||
/**
|
||||
* The length of the observed element's border box in the block dimension. For
|
||||
* boxes with a horizontal
|
||||
* [writing-mode](https://developer.mozilla.org/en-US/docs/Web/CSS/writing-mode),
|
||||
* this is the vertical dimension, or height; if the writing-mode is vertical,
|
||||
* this is the horizontal dimension, or width.
|
||||
*/
|
||||
blockSize: number;
|
||||
|
||||
/**
|
||||
* The length of the observed element's border box in the inline dimension.
|
||||
* For boxes with a horizontal
|
||||
* [writing-mode](https://developer.mozilla.org/en-US/docs/Web/CSS/writing-mode),
|
||||
* this is the horizontal dimension, or width; if the writing-mode is
|
||||
* vertical, this is the vertical dimension, or height.
|
||||
*/
|
||||
inlineSize: number;
|
||||
}
|
||||
|
||||
interface Window {
|
||||
ResizeObserver: typeof ResizeObserver;
|
||||
}
|
15
packages/core/lib/block-helpers.ts
Normal file
15
packages/core/lib/block-helpers.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
export const generateBlockId = uuidv4;
|
||||
|
||||
export const model = {
|
||||
prop: 'block',
|
||||
event: 'update',
|
||||
};
|
||||
|
||||
export const blockProps = {
|
||||
blockId: {
|
||||
type: String,
|
||||
default: generateBlockId,
|
||||
},
|
||||
};
|
|
@ -1,34 +0,0 @@
|
|||
import { Component } from 'vue';
|
||||
|
||||
export interface BlockDefinition {
|
||||
name: string;
|
||||
getDefaultData: any;
|
||||
edit: Component;
|
||||
display: Component;
|
||||
}
|
||||
|
||||
export interface BlockLibraryDefinition {
|
||||
[name: string]: BlockDefinition;
|
||||
}
|
||||
|
||||
export interface BlockProps<T> {
|
||||
blockId: string;
|
||||
data: T;
|
||||
}
|
||||
|
||||
export interface Block<T> extends BlockProps<T> {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export const model = {
|
||||
prop: 'block',
|
||||
event: 'update',
|
||||
};
|
||||
|
||||
export const blockProps = {
|
||||
blockId: {
|
||||
type: String,
|
||||
default: () => `${+(new Date())}`,
|
||||
},
|
||||
data: { type: Object, default: () => ({}) },
|
||||
};
|
|
@ -5,22 +5,23 @@
|
|||
align-items: stretch;
|
||||
justify-items: stretch;
|
||||
height: auto;
|
||||
min-width: 32px;
|
||||
min-height: 32px;
|
||||
|
||||
> * > .sb-toolbar {
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
&__edit-cover {
|
||||
}
|
||||
|
||||
> .sb-block-ordering {
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
&_active {
|
||||
outline: 1px solid var(--grey-2);
|
||||
&_active,
|
||||
&_active:hover {
|
||||
z-index: 1;
|
||||
outline: 4px solid var(--interact);
|
||||
|
||||
> * > .sb-toolbar {
|
||||
opacity: 1;
|
||||
|
@ -33,4 +34,8 @@
|
|||
pointer-events: all;
|
||||
}
|
||||
}
|
||||
|
||||
&_highlighted {
|
||||
outline: 2px solid var(--interact);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,61 +6,116 @@ import {
|
|||
ref,
|
||||
Ref,
|
||||
} from 'vue';
|
||||
import { Block } from '../blocks';
|
||||
import {
|
||||
IBlockData,
|
||||
OnUpdateBlockCb,
|
||||
OnActivateNextCb,
|
||||
OnRemoveSelfCb,
|
||||
OnAppendBlockCb,
|
||||
OnPrependBlockCb,
|
||||
OnActivatePreviousCb,
|
||||
} from '../types';
|
||||
import { SbMode } from '../mode';
|
||||
import { useResizeObserver, BlockDimensions } from '../use-resize-observer';
|
||||
import { useResizeObserver, SymBlockDimensions } from '../use-resize-observer';
|
||||
import { useActivation } from '../use-activation';
|
||||
import { useBlockTree } from '../use-block-tree';
|
||||
import { useDynamicBlocks } from '../use-dynamic-blocks';
|
||||
import hoverCover from '../directives/hover-cover';
|
||||
|
||||
import { SbBlockOrdering } from './BlockOrdering';
|
||||
import SbMissingBlock from './BlockMissing/index';
|
||||
import SbMissingBlock from './MissingBlock';
|
||||
|
||||
import './Block.scss';
|
||||
|
||||
interface BlockProps {
|
||||
block: Block;
|
||||
eventUpdate: (b?: Block) => void;
|
||||
eventPrependBlock: (b?: Block) => void;
|
||||
eventAppendBlock: (b?: Block) => void;
|
||||
eventRemoveBlock: () => void;
|
||||
eventMoveUp: () => void;
|
||||
eventMoveDown: () => void;
|
||||
sortable: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a Schlechtenburg block either the mode of the schlechtenburg instance.
|
||||
* You can use this to display child blocks inside your own blocks.
|
||||
*/
|
||||
export const SbBlock = defineComponent({
|
||||
name: 'sb-block',
|
||||
|
||||
props: {
|
||||
block: {
|
||||
type: (null as unknown) as PropType<Block>,
|
||||
required: true,
|
||||
},
|
||||
sortable: {
|
||||
type: String,
|
||||
default: null,
|
||||
},
|
||||
eventUpdate: { type: Function, default: () => {} },
|
||||
eventPrependBlock: { type: Function, default: () => {} },
|
||||
eventAppendBlock: { type: Function, default: () => {} },
|
||||
eventRemoveBlock: { type: Function, default: () => {} },
|
||||
eventMoveUp: { type: Function, default: () => {} },
|
||||
eventMoveDown: { type: Function, default: () => {} },
|
||||
directives: {
|
||||
hoverCover,
|
||||
},
|
||||
|
||||
setup(props: BlockProps, context) {
|
||||
props: {
|
||||
/**
|
||||
* The state for the block.
|
||||
*/
|
||||
block: {
|
||||
type: (null as unknown) as PropType<IBlockData<any>>,
|
||||
required: true,
|
||||
},
|
||||
/**
|
||||
* The state for the block.
|
||||
*/
|
||||
indexAsChild: {
|
||||
type: Number,
|
||||
default: -1,
|
||||
},
|
||||
/**
|
||||
* Called when the block should be updated.
|
||||
*/
|
||||
eventUpdate: {
|
||||
type: (null as unknown) as PropType<OnUpdateBlockCb>,
|
||||
default: () => () => {},
|
||||
},
|
||||
/**
|
||||
* Called when a sibling block should be inserted before the block
|
||||
*/
|
||||
eventPrependBlock: {
|
||||
type: (null as unknown) as PropType<OnPrependBlockCb>,
|
||||
default: () => () => {},
|
||||
},
|
||||
/**
|
||||
* Called when a sibling block should be inserted after the block
|
||||
*/
|
||||
eventAppendBlock: {
|
||||
type: (null as unknown) as PropType<OnAppendBlockCb>,
|
||||
default: () => () => {},
|
||||
},
|
||||
/**
|
||||
* Called when the block should be removed
|
||||
*/
|
||||
eventRemoveSelf: {
|
||||
type: (null as unknown) as PropType<OnRemoveSelfCb>,
|
||||
default: () => () => {},
|
||||
},
|
||||
/**
|
||||
* Called when the previous sibling block should be activated
|
||||
*/
|
||||
eventActivatePrevious: {
|
||||
type: (null as unknown) as PropType<OnActivatePreviousCb>,
|
||||
default: () => () => {},
|
||||
},
|
||||
/**
|
||||
* Called when the next sibling block should be activated
|
||||
*/
|
||||
eventActivateNext: {
|
||||
type: (null as unknown) as PropType<OnActivateNextCb>,
|
||||
default: () => () => {},
|
||||
},
|
||||
},
|
||||
|
||||
setup(props, context) {
|
||||
const el: Ref<null|HTMLElement> = ref(null);
|
||||
const { mode, getBlock } = useDynamicBlocks();
|
||||
const { isActive, activate } = useActivation(props.block.blockId);
|
||||
const {
|
||||
isActive,
|
||||
activate,
|
||||
} = useActivation(props.block.id);
|
||||
const classes = computed(() => ({
|
||||
'sb-block': true,
|
||||
'sb-block_active': isActive.value,
|
||||
}));
|
||||
|
||||
const { triggerSizeCalculation } = useResizeObserver(el, BlockDimensions);
|
||||
const { triggerSizeCalculation } = useResizeObserver(el, SymBlockDimensions);
|
||||
watch(() => props.block.data, triggerSizeCalculation);
|
||||
|
||||
const onChildUpdate = (updated: {[key: string]: any}) => {
|
||||
const { register } = useBlockTree();
|
||||
register(props.block, props.indexAsChild);
|
||||
watch(props.block, () => { register(props.block, props.indexAsChild); });
|
||||
|
||||
const eventChildUpdate = (updated: {[key: string]: any}) => {
|
||||
props.eventUpdate({
|
||||
...props.block,
|
||||
data: {
|
||||
|
@ -71,43 +126,52 @@ export const SbBlock = defineComponent({
|
|||
};
|
||||
|
||||
return () => {
|
||||
const BlockComponent = getBlock(props.block.name) as any;
|
||||
const BlockComponent = getBlock(props.block.name)?.[mode.value] as any;
|
||||
|
||||
if (!BlockComponent) {
|
||||
const MissingBlock = SbMissingBlock[mode.value];
|
||||
return <MissingBlock
|
||||
name={props.block.name}
|
||||
blockId={props.block.blockId}
|
||||
blockId={props.block.id}
|
||||
/>;
|
||||
}
|
||||
|
||||
if (mode.value === SbMode.Display) {
|
||||
return () => (
|
||||
<BlockComponent
|
||||
data={props.block.data}
|
||||
blockId={props.block.blockId}
|
||||
/>
|
||||
);
|
||||
if (mode.value === SbMode.View) {
|
||||
return <BlockComponent
|
||||
data={props.block.data}
|
||||
blockId={props.block.id}
|
||||
/>;
|
||||
}
|
||||
|
||||
return <div
|
||||
ref={el}
|
||||
class={classes.value}
|
||||
v-hover-cover
|
||||
>
|
||||
<div class="sb-block__edit-cover"></div>
|
||||
{context.slots['context-toolbar'] ? context.slots['context-toolbar']() : null}
|
||||
{
|
||||
/**
|
||||
* This is an alternative toolbar location that parent blocks can use to offer UI elements specific to child blocks.
|
||||
* @slot context-toolbar
|
||||
*/
|
||||
context.slots['context-toolbar'] ? context.slots['context-toolbar']() : null
|
||||
}
|
||||
<BlockComponent
|
||||
data={props.block.data}
|
||||
blockId={props.block.blockId}
|
||||
eventUpdate={onChildUpdate}
|
||||
blockId={props.block.id}
|
||||
eventUpdate={eventChildUpdate}
|
||||
eventPrependBlock={props.eventPrependBlock}
|
||||
eventAppendBlock={props.eventAppendBlock}
|
||||
eventRemoveBlock={props.eventRemoveBlock}
|
||||
onClick={($event: MouseEvent) => {
|
||||
$event.stopPropagation();
|
||||
activate();
|
||||
eventRemoveSelf={props.eventRemoveSelf}
|
||||
eventActivatePrevious={props.eventActivatePrevious}
|
||||
eventActivateNext={props.eventActivateNext}
|
||||
|
||||
{...{
|
||||
onClick: ($event: MouseEvent) => {
|
||||
$event.stopPropagation();
|
||||
activate();
|
||||
},
|
||||
...context.attrs,
|
||||
}}
|
||||
{...context.attrs}
|
||||
/>
|
||||
</div>;
|
||||
};
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
import { defineAsyncComponent } from 'vue';
|
||||
|
||||
export default {
|
||||
name: 'sb-missing-block',
|
||||
edit: defineAsyncComponent(() => import('./display')),
|
||||
display: defineAsyncComponent(() => import('./display')),
|
||||
};
|
|
@ -1,4 +1,4 @@
|
|||
import { debounce } from 'lodash-es';
|
||||
import debounce from 'lodash/debounce';
|
||||
import {
|
||||
watch,
|
||||
reactive,
|
||||
|
@ -15,13 +15,13 @@ export const SbBlockOrdering = defineComponent({
|
|||
name: 'sb-block-ordering',
|
||||
|
||||
props: {
|
||||
sortable: {
|
||||
orientation: {
|
||||
type: String,
|
||||
default: null,
|
||||
},
|
||||
eventRemoveBlock: { type: Function, default: () => {} },
|
||||
eventMoveUp: { type: Function, default: () => {} },
|
||||
eventMoveDown: { type: Function, default: () => {} },
|
||||
eventRemove: { type: Function, default: () => {} },
|
||||
eventMoveBackward: { type: Function, default: () => {} },
|
||||
eventMoveForward: { type: Function, default: () => {} },
|
||||
},
|
||||
|
||||
setup(props) {
|
||||
|
@ -32,7 +32,7 @@ export const SbBlockOrdering = defineComponent({
|
|||
|
||||
const classes = computed(() => ({
|
||||
'sb-block-ordering': true,
|
||||
[`sb-block-ordering_${props.sortable}`]: !!props.sortable,
|
||||
[`sb-block-ordering_${props.orientation}`]: !!props.orientation,
|
||||
}));
|
||||
|
||||
const { editorDimensions, blockDimensions } = useBlockSizing();
|
||||
|
@ -47,7 +47,7 @@ export const SbBlockOrdering = defineComponent({
|
|||
});
|
||||
watch(editorDimensions, resetStyles);
|
||||
watch(blockDimensions, resetStyles);
|
||||
watch(() => props.sortable, resetStyles);
|
||||
watch(() => props.orientation, resetStyles);
|
||||
|
||||
return () => (
|
||||
<div
|
||||
|
@ -55,9 +55,9 @@ export const SbBlockOrdering = defineComponent({
|
|||
style={styles}
|
||||
onClick={($event: MouseEvent) => $event.stopPropagation()}
|
||||
>
|
||||
<SbButton onClick={props.eventMoveUp}>{props.sortable === 'vertical' ? '↑' : '←'}</SbButton>
|
||||
<SbButton onClick={props.eventRemoveBlock}>x</SbButton>
|
||||
<SbButton onClick={props.eventMoveDown}>{props.sortable === 'vertical' ? '↓' : '→'}</SbButton>
|
||||
<SbButton {...{onClick: props.eventMoveBackward}}>{props.orientation === 'vertical' ? '↑' : '←'}</SbButton>
|
||||
<SbButton {...{onClick: props.eventRemove}}>x</SbButton>
|
||||
<SbButton {...{onClick: props.eventMoveForward}}>{props.orientation === 'vertical' ? '↓' : '→'}</SbButton>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
|
|
|
@ -1,10 +1,4 @@
|
|||
.sb-block-picker {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
|
||||
&__add-button {
|
||||
padding: 24px 32px;
|
||||
}
|
||||
|
|
|
@ -3,60 +3,58 @@ import {
|
|||
ref,
|
||||
defineComponent,
|
||||
} from 'vue';
|
||||
import {
|
||||
useDynamicBlocks,
|
||||
BlockDefinition,
|
||||
} from '../use-dynamic-blocks';
|
||||
import { useDynamicBlocks } from '../use-dynamic-blocks';
|
||||
import { IBlockDefinition } from '../types';
|
||||
import { generateBlockId } from '../block-helpers';
|
||||
|
||||
import { SbButton } from './Button';
|
||||
import { SbModal } from './Modal';
|
||||
import { SbContextMenu, IContextMenuSlotContext } from './ContextMenu';
|
||||
|
||||
import './BlockPicker.scss';
|
||||
|
||||
export const SbBlockPicker = defineComponent({
|
||||
name: 'sb-block-picker',
|
||||
|
||||
props: {},
|
||||
props: {
|
||||
eventPickedBlock: { type: Function, default: () => {} },
|
||||
},
|
||||
|
||||
setup(props, context) {
|
||||
const open = ref(false);
|
||||
|
||||
const { customBlocks } = useDynamicBlocks();
|
||||
|
||||
const blockList = computed(() => Object.keys(customBlocks).map((key) => customBlocks[key]));
|
||||
|
||||
const selectBlock = (block: BlockDefinition) => () => {
|
||||
const selectBlock = (block: IBlockDefinition<any>) => {
|
||||
open.value = false;
|
||||
context.emit('picked-block', {
|
||||
props.eventPickedBlock({
|
||||
name: block.name,
|
||||
blockId: `${+(new Date())}`,
|
||||
id: generateBlockId(),
|
||||
data: block.getDefaultData(),
|
||||
});
|
||||
};
|
||||
|
||||
return () => (
|
||||
<div class="sb-block-picker">
|
||||
<SbButton
|
||||
class="sb-block-picker__add-button"
|
||||
type="button"
|
||||
onClick={($event: MouseEvent) => {
|
||||
open.value = true;
|
||||
$event.stopPropagation();
|
||||
}}
|
||||
>Add a block</SbButton>
|
||||
<SbModal
|
||||
open={open.value}
|
||||
onClick={($event: MouseEvent) => $event.stopPropagation()}
|
||||
eventClose={() => {
|
||||
open.value = false;
|
||||
}}
|
||||
>
|
||||
{...blockList.value.map((block: BlockDefinition) => (
|
||||
<SbContextMenu
|
||||
class="sb-tree-block-select"
|
||||
v-slots={{
|
||||
context: (slotContext:IContextMenuSlotContext) => context.slots.context
|
||||
? context.slots.context(slotContext)
|
||||
: <SbButton {...{ onClick: slotContext.toggle }}>Insert a block</SbButton>,
|
||||
default: ({ close }: { close: Function }) => blockList.value.map((block: IBlockDefinition<any>) => (
|
||||
<SbButton
|
||||
type="button"
|
||||
onClick={selectBlock(block)}
|
||||
>{block.name}</SbButton>
|
||||
))}
|
||||
</SbModal>
|
||||
{...{
|
||||
type: 'button',
|
||||
onClick: () => {
|
||||
selectBlock(block);
|
||||
close();
|
||||
},
|
||||
}}
|
||||
>{block.name}</SbButton>)),
|
||||
}}
|
||||
></SbContextMenu>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
.sb-block-placeholder {
|
||||
width: 100%;
|
||||
flex-basis: 100%;
|
||||
flex-shrink: 2;
|
||||
position: relative;
|
||||
overflow: visible;
|
||||
|
||||
|
@ -7,4 +8,12 @@
|
|||
background-color: var(--grey-1);
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.sb-block-picker {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,30 @@
|
|||
import { defineComponent } from 'vue';
|
||||
import { BlockDefinition } from '../blocks';
|
||||
import { IBlockData } from '../types';
|
||||
|
||||
import { SbBlockPicker } from './BlockPicker';
|
||||
|
||||
import './BlockPlaceholder.scss';
|
||||
|
||||
/**
|
||||
* A placeholder for a block.
|
||||
* Displays a placeholder for a block, allowing the user to select a block to insert.
|
||||
* @sbui
|
||||
*/
|
||||
export const SbBlockPlaceholder = defineComponent({
|
||||
name: 'sb-block-placeholder',
|
||||
|
||||
setup(props, context) {
|
||||
props: {
|
||||
/**
|
||||
* Called when the user picked a block that should be inserted here.
|
||||
*/
|
||||
eventInsertBlock: { type: Function, default: () => {} },
|
||||
},
|
||||
|
||||
setup(props) {
|
||||
return () => (
|
||||
<div class="sb-block-placeholder">
|
||||
<SbBlockPicker
|
||||
onPickedBlock={(block: BlockDefinition) => context.emit('insert-block', block)}
|
||||
eventPickedBlock={(block: IBlockData<any>) => props.eventInsertBlock(block)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
|
0
packages/core/lib/components/BlockToolbar.scss
Normal file
0
packages/core/lib/components/BlockToolbar.scss
Normal file
13
packages/core/lib/components/BlockToolbar.tsx
Normal file
13
packages/core/lib/components/BlockToolbar.tsx
Normal file
|
@ -0,0 +1,13 @@
|
|||
import { defineComponent } from 'vue';
|
||||
|
||||
import './BlockToolbar.scss';
|
||||
|
||||
export const SbBlockToolbar = defineComponent({
|
||||
name: 'sb-block-toolbar',
|
||||
|
||||
setup() {
|
||||
return () => (
|
||||
<div class="sb-block-toolbar"></div>
|
||||
);
|
||||
},
|
||||
});
|
|
@ -2,12 +2,16 @@ import { defineComponent } from 'vue';
|
|||
|
||||
import './Button.scss';
|
||||
|
||||
/**
|
||||
* A button in the schlechtenburg theme
|
||||
* @sbui
|
||||
*/
|
||||
export const SbButton = defineComponent({
|
||||
name: 'sb-button',
|
||||
|
||||
inheritAttrs: false,
|
||||
|
||||
setup(props, context) {
|
||||
setup(_, context) {
|
||||
return () => (
|
||||
<button
|
||||
{...{
|
||||
|
@ -15,7 +19,13 @@ export const SbButton = defineComponent({
|
|||
class: (context.attrs.class || '') + ' sb-button',
|
||||
}}
|
||||
>
|
||||
{context.slots.default()}
|
||||
{
|
||||
/**
|
||||
* The button contents
|
||||
* @slot default
|
||||
*/
|
||||
context.slots.default?.()
|
||||
}
|
||||
</button>
|
||||
);
|
||||
},
|
||||
|
|
23
packages/core/lib/components/ContextMenu.scss
Normal file
23
packages/core/lib/components/ContextMenu.scss
Normal file
|
@ -0,0 +1,23 @@
|
|||
.sb-context {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.sb-context-menu {
|
||||
display: none;
|
||||
flex-direction: column;
|
||||
background: var(--grey-0);
|
||||
border: 1px solid var(--grey-3);
|
||||
top: 100%;
|
||||
left: 0;
|
||||
margin: 0;
|
||||
padding: 0.5rem 0.25rem;
|
||||
z-index: var(--z-context-menu);
|
||||
|
||||
max-height: 70vh;
|
||||
max-width: 100vw;
|
||||
overflow: auto;
|
||||
|
||||
&[open] {
|
||||
display: flex;
|
||||
}
|
||||
}
|
84
packages/core/lib/components/ContextMenu.tsx
Normal file
84
packages/core/lib/components/ContextMenu.tsx
Normal file
|
@ -0,0 +1,84 @@
|
|||
import {
|
||||
watch,
|
||||
defineComponent,
|
||||
ref,
|
||||
Ref,
|
||||
} from 'vue';
|
||||
import { SbButton } from './Button';
|
||||
|
||||
import './ContextMenu.scss';
|
||||
|
||||
export interface IContextMenuSlotContext {
|
||||
opened: Ref<boolean>;
|
||||
open: () => void;
|
||||
close: () => void;
|
||||
toggle: () => void;
|
||||
}
|
||||
|
||||
export const SbContextMenu = defineComponent({
|
||||
name: 'sb-context-menu',
|
||||
|
||||
props: {
|
||||
onClose: { type: Function, default: () => {} },
|
||||
onOpen: { type: Function, default: () => {} },
|
||||
},
|
||||
|
||||
setup(props, context) {
|
||||
const opened = ref(false);
|
||||
const open = () => { opened.value = true; };
|
||||
const close = () => { opened.value = false; };
|
||||
const closeOnEscape = ($event: KeyboardEvent) => {
|
||||
if ($event.key === 'Escape') {
|
||||
close();
|
||||
}
|
||||
};
|
||||
const toggle = () => { opened.value ? close() : open() };
|
||||
|
||||
watch(opened, (curr, prev) => {
|
||||
if (curr === prev) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!curr) {
|
||||
document.body.removeEventListener('click', close);
|
||||
document.body.removeEventListener('keypress', closeOnEscape);
|
||||
props.onClose();
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
document.body.addEventListener('click', close);
|
||||
document.body.addEventListener('keypress', closeOnEscape);
|
||||
props.onOpen();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return () => (
|
||||
<div class="sb-context">
|
||||
{
|
||||
context.slots.context?.({
|
||||
opened,
|
||||
toggle,
|
||||
close,
|
||||
open,
|
||||
}) || <SbButton {...{ onClick: toggle }}>Menu</SbButton>
|
||||
}
|
||||
<dialog
|
||||
class="sb-context-menu"
|
||||
open={opened.value ? true : undefined}
|
||||
onClick={($event: Event) => {
|
||||
// Make sure clicks inside do not autoclose this
|
||||
$event.stopPropagation();
|
||||
}}
|
||||
{...{ onClose: close /* TODO: DialogHTMLAttributes needs an onClose handler type */ }}
|
||||
>
|
||||
{context.slots.default?.({
|
||||
opened,
|
||||
toggle,
|
||||
close,
|
||||
open,
|
||||
}) || null}
|
||||
</dialog>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
});
|
|
@ -1,10 +1,8 @@
|
|||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.sb-main {
|
||||
position: relative;
|
||||
color: var(--fg);
|
||||
background-color: var(--bg);
|
||||
|
||||
html {
|
||||
--grey-0: white;
|
||||
--grey-1-t: rgba(0, 0, 0, 0.05);
|
||||
--grey-1: rgb(242, 242, 242);
|
||||
|
@ -22,9 +20,16 @@ html {
|
|||
--fg: var(--black);
|
||||
|
||||
--interact: #3f9cff;
|
||||
}
|
||||
--interact-lite: #3f9cff;
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
min-height: 100vh;
|
||||
--z-toolbar: 2000;
|
||||
--z-context-menu: 3000;
|
||||
--z-tree-block-select: 4000;
|
||||
--z-modal: 10000;
|
||||
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
}
|
119
packages/core/lib/components/Main.tsx
Normal file
119
packages/core/lib/components/Main.tsx
Normal file
|
@ -0,0 +1,119 @@
|
|||
import {
|
||||
defineComponent,
|
||||
provide,
|
||||
shallowReactive,
|
||||
ref,
|
||||
watch,
|
||||
PropType,
|
||||
Ref,
|
||||
} from 'vue';
|
||||
import {
|
||||
IBlockData,
|
||||
IBlockDefinition,
|
||||
IBlockLibrary,
|
||||
ITreeNode,
|
||||
OnUpdateBlockCb,
|
||||
} from '../types';
|
||||
import { model } from '../block-helpers';
|
||||
import { SymMode, SbMode } from '../mode';
|
||||
import { SymBlockLibrary} from '../use-dynamic-blocks';
|
||||
import {
|
||||
SymBlockTree,
|
||||
SymBlockTreeRegister,
|
||||
SymBlockTreeUnregister,
|
||||
} from '../use-block-tree';
|
||||
import { SymEditorDimensions, useResizeObserver } from '../use-resize-observer';
|
||||
import { SymActiveBlock } from '../use-activation';
|
||||
|
||||
import { SbMainMenu } from './MainMenu';
|
||||
import { SbBlockToolbar } from './BlockToolbar';
|
||||
import { SbBlock } from './Block';
|
||||
|
||||
export interface ISbMainProps {
|
||||
availableBlocks: IBlockDefinition<any>[];
|
||||
block: IBlockData<any>;
|
||||
eventUpdate: OnUpdateBlockCb;
|
||||
mode: SbMode;
|
||||
}
|
||||
|
||||
import './Main.scss';
|
||||
|
||||
export const SbMain = defineComponent({
|
||||
name: 'sb-main',
|
||||
|
||||
model,
|
||||
|
||||
props: {
|
||||
availableBlocks: {
|
||||
type: Array as PropType<IBlockDefinition<any>[]>,
|
||||
default: () => [],
|
||||
},
|
||||
block: {
|
||||
type: Object as PropType<IBlockData<any>>,
|
||||
required: true,
|
||||
},
|
||||
/**
|
||||
* Called when the block should be updated.
|
||||
*/
|
||||
eventUpdate: {
|
||||
type: (null as unknown) as PropType<OnUpdateBlockCb>,
|
||||
default: () => {},
|
||||
},
|
||||
mode: {
|
||||
type: String as PropType<SbMode>,
|
||||
validator(value: any) {
|
||||
return Object.values(SbMode).includes(value);
|
||||
},
|
||||
default: SbMode.Edit,
|
||||
},
|
||||
},
|
||||
|
||||
setup(props: ISbMainProps) {
|
||||
const el: Ref<null|HTMLElement> = ref(null);
|
||||
useResizeObserver(el, SymEditorDimensions);
|
||||
|
||||
const mode = ref(props.mode);
|
||||
provide(SymMode, mode);
|
||||
|
||||
watch(() => props.mode, (newMode) => {
|
||||
mode.value = newMode;
|
||||
});
|
||||
|
||||
const activeBlock = ref(null);
|
||||
provide(SymActiveBlock, activeBlock);
|
||||
|
||||
const blockTree: Ref<ITreeNode|null> = ref(null);
|
||||
provide(SymBlockTree, blockTree);
|
||||
provide(SymBlockTreeRegister, (block: ITreeNode) => { blockTree.value = block; });
|
||||
provide(SymBlockTreeUnregister, () => { blockTree.value = null; });
|
||||
|
||||
const blockLibrary: IBlockLibrary = shallowReactive({
|
||||
...props.availableBlocks.reduce(
|
||||
(blocks: IBlockLibrary, block: IBlockDefinition<any>) => ({ ...blocks, [block.name]: block }),
|
||||
{},
|
||||
),
|
||||
});
|
||||
|
||||
provide(SymBlockLibrary, blockLibrary);
|
||||
|
||||
return () => (
|
||||
<div
|
||||
class="sb-main"
|
||||
ref={el}
|
||||
>
|
||||
{
|
||||
mode.value === SbMode.Edit
|
||||
? <>
|
||||
<SbMainMenu block={props.block} />
|
||||
<SbBlockToolbar />
|
||||
</>
|
||||
: null
|
||||
}
|
||||
<SbBlock
|
||||
block={props.block}
|
||||
eventUpdate={props.eventUpdate}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
});
|
5
packages/core/lib/components/MainMenu.scss
Normal file
5
packages/core/lib/components/MainMenu.scss
Normal file
|
@ -0,0 +1,5 @@
|
|||
.sb-main-menu {
|
||||
display: flex;
|
||||
padding-bottom: 4rem;
|
||||
background-color: var(--grey-0);
|
||||
}
|
27
packages/core/lib/components/MainMenu.tsx
Normal file
27
packages/core/lib/components/MainMenu.tsx
Normal file
|
@ -0,0 +1,27 @@
|
|||
import {
|
||||
defineComponent,
|
||||
PropType,
|
||||
} from 'vue';
|
||||
import { IBlockData } from '../types';
|
||||
import { SbTreeBlockSelect } from './TreeBlockSelect';
|
||||
|
||||
import './MainMenu.scss';
|
||||
|
||||
export const SbMainMenu = defineComponent({
|
||||
name: 'sb-main-menu',
|
||||
|
||||
props: {
|
||||
block: {
|
||||
type: (null as unknown) as PropType<IBlockData<any>>,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
setup() {
|
||||
return () => (
|
||||
<div class="sb-main-menu">
|
||||
<SbTreeBlockSelect />
|
||||
</div>
|
||||
);
|
||||
},
|
||||
});
|
7
packages/core/lib/components/MissingBlock/index.ts
Normal file
7
packages/core/lib/components/MissingBlock/index.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import { defineAsyncComponent } from 'vue';
|
||||
|
||||
export default {
|
||||
name: 'sb-missing-block',
|
||||
edit: defineAsyncComponent(() => import('./view')),
|
||||
view: defineAsyncComponent(() => import('./view')),
|
||||
};
|
0
packages/core/lib/components/MissingBlock/util.ts
Normal file
0
packages/core/lib/components/MissingBlock/util.ts
Normal file
|
@ -2,25 +2,18 @@ import { defineComponent, PropType } from 'vue';
|
|||
import {
|
||||
model,
|
||||
blockProps,
|
||||
BlockProps,
|
||||
} from '../../blocks';
|
||||
} from '../../block-helpers';
|
||||
|
||||
import './style.scss';
|
||||
|
||||
interface MissingBlockProps extends BlockProps<any> {
|
||||
eventUpdate: (b?: any) => void;
|
||||
eventAppendBlock: (b?: any) => void;
|
||||
eventRemoveBlock: () => void;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: 'sb-missing-block',
|
||||
|
||||
model,
|
||||
|
||||
props: {
|
||||
name: String,
|
||||
...blockProps,
|
||||
name: String,
|
||||
data: {
|
||||
type: (null as unknown) as PropType<any>,
|
||||
default: null,
|
||||
|
@ -30,12 +23,9 @@ export default defineComponent({
|
|||
eventRemoveBlock: { type: Function, default: () => {} },
|
||||
},
|
||||
|
||||
setup(props: MissingBlockProps) {
|
||||
console.log(props, props.name, props.data, props.blockId);
|
||||
setup(props) {
|
||||
return () => (
|
||||
<div class="sb-missing-block">
|
||||
Missing block: {props.name}
|
||||
</div>
|
||||
<div class="sb-missing-block">Missing block: {props.name}</div>
|
||||
);
|
||||
},
|
||||
});
|
|
@ -2,7 +2,7 @@
|
|||
&__overlay {
|
||||
background-color: var(--grey-3-t);
|
||||
position: fixed;
|
||||
z-index: 10;
|
||||
z-index: var(--z-modal);
|
||||
top: 0;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
|
|
|
@ -5,11 +5,6 @@ import {
|
|||
|
||||
import './Modal.scss';
|
||||
|
||||
interface ModalProps {
|
||||
open: boolean;
|
||||
eventClose: () => void;
|
||||
}
|
||||
|
||||
export const SbModal = defineComponent({
|
||||
name: 'sb-modal',
|
||||
|
||||
|
@ -18,10 +13,10 @@ export const SbModal = defineComponent({
|
|||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
eventClose: { type: Function, default: () => {} },
|
||||
onClose: { type: Function, default: () => {} },
|
||||
},
|
||||
|
||||
setup(props: ModalProps, context) {
|
||||
setup(props, context) {
|
||||
const classes = computed(() => ({
|
||||
'sb-modal': true,
|
||||
'sb-modal_open': props.open,
|
||||
|
@ -33,11 +28,11 @@ export const SbModal = defineComponent({
|
|||
class="sb-modal__overlay"
|
||||
onClick={($event: MouseEvent) => {
|
||||
$event.stopPropagation();
|
||||
props.eventClose();
|
||||
props.onClose();
|
||||
}}
|
||||
>
|
||||
<div class="sb-modal__content">
|
||||
{context.slots.default()}
|
||||
{context.slots.default?.()}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
.sb-main {
|
||||
position: relative;
|
||||
background-color: var(--bg);
|
||||
padding: 50px 40px;
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
import {
|
||||
defineComponent,
|
||||
provide,
|
||||
shallowReactive,
|
||||
ref,
|
||||
watch,
|
||||
PropType,
|
||||
Ref,
|
||||
} from 'vue';
|
||||
import {
|
||||
model,
|
||||
Block,
|
||||
BlockDefinition,
|
||||
BlockLibraryDefinition,
|
||||
} from '../blocks';
|
||||
import { Mode, SbMode } from '../mode';
|
||||
import { BlockLibrary } from '../use-dynamic-blocks';
|
||||
import { EditorDimensions, useResizeObserver } from '../use-resize-observer';
|
||||
import { ActiveBlock } from '../use-activation';
|
||||
|
||||
import { SbBlock } from './Block';
|
||||
|
||||
import './Schlechtenburg.scss';
|
||||
|
||||
export interface SchlechtenburgProps {
|
||||
customBlocks: BlockDefinition[];
|
||||
eventUpdate: (b: Block<any>) => void;
|
||||
block: Block<any>;
|
||||
mode: SbMode;
|
||||
}
|
||||
|
||||
export const Schlechtenburg = defineComponent({
|
||||
name: 'schlechtenburg-main',
|
||||
|
||||
model,
|
||||
|
||||
props: {
|
||||
customBlocks: { type: Array as PropType<BlockDefinition[]>, default: () => [] },
|
||||
block: { type: Object as PropType<Block<any>>, required: true },
|
||||
eventUpdate: { type: Function, default: () => {} },
|
||||
mode: {
|
||||
type: String as PropType<SbMode>,
|
||||
validator(value: any) {
|
||||
return Object.values(SbMode).includes(value);
|
||||
},
|
||||
default: SbMode.Edit,
|
||||
},
|
||||
},
|
||||
|
||||
setup(props: SchlechtenburgProps) {
|
||||
const el: Ref<null|HTMLElement> = ref(null);
|
||||
useResizeObserver(el, EditorDimensions);
|
||||
|
||||
const mode = ref(props.mode);
|
||||
provide(Mode, mode);
|
||||
|
||||
const activeBlock = ref(null);
|
||||
provide(ActiveBlock, activeBlock);
|
||||
|
||||
const blockLibrary: BlockLibraryDefinition = shallowReactive({
|
||||
...props.customBlocks.reduce(
|
||||
(blocks: {[name: string]: Block<any>}, block: Block<any>) => ({ ...blocks, [block.name]: block }),
|
||||
{},
|
||||
),
|
||||
});
|
||||
|
||||
provide(BlockLibrary, blockLibrary);
|
||||
|
||||
watch(props.block, () => {
|
||||
console.log('Update', props.block);
|
||||
});
|
||||
|
||||
return () => (
|
||||
<div
|
||||
class="sb-main"
|
||||
ref={el}
|
||||
>
|
||||
<SbBlock
|
||||
block={props.block}
|
||||
eventUpdate={props.eventUpdate}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
});
|
|
@ -2,6 +2,7 @@
|
|||
background-color: var(--grey-0);
|
||||
border: 1px solid var(--grey-2);
|
||||
position: relative;
|
||||
font-size: 1rem;
|
||||
|
||||
&:hover {
|
||||
border: 1px solid var(--interact);
|
||||
|
|
|
@ -1,19 +1,29 @@
|
|||
import { defineComponent } from 'vue';
|
||||
import './Select.scss';
|
||||
|
||||
/**
|
||||
* A select input in the schlechtenburg theme
|
||||
* @sbui
|
||||
*/
|
||||
export const SbSelect = defineComponent({
|
||||
name: 'sb-select',
|
||||
|
||||
inheritAttrs: false,
|
||||
|
||||
setup(props, context) {
|
||||
setup(_, context) {
|
||||
return () => (
|
||||
<div class="sb-select">
|
||||
<select
|
||||
class="sb-select__input"
|
||||
{...context.attrs}
|
||||
>
|
||||
{context.slots.default()}
|
||||
{
|
||||
/**
|
||||
* The select options list
|
||||
* @slot default
|
||||
*/
|
||||
context.slots.default?.()
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -2,4 +2,7 @@
|
|||
position: absolute;
|
||||
width: auto;
|
||||
height: auto;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
z-index: var(--z-toolbar);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { debounce } from 'lodash-es';
|
||||
import debounce from 'lodash/debounce';
|
||||
import {
|
||||
defineComponent,
|
||||
watch,
|
||||
|
@ -8,6 +8,10 @@ import { useBlockSizing } from '../use-resize-observer';
|
|||
|
||||
import './Toolbar.scss';
|
||||
|
||||
/**
|
||||
* Toolbar in the schlechtenburg theme
|
||||
* @sbui
|
||||
*/
|
||||
export const SbToolbar = defineComponent({
|
||||
name: 'sb-toolbar',
|
||||
|
||||
|
@ -38,7 +42,13 @@ export const SbToolbar = defineComponent({
|
|||
style={styles}
|
||||
onClick={($event: MouseEvent) => $event.stopPropagation()}
|
||||
>
|
||||
{context.slots?.default?.()}
|
||||
{
|
||||
/**
|
||||
* The toolbar contents
|
||||
* @slot default
|
||||
*/
|
||||
context.slots.default?.()
|
||||
}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
|
|
36
packages/core/lib/components/TreeBlockSelect.scss
Normal file
36
packages/core/lib/components/TreeBlockSelect.scss
Normal file
|
@ -0,0 +1,36 @@
|
|||
.sb-tree-block-select {
|
||||
&__list {
|
||||
list-style: none;
|
||||
color: var(--fg);
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
|
||||
&_base {
|
||||
padding-right: 1rem;
|
||||
}
|
||||
}
|
||||
|
||||
&__block {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
padding-left: 1rem;
|
||||
|
||||
&-name {
|
||||
display: block;
|
||||
background: transparent;
|
||||
border: 0;
|
||||
font: inherit;
|
||||
color: inherit;
|
||||
padding: 0.25rem 0.5rem;
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
|
||||
&_active {
|
||||
& > .sb-tree-block-select__block-name {
|
||||
outline: 1px solid var(--interact);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
58
packages/core/lib/components/TreeBlockSelect.tsx
Normal file
58
packages/core/lib/components/TreeBlockSelect.tsx
Normal file
|
@ -0,0 +1,58 @@
|
|||
import { defineComponent } from 'vue';
|
||||
import { ITreeNode } from '../types';
|
||||
import { useBlockTree } from '../use-block-tree';
|
||||
import { useActivation } from '../use-activation';
|
||||
|
||||
import { SbContextMenu } from './ContextMenu';
|
||||
import { SbButton } from './Button';
|
||||
|
||||
import './TreeBlockSelect.scss';
|
||||
|
||||
export const SbTreeBlockSelect = defineComponent({
|
||||
name: 'sb-main-menu',
|
||||
|
||||
setup() {
|
||||
const { blockTree } = useBlockTree();
|
||||
const {
|
||||
activate,
|
||||
activeBlockId,
|
||||
} = useActivation();
|
||||
|
||||
const treeToHtml = (tree: ITreeNode, close: Function) => <li
|
||||
class={{
|
||||
'sb-tree-block-select__block': true,
|
||||
'sb-tree-block-select__block_active': activeBlockId.value === tree.id,
|
||||
}}
|
||||
>
|
||||
<button
|
||||
class="sb-tree-block-select__block-name"
|
||||
onClick={() => {
|
||||
activate(tree.id);
|
||||
close();
|
||||
}}
|
||||
onMouseenter={() => activate(tree.id)}
|
||||
>{tree.name}</button>
|
||||
{tree.children?.length
|
||||
? <ul class="sb-tree-block-select__list">
|
||||
{tree.children?.map((child: ITreeNode) => treeToHtml(child, close))}
|
||||
</ul>
|
||||
: null
|
||||
}
|
||||
</li>;
|
||||
|
||||
|
||||
return () => (
|
||||
blockTree.value
|
||||
? <SbContextMenu
|
||||
class="sb-tree-block-select"
|
||||
v-slots={{
|
||||
context: ({ toggle }: { toggle: Function }) => <SbButton {...{ onClick: toggle }}>Tree</SbButton>,
|
||||
default: ({ close }: { close: Function }) => <ul
|
||||
class="sb-tree-block-select__list sb-tree-block-select__list_base"
|
||||
>{treeToHtml(blockTree.value as ITreeNode, close)}</ul>,
|
||||
}}
|
||||
/>
|
||||
: ''
|
||||
);
|
||||
},
|
||||
});
|
|
@ -1,3 +0,0 @@
|
|||
export default {
|
||||
|
||||
};
|
9
packages/core/lib/directives/hover-cover.scss
Normal file
9
packages/core/lib/directives/hover-cover.scss
Normal file
|
@ -0,0 +1,9 @@
|
|||
.sb-hover-cover {
|
||||
&:hover {
|
||||
outline: 1px dashed var(--interact);
|
||||
}
|
||||
|
||||
&_child-hovered:hover {
|
||||
outline: none;
|
||||
}
|
||||
}
|
64
packages/core/lib/directives/hover-cover.ts
Normal file
64
packages/core/lib/directives/hover-cover.ts
Normal file
|
@ -0,0 +1,64 @@
|
|||
import './hover-cover.scss';
|
||||
|
||||
const findParents = (el: HTMLElement, foundParents: HTMLElement[] = []): HTMLElement[] => {
|
||||
const parent = el.parentElement as HTMLElement|null;
|
||||
if (!parent) {
|
||||
return foundParents;
|
||||
}
|
||||
|
||||
if (parent.classList.contains('sb-hover-cover')) {
|
||||
return findParents(
|
||||
parent,
|
||||
[
|
||||
...foundParents,
|
||||
parent,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return findParents(
|
||||
parent,
|
||||
foundParents,
|
||||
);
|
||||
}
|
||||
|
||||
const parentData = new WeakMap();
|
||||
|
||||
const onMouseEnter = (event: MouseEvent) => {
|
||||
const parents = parentData.get(event.target as HTMLElement);
|
||||
for (const parent of parents) {
|
||||
parent.classList.add('sb-hover-cover_child-hovered');
|
||||
}
|
||||
};
|
||||
|
||||
const onMouseLeave = (event: MouseEvent) => {
|
||||
const parents = parentData.get(event.target as HTMLElement);
|
||||
if (parents && parents.length) {
|
||||
parents[0].classList.remove('sb-hover-cover_child-hovered');
|
||||
}
|
||||
};
|
||||
|
||||
export default {
|
||||
updated(el: HTMLElement) {
|
||||
el.classList.add('sb-hover-cover');
|
||||
},
|
||||
|
||||
beforeMount(el: HTMLElement) {
|
||||
el.classList.add('sb-hover-cover');
|
||||
},
|
||||
|
||||
mounted(el: HTMLElement) {
|
||||
el.classList.add('sb-hover-cover');
|
||||
|
||||
const parents = findParents(el);
|
||||
parentData.set(el, parents);
|
||||
|
||||
el.addEventListener('mouseenter', onMouseEnter)
|
||||
el.addEventListener('mouseleave', onMouseLeave)
|
||||
},
|
||||
|
||||
unmounted(el:HTMLElement) {
|
||||
el.removeEventListener('mouseenter', onMouseEnter)
|
||||
el.removeEventListener('mouseleave', onMouseLeave)
|
||||
},
|
||||
};
|
0
packages/core/lib/id.ts
Normal file
0
packages/core/lib/id.ts
Normal file
|
@ -1,13 +1,13 @@
|
|||
export * from './mode';
|
||||
export * from './blocks';
|
||||
export * from './types';
|
||||
|
||||
export * from './block-helpers';
|
||||
|
||||
export * from './use-activation';
|
||||
export * from './use-dynamic-blocks';
|
||||
export * from './use-resize-observer';
|
||||
|
||||
export * from './directives/activation-cover.js';
|
||||
|
||||
export * from './components/Schlechtenburg';
|
||||
export * from './components/Main';
|
||||
export * from './components/Block';
|
||||
export * from './components/BlockPicker';
|
||||
export * from './components/BlockOrdering';
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
/**
|
||||
* The mode the Schlechtenburg editor is currently in
|
||||
*/
|
||||
export enum SbMode {
|
||||
Edit = 'edit',
|
||||
Display = 'display',
|
||||
View = 'view',
|
||||
}
|
||||
export const Mode = Symbol('Schlechtenburg mode');
|
||||
export const SymMode = Symbol('Schlechtenburg mode');
|
||||
|
|
8
packages/core/lib/types.d.ts
vendored
Normal file
8
packages/core/lib/types.d.ts
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
/*
|
||||
import {HTMLAttributes} from "vue";
|
||||
|
||||
interface DialogHTMLAttributes extends HTMLAttributes {
|
||||
open?: boolean;
|
||||
onClose?: Function;
|
||||
}
|
||||
*/
|
172
packages/core/lib/types.ts
Normal file
172
packages/core/lib/types.ts
Normal file
|
@ -0,0 +1,172 @@
|
|||
import { Component } from 'vue';
|
||||
|
||||
/**
|
||||
* Schlechtenburg keeps track of the rendered block tree.
|
||||
* This is useful for e.g. the tree select component in the editor header.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export interface ITreeNode {
|
||||
id: string;
|
||||
name: string;
|
||||
icon?: string;
|
||||
children: ITreeNode[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Schlechtenburg inputs and outputs a plain JS Object that can be JSON stringified. This is the
|
||||
* interface type for that data structure. `T` will be the data type of the specific block being
|
||||
*
|
||||
* @see SbMain
|
||||
*/
|
||||
export interface IBlockData<T> {
|
||||
id: string;
|
||||
name: string;
|
||||
data: T;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Callback type for sending full block updates. SbBlock takes this as a prop.
|
||||
*
|
||||
* ```
|
||||
* <SbBlock eventUpdate={myFn as OnUpdateSelfCb}></SbBlock>
|
||||
* ```
|
||||
*
|
||||
* @see SbBlock
|
||||
*/
|
||||
export type OnUpdateBlockCb = (updated: IBlockData<any>) => void;
|
||||
|
||||
/**
|
||||
* Callback type for sending partial self-updates in edit mode.
|
||||
*
|
||||
* ```
|
||||
* props: {
|
||||
* eventUpdate: {
|
||||
* type: (null as unknown) as PropType<OnUpdateSelfCb<IYourComponentData>>,
|
||||
* default: () => {},
|
||||
* },
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @see SbBlock
|
||||
*/
|
||||
export type OnUpdateSelfCb<T> = (updated: Partial<T>) => void;
|
||||
|
||||
/**
|
||||
* Callback type for sending blocks that should be prepended as a sibling before the current block
|
||||
*
|
||||
* ```
|
||||
* props: {
|
||||
* eventPrependBlock: {
|
||||
* type: (null as unknown) as PropType<OnPrependBlockCb<IComponentToBePrependedData>>,
|
||||
* default: () => {},
|
||||
* },
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @see SbBlock
|
||||
*/
|
||||
export type OnPrependBlockCb = (block: IBlockData<any>) => void;
|
||||
|
||||
/**
|
||||
* Callback type for sending blocks that should be appended as a sibling after the current block
|
||||
*
|
||||
* ```
|
||||
* props: {
|
||||
* eventAppendBlock: {
|
||||
* type: (null as unknown) as PropType<OnAppendBlockCb<IComponentToBeAppendedData>>,
|
||||
* default: () => {},
|
||||
* },
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @see SbBlock
|
||||
*/
|
||||
export type OnAppendBlockCb = (block: IBlockData<any>) => void;
|
||||
|
||||
/**
|
||||
* Callback type for removing the current block.
|
||||
*
|
||||
* ```
|
||||
* props: {
|
||||
* eventRemoveSelf: {
|
||||
* type: (null as unknown) as PropType<OnRemoveSelfCb>,
|
||||
* default: () => {},
|
||||
* },
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @see SbBlock
|
||||
*/
|
||||
export type OnRemoveSelfCb = () => void;
|
||||
|
||||
/**
|
||||
* Callback type for activating the previous block.
|
||||
*
|
||||
* ```
|
||||
* props: {
|
||||
* eventActivatePrevious: {
|
||||
* type: (null as unknown) as PropType<OnActivatePreviousCb>,
|
||||
* default: (_i:number) => {},
|
||||
* },
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @see SbBlock
|
||||
*/
|
||||
export type OnActivatePreviousCb = (_i:number) => void;
|
||||
|
||||
/**
|
||||
* Callback type for activating the next block.
|
||||
*
|
||||
* ```
|
||||
* props: {
|
||||
* eventActivateNext: {
|
||||
* type: (null as unknown) as PropType<OnActivateNextCb>,
|
||||
* default: (_i:number) => {},
|
||||
* },
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @see SbBlock
|
||||
*/
|
||||
export type OnActivateNextCb = (_i:number) => void;
|
||||
|
||||
/**
|
||||
* Any Block that you create
|
||||
*
|
||||
* @see IBlockDefinition
|
||||
*/
|
||||
export interface IBlockProps<T> {
|
||||
blockId?: string;
|
||||
data?: T,
|
||||
eventUpdate?: OnUpdateSelfCb<T>;
|
||||
eventPrependBlock?: OnPrependBlockCb;
|
||||
eventAppendBlock?: OnAppendBlockCb;
|
||||
eventRemoveSelf?: OnRemoveSelfCb;
|
||||
eventActivateNext?: OnActivateNextCb;
|
||||
eventActivatePrevious?: OnActivatePreviousCb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Any Block that you create
|
||||
*
|
||||
* @see IBlockProps
|
||||
*/
|
||||
export interface IBlockDefinition<T> {
|
||||
name: string;
|
||||
icon?: string;
|
||||
getDefaultData: T;
|
||||
edit: Component<IBlockProps<T>>;
|
||||
view: Component<IBlockProps<T>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Schlechtenburg maintains a library of blocks that are available
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export interface IBlockLibrary {
|
||||
[name: string]: IBlockDefinition<any>;
|
||||
}
|
|
@ -3,15 +3,34 @@ import {
|
|||
ref,
|
||||
inject,
|
||||
computed,
|
||||
onBeforeUnmount,
|
||||
} from 'vue';
|
||||
|
||||
export const ActiveBlock = Symbol('Schlechtenburg active block');
|
||||
export function useActivation(currentBlockId: string) {
|
||||
const activeBlockId: Ref<string|null> = inject(ActiveBlock, ref(null));
|
||||
export const SymActiveBlock = Symbol('Schlechtenburg active block');
|
||||
export function useActivation(currentBlockId: string|null = null) {
|
||||
const activeBlockId: Ref<string|null> = inject(SymActiveBlock, ref(null));
|
||||
|
||||
const isActive = computed(() => activeBlockId.value === currentBlockId);
|
||||
const activate = (blockId?: string|null) => {
|
||||
activeBlockId.value = blockId !== undefined ? blockId : currentBlockId;
|
||||
|
||||
const deactivate = (id: string|null = currentBlockId) => {
|
||||
if (activeBlockId.value !== id) {
|
||||
return;
|
||||
}
|
||||
|
||||
activeBlockId.value = null;
|
||||
};
|
||||
|
||||
const deactivateCb = (_:Event) => deactivate();
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener('click', deactivateCb);
|
||||
})
|
||||
|
||||
const activate = (id: string|null = currentBlockId) => {
|
||||
document.addEventListener('click', deactivateCb, { once: true });
|
||||
activeBlockId.value = id;
|
||||
};
|
||||
|
||||
const requestActivation = () => {
|
||||
if (activeBlockId.value) {
|
||||
return;
|
||||
|
@ -21,8 +40,10 @@ export function useActivation(currentBlockId: string) {
|
|||
};
|
||||
|
||||
return {
|
||||
activeBlockId,
|
||||
isActive,
|
||||
activate,
|
||||
deactivate,
|
||||
requestActivation,
|
||||
};
|
||||
}
|
||||
|
|
85
packages/core/lib/use-block-tree.ts
Normal file
85
packages/core/lib/use-block-tree.ts
Normal file
|
@ -0,0 +1,85 @@
|
|||
import {
|
||||
ref,
|
||||
Ref,
|
||||
reactive,
|
||||
inject,
|
||||
provide,
|
||||
onUnmounted,
|
||||
} from 'vue';
|
||||
import {
|
||||
ITreeNode,
|
||||
IBlockData,
|
||||
} from './types';
|
||||
import { useDynamicBlocks } from './use-dynamic-blocks';
|
||||
import { SbMode } from './mode';
|
||||
|
||||
export const SymBlockTree= Symbol('Schlechtenburg block tree');
|
||||
export const SymBlockTreeRegister = Symbol('Schlechtenburg block tree register');
|
||||
export const SymBlockTreeUnregister = Symbol('Schlechtenburg block tree unregister');
|
||||
|
||||
export function useBlockTree() {
|
||||
const blockTree: Ref<ITreeNode|null> = inject(SymBlockTree, ref(null));
|
||||
const registerWithParent = inject(SymBlockTreeRegister, (_b: ITreeNode, _i: number) => {});
|
||||
const unregisterWithParent = inject(SymBlockTreeUnregister, (_b: ITreeNode) => {});
|
||||
|
||||
const self: ITreeNode = reactive({
|
||||
id: '',
|
||||
name: '',
|
||||
icon: '',
|
||||
children: [],
|
||||
});
|
||||
|
||||
// Provide a registration function to child blocks
|
||||
provide(SymBlockTreeRegister, (block: ITreeNode, index:number = -1) => {
|
||||
if (self.children.find((child: ITreeNode) => child.id === block.id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (index < 0) {
|
||||
}
|
||||
|
||||
const normalizedIndex = index < 0 ? 0 : index;
|
||||
|
||||
self.children =[
|
||||
...self.children.slice(0, normalizedIndex),
|
||||
block,
|
||||
...self.children.slice(normalizedIndex),
|
||||
];
|
||||
});
|
||||
|
||||
// Provide an unregistration function to child blocks
|
||||
provide(SymBlockTreeUnregister, ({ id }: ITreeNode) => {
|
||||
self.children = self.children.filter((child: ITreeNode) => child.id !== id);
|
||||
});
|
||||
|
||||
const { mode } = useDynamicBlocks();
|
||||
|
||||
const register = (block: IBlockData<any>, index: number = 0) => {
|
||||
if (!block.id) {
|
||||
throw new Error(`Cannot register a block without an id: ${JSON.stringify(block)}`);
|
||||
}
|
||||
|
||||
if (mode.value !== SbMode.Edit) {
|
||||
console.warn('Ignoring block tree registration requests outside of edit mode.');
|
||||
return;
|
||||
}
|
||||
|
||||
self.id = block.id;
|
||||
self.name = block.name;
|
||||
|
||||
// Register ourselves at the parent block
|
||||
registerWithParent(self, index);
|
||||
}
|
||||
|
||||
// Unregister from parent when we get destroyed
|
||||
onUnmounted(() => {
|
||||
if (self.id) {
|
||||
unregisterWithParent(self);
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
blockTree,
|
||||
register,
|
||||
};
|
||||
}
|
|
@ -3,14 +3,14 @@ import {
|
|||
inject,
|
||||
reactive,
|
||||
} from 'vue';
|
||||
import { BlockLibraryDefinition } from './blocks';
|
||||
import { Mode, SbMode } from './mode';
|
||||
import { IBlockLibrary } from './types';
|
||||
import { SymMode, SbMode } from './mode';
|
||||
|
||||
export const BlockLibrary = Symbol('Schlechtenburg block library');
|
||||
export const SymBlockLibrary = Symbol('Schlechtenburg block library');
|
||||
export function useDynamicBlocks() {
|
||||
const mode = inject(Mode, ref(SbMode.Edit));
|
||||
const customBlocks: BlockLibraryDefinition = inject(BlockLibrary, reactive({}));
|
||||
const getBlock = (name: string) => customBlocks[name]?.[mode.value];
|
||||
const mode = inject(SymMode, ref(SbMode.Edit));
|
||||
const customBlocks: IBlockLibrary = inject(SymBlockLibrary, reactive({}));
|
||||
const getBlock = (name: string) => customBlocks[name];
|
||||
|
||||
return {
|
||||
mode,
|
||||
|
|
|
@ -2,6 +2,7 @@ import {
|
|||
Ref,
|
||||
ref,
|
||||
inject,
|
||||
onBeforeMount,
|
||||
watch,
|
||||
provide,
|
||||
} from 'vue';
|
||||
|
@ -13,8 +14,8 @@ interface BlockRect {
|
|||
top: number;
|
||||
}
|
||||
|
||||
export const BlockDimensions = Symbol('Schlechtenburg block dimensions');
|
||||
export const EditorDimensions = Symbol('Schlechtenburg editor dimensions');
|
||||
export const SymBlockDimensions = Symbol('Schlechtenburg block dimensions');
|
||||
export const SymEditorDimensions = Symbol('Schlechtenburg editor dimensions');
|
||||
export function useResizeObserver(el: Ref<null|HTMLElement>, symbol: symbol) {
|
||||
const dimensions: Ref<null|BlockRect> = ref(null);
|
||||
provide(symbol, dimensions);
|
||||
|
@ -32,23 +33,25 @@ export function useResizeObserver(el: Ref<null|HTMLElement>, symbol: symbol) {
|
|||
};
|
||||
};
|
||||
|
||||
const resizeObserver = new ResizeObserver(triggerSizeCalculation);
|
||||
const mutationObserver = new MutationObserver(triggerSizeCalculation);
|
||||
onBeforeMount(() => {
|
||||
const resizeObserver = new ResizeObserver(triggerSizeCalculation);
|
||||
const mutationObserver = new MutationObserver(triggerSizeCalculation);
|
||||
|
||||
watch(el, () => {
|
||||
if (!el.value) {
|
||||
return;
|
||||
}
|
||||
resizeObserver.observe(el.value);
|
||||
mutationObserver.observe(el.value, { attributes: true, childList: false, subtree: false });
|
||||
});
|
||||
watch(el, () => {
|
||||
if (!el.value) {
|
||||
return;
|
||||
}
|
||||
resizeObserver.observe(el.value);
|
||||
mutationObserver.observe(el.value, { attributes: true, childList: false, subtree: false });
|
||||
});
|
||||
})
|
||||
|
||||
return { triggerSizeCalculation, dimensions };
|
||||
}
|
||||
|
||||
export function useBlockSizing() {
|
||||
const editorDimensions: Ref<BlockRect|null> = inject(EditorDimensions, ref(null));
|
||||
const blockDimensions: Ref<BlockRect|null> = inject(BlockDimensions, ref(null));
|
||||
const editorDimensions: Ref<BlockRect|null> = inject(SymEditorDimensions, ref(null));
|
||||
const blockDimensions: Ref<BlockRect|null> = inject(SymBlockDimensions, ref(null));
|
||||
|
||||
return { editorDimensions, blockDimensions };
|
||||
}
|
||||
|
|
1843
packages/core/package-lock.json
generated
1843
packages/core/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -6,12 +6,18 @@
|
|||
"homepage": "",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"main": "lib/index.ts",
|
||||
"scripts": {
|
||||
"dev": "npm run json-to-md:watch",
|
||||
"typecheck": "vuedx-typecheck --no-pretty ./lib",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"directories": {
|
||||
"lib": "lib",
|
||||
"test": "__tests__"
|
||||
"doc": "docs",
|
||||
"lib": "lib"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
"lib",
|
||||
"docs"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
|
@ -21,7 +27,17 @@
|
|||
"url": "git@git.b12f.io:b12f/schlechtenburg.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"vue": "^3.0.4",
|
||||
"lodash-es": "^4.17.20"
|
||||
"lodash": "^4.17.21",
|
||||
"uuid": "^8.3.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"vue": "^3.2.31"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash-es": "^4.17.4",
|
||||
"@types/uuid": "^8.3.0",
|
||||
"@vuedx/typecheck": "^0.6.3",
|
||||
"@vuedx/typescript-plugin-vue": "^0.6.3",
|
||||
"vue": "^3.4.23"
|
||||
}
|
||||
}
|
||||
|
|
9
packages/core/tsconfig.json
Normal file
9
packages/core/tsconfig.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": [
|
||||
"lib/**/*.ts",
|
||||
"lib/**/*.d.ts",
|
||||
"lib/**/*.tsx",
|
||||
"lib/**/*.vue"
|
||||
]
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
const heading = require('..');
|
||||
|
||||
describe('@schlechtenburg/heading', () => {
|
||||
it('needs tests');
|
||||
});
|
16
packages/heading/__tests__/heading.test.ts
Normal file
16
packages/heading/__tests__/heading.test.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { describe, expect, it } from 'vitest'
|
||||
import { mount } from '@vue/test-utils';
|
||||
import SbHeadingEdit from '../lib/edit';
|
||||
import SbHeadingView from '../lib/view';
|
||||
|
||||
describe('@schlechtenburg/heading', () => {
|
||||
it('edit should render', () => {
|
||||
const edit = mount(SbHeadingEdit);
|
||||
expect(edit.find('p').element).toBeTruthy();
|
||||
expect(edit.find('div.sb-toolbar').element).toBeTruthy();
|
||||
});
|
||||
it('view should render', () => {
|
||||
const edit = mount(SbHeadingView);
|
||||
expect(edit.find('h1').element).toBeTruthy();
|
||||
});
|
||||
});
|
1
packages/heading/docs/components.json
Normal file
1
packages/heading/docs/components.json
Normal file
|
@ -0,0 +1 @@
|
|||
[]
|
2032
packages/heading/docs/lib.json
Normal file
2032
packages/heading/docs/lib.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1 +1,220 @@
|
|||
export default {};
|
||||
import {
|
||||
defineComponent,
|
||||
reactive,
|
||||
computed,
|
||||
ref,
|
||||
Ref,
|
||||
onMounted,
|
||||
watch,
|
||||
PropType,
|
||||
} from 'vue';
|
||||
import {
|
||||
model,
|
||||
useActivation,
|
||||
SbToolbar,
|
||||
SbSelect,
|
||||
OnUpdateSelfCb,
|
||||
OnAppendBlockCb,
|
||||
OnRemoveSelfCb,
|
||||
OnActivateNextCb,
|
||||
OnActivatePreviousCb,
|
||||
generateBlockId,
|
||||
} from '@schlechtenburg/core';
|
||||
import {
|
||||
getDefaultData,
|
||||
IHeadingData
|
||||
} from './util';
|
||||
import { getDefaultData as getDefaultParagraphData } from '@schlechtenburg/paragraph';
|
||||
|
||||
import './style.scss';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'sb-heading-edit',
|
||||
|
||||
model,
|
||||
|
||||
props: {
|
||||
blockId: { type: String, required: true },
|
||||
data: {
|
||||
type: (null as unknown) as PropType<IHeadingData>,
|
||||
default: getDefaultData,
|
||||
},
|
||||
eventUpdate: {
|
||||
type: (null as unknown) as PropType<OnUpdateSelfCb<IHeadingData>>,
|
||||
default: () => {},
|
||||
},
|
||||
eventAppendBlock: {
|
||||
type: (null as unknown) as PropType<OnAppendBlockCb>,
|
||||
default: () => {},
|
||||
},
|
||||
eventRemoveSelf: {
|
||||
type: (null as unknown) as PropType<OnRemoveSelfCb>,
|
||||
default: () => {},
|
||||
},
|
||||
eventActivateNext: {
|
||||
type: (null as unknown) as PropType<OnActivateNextCb>,
|
||||
default: () => {},
|
||||
},
|
||||
eventActivatePrevious: {
|
||||
type: (null as unknown) as PropType<OnActivatePreviousCb>,
|
||||
default: () => {},
|
||||
},
|
||||
},
|
||||
|
||||
setup(props) {
|
||||
const localData = (reactive({
|
||||
value: props.data.value,
|
||||
align: props.data.align,
|
||||
level: props.data.level,
|
||||
focused: false,
|
||||
}) as unknown) as {
|
||||
value: string;
|
||||
align: string;
|
||||
level: number;
|
||||
focused: boolean;
|
||||
};
|
||||
|
||||
const inputEl: Ref<null|HTMLElement> = ref(null);
|
||||
|
||||
const { isActive, activate } = useActivation(props.blockId);
|
||||
|
||||
const focusInput = () => {
|
||||
if (inputEl.value && isActive.value) {
|
||||
inputEl.value.focus();
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
focusInput();
|
||||
if (inputEl.value) {
|
||||
inputEl.value.innerHTML = localData.value;
|
||||
}
|
||||
});
|
||||
|
||||
watch(isActive, focusInput);
|
||||
|
||||
watch(() => props.data, () => {
|
||||
localData.value = props.data.value;
|
||||
localData.align = props.data.align;
|
||||
localData.level = props.data.level;
|
||||
if (inputEl.value) {
|
||||
inputEl.value.innerHTML = localData.value;
|
||||
}
|
||||
});
|
||||
|
||||
const onTextUpdate = ($event: Event) => {
|
||||
localData.value = ($event.target as HTMLElement).innerHTML;
|
||||
};
|
||||
|
||||
const classes = computed(() => ({
|
||||
'sb-heading': true,
|
||||
'sb-heading_focused': localData.focused,
|
||||
[`sb-heading_align-${localData.align}`]: true,
|
||||
[`sb-heading_${localData.level}`]: true,
|
||||
}));
|
||||
|
||||
const setLevel = ($event: Event) => {
|
||||
props.eventUpdate({
|
||||
...localData,
|
||||
level: parseInt(($event.target as HTMLSelectElement).value, 10),
|
||||
});
|
||||
};
|
||||
|
||||
const setAlignment = ($event: Event) => {
|
||||
props.eventUpdate({
|
||||
...localData,
|
||||
align: ($event.target as HTMLSelectElement).value,
|
||||
});
|
||||
};
|
||||
|
||||
const onFocus = () => {
|
||||
localData.focused = true;
|
||||
activate();
|
||||
};
|
||||
|
||||
const onBlur = () => {
|
||||
localData.focused = false;
|
||||
props.eventUpdate({
|
||||
value: localData.value,
|
||||
align: localData.align,
|
||||
level: localData.level,
|
||||
});
|
||||
};
|
||||
|
||||
const onKeydown = ($event: KeyboardEvent) => {
|
||||
if ($event.key === 'Enter' && !$event.shiftKey) {
|
||||
const id = generateBlockId();
|
||||
props.eventAppendBlock({
|
||||
id,
|
||||
name: 'sb-paragraph',
|
||||
data: getDefaultParagraphData(),
|
||||
});
|
||||
|
||||
activate(id);
|
||||
|
||||
$event.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
const onKeyup = ($event: KeyboardEvent) => {
|
||||
if ($event.key === 'Backspace' && localData.value === '') {
|
||||
props.eventRemoveSelf();
|
||||
}
|
||||
|
||||
const selection = window.getSelection();
|
||||
const node = selection?.focusNode;
|
||||
const childNodes = Array.from(inputEl?.value?.childNodes || []);
|
||||
const index = node ? childNodes.indexOf(node as ChildNode) : -1;
|
||||
if (node === inputEl.value || index === 0 || index === childNodes.length -1) {
|
||||
switch ($event.key) {
|
||||
case 'ArrowDown':
|
||||
props.eventActivateNext();
|
||||
break;
|
||||
case 'ArrowUp':
|
||||
props.eventActivatePrevious();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return () => (
|
||||
<div class={classes.value}>
|
||||
<SbToolbar>
|
||||
<SbSelect
|
||||
{...{
|
||||
value: localData.level,
|
||||
onChange: setLevel,
|
||||
}}
|
||||
>
|
||||
<option value={1}>h1</option>
|
||||
<option value={2}>h2</option>
|
||||
<option value={3}>h3</option>
|
||||
<option value={4}>h4</option>
|
||||
<option value={5}>h5</option>
|
||||
<option value={6}>h6</option>
|
||||
</SbSelect>
|
||||
<SbSelect
|
||||
{...{
|
||||
value: localData.align,
|
||||
onChange: setAlignment,
|
||||
}}
|
||||
>
|
||||
<option>left</option>
|
||||
<option>center</option>
|
||||
<option>right</option>
|
||||
</SbSelect>
|
||||
</SbToolbar>
|
||||
<p
|
||||
class="sb-heading__input"
|
||||
ref={inputEl}
|
||||
contenteditable
|
||||
onInput={onTextUpdate}
|
||||
onFocus={onFocus}
|
||||
onBlur={onBlur}
|
||||
onKeydown={onKeydown}
|
||||
onKeyup={onKeyup}
|
||||
></p>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
import { defineAsyncComponent } from 'vue';
|
||||
import { IBlockDefinition } from '@schlechtenburg/core';
|
||||
import { getDefaultData } from './util';
|
||||
|
||||
export * from './util';
|
||||
export const name = 'sb-heading';
|
||||
|
||||
export default {
|
||||
name: 'sb-heading',
|
||||
name,
|
||||
getDefaultData,
|
||||
edit: defineAsyncComponent(() => import('./edit')),
|
||||
display: defineAsyncComponent(() => import('./edit')),
|
||||
};
|
||||
view: defineAsyncComponent(() => import('./view')),
|
||||
} as IBlockDefinition;
|
||||
|
|
40
packages/heading/lib/style.scss
Normal file
40
packages/heading/lib/style.scss
Normal file
|
@ -0,0 +1,40 @@
|
|||
.sb-heading {
|
||||
flex-basis: 100%;
|
||||
font-weight: bold;
|
||||
line-height: 1.2;
|
||||
|
||||
&_1 {
|
||||
font-size: 4rem;
|
||||
}
|
||||
|
||||
&_2 {
|
||||
font-size: 3rem;
|
||||
}
|
||||
|
||||
&_3 {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
&_4 {
|
||||
font-size: 1.6rem;
|
||||
}
|
||||
|
||||
&_5 {
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
&_6 {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
&__input {
|
||||
display: block;
|
||||
flex-basis: 100%;
|
||||
}
|
||||
|
||||
&_align {
|
||||
&-left { &, .sb-heading__input { text-align: left; } }
|
||||
&-right { &, .sb-heading__input { text-align: right; } }
|
||||
&-center { &, .sb-heading__input { text-align: center; } }
|
||||
}
|
||||
}
|
|
@ -1,2 +1,11 @@
|
|||
export const a = 1;
|
||||
export const getDefaultData = () => ({});
|
||||
export interface IHeadingData {
|
||||
value: string;
|
||||
align: string;
|
||||
level: number;
|
||||
}
|
||||
|
||||
export const getDefaultData: () => IHeadingData = () => ({
|
||||
value: '',
|
||||
align: 'left',
|
||||
level: 1,
|
||||
});
|
||||
|
|
44
packages/heading/lib/view.ts
Normal file
44
packages/heading/lib/view.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import {
|
||||
defineComponent,
|
||||
computed,
|
||||
PropType,
|
||||
h,
|
||||
} from 'vue';
|
||||
import {
|
||||
model,
|
||||
} from '@schlechtenburg/core';
|
||||
import {
|
||||
getDefaultData,
|
||||
IHeadingData,
|
||||
} from './util';
|
||||
|
||||
import './style.scss';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'sb-heading-display',
|
||||
|
||||
model,
|
||||
|
||||
props: {
|
||||
data: {
|
||||
type: Object as PropType<IHeadingData>,
|
||||
default: getDefaultData,
|
||||
},
|
||||
},
|
||||
|
||||
setup(props) {
|
||||
const classes = computed(() => ({
|
||||
'sb-heading': true,
|
||||
[`sb-heading_align-${props.data.align}`]: true,
|
||||
[`sb-heading_${props.data.level}`]: true,
|
||||
}));
|
||||
|
||||
return () => h(
|
||||
`h${props.data.level}`,
|
||||
{
|
||||
class: classes.value,
|
||||
innerHTML: props.data.value,
|
||||
},
|
||||
);
|
||||
},
|
||||
});
|
1510
packages/heading/package-lock.json
generated
1510
packages/heading/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -4,14 +4,15 @@
|
|||
"description": "> TODO: description",
|
||||
"author": "Benjamin Bädorf <hello@benjaminbaedorf.eu>",
|
||||
"homepage": "",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"main": "lib/index.ts",
|
||||
"directories": {
|
||||
"lib": "lib",
|
||||
"test": "__tests__"
|
||||
"doc": "docs",
|
||||
"lib": "lib"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
"lib",
|
||||
"docs"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
|
@ -21,10 +22,20 @@
|
|||
"url": "git@git.b12f.io:b12f/schlechtenburg.git"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "npm run json-to-md:watch",
|
||||
"typecheck": "vuedx-typecheck --no-pretty ./lib",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"vue": "^3.2.31"
|
||||
},
|
||||
"dependencies": {
|
||||
"@schlechtenburg/core": "^0.0.0",
|
||||
"vue": "^3.0.4"
|
||||
"@schlechtenburg/paragraph": "^0.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vuedx/typecheck": "^0.6.3",
|
||||
"@vuedx/typescript-plugin-vue": "^0.6.3",
|
||||
"vue": "^3.2.31"
|
||||
}
|
||||
}
|
||||
|
|
9
packages/heading/tsconfig.json
Normal file
9
packages/heading/tsconfig.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": [
|
||||
"lib/**/*.ts",
|
||||
"lib/**/*.d.ts",
|
||||
"lib/**/*.tsx",
|
||||
"lib/**/*.vue"
|
||||
]
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
const image = require('..');
|
||||
|
||||
describe('@schlechtenburg/image', () => {
|
||||
it('needs tests');
|
||||
});
|
16
packages/image/__tests__/image.test.ts
Normal file
16
packages/image/__tests__/image.test.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { describe, expect, it } from 'vitest'
|
||||
import { mount } from '@vue/test-utils';
|
||||
import SbImageEdit from '../lib/edit';
|
||||
import SbImageView from '../lib/view';
|
||||
|
||||
describe('@schlechtenburg/image', () => {
|
||||
it('edit should render', () => {
|
||||
const edit = mount(SbImageEdit);
|
||||
expect(edit.find('figure').element).toBeTruthy();
|
||||
expect(edit.find('div.sb-toolbar').element).toBeTruthy();
|
||||
});
|
||||
it('view should render', () => {
|
||||
const edit = mount(SbImageView);
|
||||
expect(edit.find('img').element).toBeTruthy();
|
||||
});
|
||||
});
|
1
packages/image/docs/components.json
Normal file
1
packages/image/docs/components.json
Normal file
|
@ -0,0 +1 @@
|
|||
[]
|
1173
packages/image/docs/lib.json
Normal file
1173
packages/image/docs/lib.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -8,16 +8,16 @@ import {
|
|||
} from 'vue';
|
||||
import {
|
||||
model,
|
||||
blockProps,
|
||||
SbToolbar,
|
||||
SbButton,
|
||||
SbBlock
|
||||
SbBlock,
|
||||
IBlockData,
|
||||
OnUpdateSelfCb,
|
||||
} from '@schlechtenburg/core';
|
||||
|
||||
import { IParagraphData } from '@schlechtenburg/paragraph';
|
||||
import {
|
||||
getDefaultData,
|
||||
ImageData,
|
||||
ImageProps,
|
||||
IImageData,
|
||||
} from './util';
|
||||
|
||||
import './style.scss';
|
||||
|
@ -28,15 +28,17 @@ export default defineComponent({
|
|||
model,
|
||||
|
||||
props: {
|
||||
...blockProps,
|
||||
eventUpdate: { type: Function, default: () => {} },
|
||||
eventUpdate: {
|
||||
type: (null as unknown) as PropType<OnUpdateSelfCb<IImageData>>,
|
||||
default: () => {},
|
||||
},
|
||||
data: {
|
||||
type: (null as unknown) as PropType<ImageData>,
|
||||
type: (null as unknown) as PropType<IImageData>,
|
||||
default: getDefaultData,
|
||||
},
|
||||
},
|
||||
|
||||
setup(props: ImageProps) {
|
||||
setup(props) {
|
||||
const localData = reactive({
|
||||
src: props.data.src,
|
||||
alt: props.data.alt,
|
||||
|
@ -61,8 +63,13 @@ export default defineComponent({
|
|||
if (fileInput.value && fileInput.value.files && fileInput.value.files.length) {
|
||||
const reader = new FileReader();
|
||||
reader.addEventListener('load', () => {
|
||||
const src = reader?.result?.toString();
|
||||
if (!src) {
|
||||
throw new Error('Couldn\'t load image src');
|
||||
}
|
||||
|
||||
props.eventUpdate({
|
||||
src: reader.result,
|
||||
src,
|
||||
alt: props.data.alt,
|
||||
description: props.data.description,
|
||||
});
|
||||
|
@ -72,7 +79,7 @@ export default defineComponent({
|
|||
}
|
||||
};
|
||||
|
||||
const onDescriptionUpdate = (description) => {
|
||||
const onDescriptionUpdate = (description: IBlockData<IParagraphData>) => {
|
||||
props.eventUpdate({
|
||||
...props.data,
|
||||
description,
|
||||
|
@ -83,7 +90,7 @@ export default defineComponent({
|
|||
<figure class="sb-image">
|
||||
<SbToolbar>
|
||||
{localData.src
|
||||
? <SbButton onClick={selectImage}>Change Image</SbButton>
|
||||
? <SbButton {...{ onClick: selectImage }}>Select Image</SbButton>
|
||||
: null}
|
||||
<input
|
||||
type="file"
|
||||
|
@ -101,10 +108,11 @@ export default defineComponent({
|
|||
/>
|
||||
<SbBlock
|
||||
block={localData.description}
|
||||
eventUpdate={(updated: Block) => onDescriptionUpdate(updated)}
|
||||
onUpdate={(updated: IBlockData<IParagraphData>) => onDescriptionUpdate(updated)}
|
||||
/>
|
||||
</>
|
||||
: <SbButton onClick={selectImage}>Select Image</SbButton>}
|
||||
: <SbButton {...{ onClick: selectImage }}>Select Image</SbButton>
|
||||
}
|
||||
</figure>
|
||||
);
|
||||
},
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
import { defineAsyncComponent } from 'vue';
|
||||
import { getDefaultData } from './util';
|
||||
|
||||
export * from './util';
|
||||
export const name = 'sb-image';
|
||||
|
||||
export default {
|
||||
name: 'sb-image',
|
||||
name,
|
||||
getDefaultData,
|
||||
edit: defineAsyncComponent(() => import('./edit')),
|
||||
display: defineAsyncComponent(() => import('./display')),
|
||||
view: defineAsyncComponent(() => import('./view')),
|
||||
};
|
||||
|
|
|
@ -1,22 +1,25 @@
|
|||
import {
|
||||
ParagraphData,
|
||||
IBlockData,
|
||||
generateBlockId,
|
||||
} from '@schlechtenburg/core';
|
||||
import {
|
||||
name as paragraphName,
|
||||
IParagraphData,
|
||||
getDefaultData as getDefaultParagraphData
|
||||
} from '@schlechtenburg/paragraph';
|
||||
import { BlockData, BlockProps } from '/@/blocks';
|
||||
|
||||
export interface ImageData {
|
||||
export interface IImageData {
|
||||
src: string;
|
||||
alt: string;
|
||||
description: ParagraphData;
|
||||
description: IBlockData<IParagraphData>;
|
||||
}
|
||||
|
||||
export interface ImageProps extends BlockProps {
|
||||
data: ImageData;
|
||||
eventUpdate: (b?: BlockData) => void;
|
||||
}
|
||||
|
||||
export const getDefaultData: () => ImageData = () => ({
|
||||
export const getDefaultData: () => IImageData = () => ({
|
||||
src: '',
|
||||
alt: '',
|
||||
description: getDefaultParagraphData(),
|
||||
description: {
|
||||
id: generateBlockId(),
|
||||
name: paragraphName,
|
||||
data: getDefaultParagraphData(),
|
||||
},
|
||||
});
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue