Compare commits

..

2 commits

Author SHA1 Message Date
Benjamin Bädorf 44cef9309f
move to docs package 2021-03-10 00:29:50 +01:00
Benjamin Bädorf eec847ed92
Remove docs 2021-03-09 21:26:17 +01:00
126 changed files with 3425 additions and 52954 deletions

2
.envrc
View file

@ -1,2 +0,0 @@
watch_file shell.nix
use nix

4
.gitignore vendored
View file

@ -1,9 +1,7 @@
.direnv
node_modules
.DS_Store
dist
dist-ssr
*.local
tags
.temp
.cache
yarn-error.log

View file

@ -1,660 +0,0 @@
### 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/>.

View file

@ -1,29 +0,0 @@
import { defineConfig } from 'vitepress';
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' },
]
}
]
}
});

View file

@ -1,41 +0,0 @@
.example-editor {
display: flex;
flex-direction: column;
&--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;
}
}

View file

@ -1,102 +0,0 @@
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>;
};
},
});

View file

@ -1,51 +0,0 @@
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>;
},
});

File diff suppressed because it is too large Load diff

View file

@ -1,3 +0,0 @@
# Example blocks
As Schlechtenburg is still in active development, it's good to check out the official blocks to see what they look like.

View file

@ -1,23 +0,0 @@
# 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>;
```

File diff suppressed because one or more lines are too long

View file

@ -1,20 +0,0 @@
<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>

View file

@ -1,19 +0,0 @@
---
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
---

View file

@ -1,120 +0,0 @@
# 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,
]}
/>;
}
```

View file

@ -1,72 +0,0 @@
*,
*::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;
}
}

View file

@ -1,21 +0,0 @@
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');

View file

@ -1,16 +0,0 @@
---
layout: page
---
<script setup>
import { withBase } from 'vitepress';
import ExampleEditor from './ExampleEditor';
</script>
<div class="sb-doc">
# Example Schlechtenburg Editor
</div>
<ExampleEditor></ExampleEditor>

View file

@ -1 +0,0 @@
# Usage

View file

@ -1,18 +0,0 @@
import { defineConfig } from 'vite';
import vueJsx from '@vitejs/plugin-vue-jsx'
import { join } from 'path';
export default defineConfig({
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'),
},
},
});

View file

@ -1,81 +0,0 @@
# 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.

View file

@ -1,4 +0,0 @@
## 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.

15684
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -2,23 +2,8 @@
"name": "schlechtenburg",
"version": "0.0.0",
"license": "GPL-3.0-or-later",
"scripts": {
"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"
},
"scripts": {},
"devDependencies": {
"@vitejs/plugin-vue-jsx": "^2.0.0",
"lerna": "^3.22.1",
"sass": "^1.54.4",
"typedoc": "^0.22.13",
"typescript": "^4.6.2",
"vitepress": "^1.0.0-alpha.13",
"vue": "^3.2.37"
},
"dependencies": {
"lodash-es": "^4.17.21"
"lerna": "^3.22.1"
}
}

View file

@ -1,298 +0,0 @@
[
{
"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": {}
}
]

File diff suppressed because it is too large Load diff

242
packages/core/lib/ResizeObserver.d.ts vendored Normal file
View file

@ -0,0 +1,242 @@
/**
* 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;
}

View file

@ -5,22 +5,21 @@
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,
&_active:hover {
z-index: 1;
&_active {
outline: 4px solid var(--interact);
> * > .sb-toolbar {

View file

@ -6,117 +6,44 @@ import {
ref,
Ref,
} from 'vue';
import {
IBlockData,
OnUpdateBlockCb,
OnActivateNextCb,
OnRemoveSelfCb,
OnAppendBlockCb,
OnPrependBlockCb,
OnActivatePreviousCb,
} from '../types';
import { BlockData } from '../types';
import { SbMode } from '../mode';
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 SbMissingBlock from './MissingBlock';
import './Block.scss';
/**
* 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',
directives: {
hoverCover,
},
props: {
/**
* The state for the block.
*/
block: {
type: (null as unknown) as PropType<IBlockData<any>>,
type: (null as unknown) as PropType<BlockData<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: () => () => {},
sortable: {
type: String,
default: null,
},
onUpdate: { type: Function, default: () => {} },
onPrependBlock: { type: Function, default: () => {} },
onAppendBlock: { type: Function, default: () => {} },
onRemoveSelf: { type: Function, default: () => {} },
onActivatePrevious: { type: Function, default: () => {} },
onActivateNext: { type: Function, default: () => {} },
},
setup(props, context) {
const el: Ref<null|HTMLElement> = ref(null);
const { mode, getBlock } = useDynamicBlocks();
const {
isActive,
activate,
} = useActivation(props.block.id);
const classes = computed(() => ({
'sb-block': true,
'sb-block_active': isActive.value,
}));
const { triggerSizeCalculation } = useResizeObserver(el, SymBlockDimensions);
watch(() => props.block.data, triggerSizeCalculation);
const classes = computed(() => ({ 'sb-block': true }));
const { register } = useBlockTree();
register(props.block, props.indexAsChild);
watch(props.block, () => { register(props.block, props.indexAsChild); });
register(props.block);
watch(props.block, () => { register(props.block); });
const eventChildUpdate = (updated: {[key: string]: any}) => {
props.eventUpdate({
const onChildUpdate = (updated: {[key: string]: any}) => {
props.onUpdate({
...props.block,
data: {
...props.block.data,
@ -136,7 +63,7 @@ export const SbBlock = defineComponent({
/>;
}
if (mode.value === SbMode.View) {
if (mode.value === SbMode.Display) {
return <BlockComponent
data={props.block.data}
blockId={props.block.id}
@ -146,29 +73,20 @@ export const SbBlock = defineComponent({
return <div
ref={el}
class={classes.value}
v-hover-cover
>
{
/**
* 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.id}
eventUpdate={eventChildUpdate}
eventPrependBlock={props.eventPrependBlock}
eventAppendBlock={props.eventAppendBlock}
eventRemoveSelf={props.eventRemoveSelf}
eventActivatePrevious={props.eventActivatePrevious}
eventActivateNext={props.eventActivateNext}
onUpdate={onChildUpdate}
onPrependBlock={props.onPrependBlock}
onAppendBlock={props.onAppendBlock}
onRemoveSelf={props.onRemoveSelf}
onActivatePrevious={props.onActivatePrevious}
onActivateNext={props.onActivateNext}
{...{
onClick: ($event: MouseEvent) => {
$event.stopPropagation();
activate();
},
...context.attrs,
}}

View file

@ -1,4 +1,4 @@
import debounce from 'lodash/debounce';
import { debounce } from 'lodash-es';
import {
watch,
reactive,
@ -19,9 +19,9 @@ export const SbBlockOrdering = defineComponent({
type: String,
default: null,
},
eventRemove: { type: Function, default: () => {} },
eventMoveBackward: { type: Function, default: () => {} },
eventMoveForward: { type: Function, default: () => {} },
onRemove: { type: Function, default: () => {} },
onMoveBackward: { type: Function, default: () => {} },
onMoveForward: { type: Function, default: () => {} },
},
setup(props) {
@ -55,9 +55,9 @@ export const SbBlockOrdering = defineComponent({
style={styles}
onClick={($event: MouseEvent) => $event.stopPropagation()}
>
<SbButton {...{onClick: props.eventMoveBackward}}>{props.orientation === 'vertical' ? '↑' : '←'}</SbButton>
<SbButton {...{onClick: props.eventRemove}}>x</SbButton>
<SbButton {...{onClick: props.eventMoveForward}}>{props.orientation === 'vertical' ? '↓' : '→'}</SbButton>
<SbButton {...{onClick: props.onMoveBackward}}>{props.orientation === 'vertical' ? '↑' : '←'}</SbButton>
<SbButton {...{onClick: props.onRemove}}>x</SbButton>
<SbButton {...{onClick: props.onMoveForward}}>{props.orientation === 'vertical' ? '↓' : '→'}</SbButton>
</div>
);
},

View file

@ -1,4 +1,10 @@
.sb-block-picker {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
&__add-button {
padding: 24px 32px;
}

View file

@ -4,11 +4,10 @@ import {
defineComponent,
} from 'vue';
import { useDynamicBlocks } from '../use-dynamic-blocks';
import { IBlockDefinition } from '../types';
import { generateBlockId } from '../block-helpers';
import { BlockDefinition } from '../types';
import { SbButton } from './Button';
import { SbContextMenu, IContextMenuSlotContext } from './ContextMenu';
import { SbModal } from './Modal';
import './BlockPicker.scss';
@ -16,45 +15,52 @@ export const SbBlockPicker = defineComponent({
name: 'sb-block-picker',
props: {
eventPickedBlock: { type: Function, default: () => {} },
onPickedBlock: { type: Function, default: () => {} },
},
setup(props, context) {
setup(props) {
const open = ref(false);
const { customBlocks } = useDynamicBlocks();
const blockList = computed(() => Object.keys(customBlocks).map((key) => customBlocks[key]));
const selectBlock = (block: IBlockDefinition<any>) => {
const selectBlock = (block: BlockDefinition<any>) => () => {
open.value = false;
props.eventPickedBlock({
props.onPickedBlock({
name: block.name,
id: generateBlockId(),
id: `${+(new Date())}`,
data: block.getDefaultData(),
});
};
return () => (
<div class="sb-block-picker">
<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
class="sb-block-picker__add-button"
{...{
type: 'button',
onClick: ($event: MouseEvent) => {
open.value = true;
$event.stopPropagation();
},
}}
>+</SbButton>
<SbModal
open={open.value}
onClose={() => {
open.value = false;
}}
{...{ onClick: ($event: MouseEvent) => $event.stopPropagation() }}
>
{...blockList.value.map((block: BlockDefinition<any>) => (
<SbButton
{...{
type: 'button',
onClick: () => {
selectBlock(block);
close();
},
onClick: () => selectBlock(block),
}}
>{block.name}</SbButton>)),
}}
></SbContextMenu>
>{block.name}</SbButton>
))}
</SbModal>
</div>
);
},

View file

@ -1,6 +1,5 @@
.sb-block-placeholder {
flex-basis: 100%;
flex-shrink: 2;
width: 100%;
position: relative;
overflow: visible;
@ -8,12 +7,4 @@
background-color: var(--grey-1);
width: 100%;
}
.sb-block-picker {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
}
}

View file

@ -1,30 +1,22 @@
import { defineComponent } from 'vue';
import { IBlockData } from '../types';
import { BlockData } 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',
props: {
/**
* Called when the user picked a block that should be inserted here.
*/
eventInsertBlock: { type: Function, default: () => {} },
onInsertBlock: { type: Function, default: () => {} },
},
setup(props) {
return () => (
<div class="sb-block-placeholder">
<SbBlockPicker
eventPickedBlock={(block: IBlockData<any>) => props.eventInsertBlock(block)}
onPickedBlock={(block: BlockData<any>) => props.onInsertBlock(block)}
/>
</div>
);

View file

@ -2,10 +2,6 @@ import { defineComponent } from 'vue';
import './Button.scss';
/**
* A button in the schlechtenburg theme
* @sbui
*/
export const SbButton = defineComponent({
name: 'sb-button',
@ -19,13 +15,7 @@ export const SbButton = defineComponent({
class: (context.attrs.class || '') + ' sb-button',
}}
>
{
/**
* The button contents
* @slot default
*/
context.slots.default?.()
}
{context.slots.default?.()}
</button>
);
},

View file

@ -10,7 +10,6 @@
top: 100%;
left: 0;
margin: 0;
padding: 0.5rem 0.25rem;
z-index: var(--z-context-menu);
max-height: 70vh;

View file

@ -2,19 +2,11 @@ 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',

View file

@ -1,35 +1,5 @@
.sb-main {
position: relative;
color: var(--fg);
background-color: var(--bg);
--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;
--z-toolbar: 2000;
--z-context-menu: 3000;
--z-tree-block-select: 4000;
--z-modal: 10000;
*,
*::before,
*::after {
box-sizing: border-box;
}
padding: 50px 40px;
}

View file

@ -3,19 +3,17 @@ import {
provide,
shallowReactive,
ref,
watch,
PropType,
Ref,
} from 'vue';
import {
IBlockData,
IBlockDefinition,
IBlockLibrary,
ITreeNode,
OnUpdateBlockCb,
BlockData,
BlockDefinition,
BlockLibrary,
TreeNode,
} from '../types';
import { model } from '../block-helpers';
import { SymMode, SbMode } from '../mode';
import { Mode, SbMode } from '../mode';
import { SymBlockLibrary} from '../use-dynamic-blocks';
import {
SymBlockTree,
@ -23,42 +21,24 @@ import {
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>[]>,
customBlocks: {
type: Array as PropType<BlockDefinition<any>[]>,
default: () => [],
},
block: {
type: Object as PropType<IBlockData<any>>,
type: Object as PropType<BlockData<any>>,
required: true,
},
/**
* Called when the block should be updated.
*/
eventUpdate: {
type: (null as unknown) as PropType<OnUpdateBlockCb>,
default: () => {},
},
onUpdate: { type: Function, default: () => {} },
mode: {
type: String as PropType<SbMode>,
validator(value: any) {
@ -68,28 +48,21 @@ export const SbMain = defineComponent({
},
},
setup(props: ISbMainProps) {
setup(props: any) { // TODO: why does the typing of props not work here?
const el: Ref<null|HTMLElement> = ref(null);
useResizeObserver(el, SymEditorDimensions);
const mode = ref(props.mode);
provide(SymMode, mode);
provide(Mode, mode);
watch(() => props.mode, (newMode) => {
mode.value = newMode;
});
const activeBlock = ref(null);
provide(SymActiveBlock, activeBlock);
const blockTree: Ref<ITreeNode|null> = ref(null);
const blockTree: Ref<TreeNode|null> = ref(null);
provide(SymBlockTree, blockTree);
provide(SymBlockTreeRegister, (block: ITreeNode) => { blockTree.value = block; });
provide(SymBlockTreeRegister, (block: TreeNode) => { blockTree.value = block; });
provide(SymBlockTreeUnregister, () => { blockTree.value = null; });
const blockLibrary: IBlockLibrary = shallowReactive({
...props.availableBlocks.reduce(
(blocks: IBlockLibrary, block: IBlockDefinition<any>) => ({ ...blocks, [block.name]: block }),
const blockLibrary: BlockLibrary = shallowReactive({
...props.customBlocks.reduce(
(blocks: BlockLibrary, block: BlockDefinition<any>) => ({ ...blocks, [block.name]: block }),
{},
),
});
@ -101,17 +74,9 @@ export const SbMain = defineComponent({
class="sb-main"
ref={el}
>
{
mode.value === SbMode.Edit
? <>
<SbMainMenu block={props.block} />
<SbBlockToolbar />
</>
: null
}
<SbBlock
block={props.block}
eventUpdate={props.eventUpdate}
onUpdate={props.onUpdate}
/>
</div>
);

View file

@ -1,5 +1,2 @@
.sb-main-menu {
display: flex;
padding-bottom: 4rem;
background-color: var(--grey-0);
}

View file

@ -2,7 +2,7 @@ import {
defineComponent,
PropType,
} from 'vue';
import { IBlockData } from '../types';
import { BlockData } from '../types';
import { SbTreeBlockSelect } from './TreeBlockSelect';
import './MainMenu.scss';
@ -12,7 +12,7 @@ export const SbMainMenu = defineComponent({
props: {
block: {
type: (null as unknown) as PropType<IBlockData<any>>,
type: (null as unknown) as PropType<BlockData<any>>,
required: true,
},
},

View file

@ -2,6 +2,6 @@ import { defineAsyncComponent } from 'vue';
export default {
name: 'sb-missing-block',
edit: defineAsyncComponent(() => import('./view')),
view: defineAsyncComponent(() => import('./view')),
edit: defineAsyncComponent(() => import('./display')),
display: defineAsyncComponent(() => import('./display')),
};

View file

@ -2,7 +2,7 @@
&__overlay {
background-color: var(--grey-3-t);
position: fixed;
z-index: var(--z-modal);
z-index: 10;
top: 0;
left: 0;
bottom: 0;

View file

@ -2,7 +2,6 @@
background-color: var(--grey-0);
border: 1px solid var(--grey-2);
position: relative;
font-size: 1rem;
&:hover {
border: 1px solid var(--interact);

View file

@ -1,10 +1,6 @@
import { defineComponent } from 'vue';
import './Select.scss';
/**
* A select input in the schlechtenburg theme
* @sbui
*/
export const SbSelect = defineComponent({
name: 'sb-select',
@ -17,13 +13,7 @@ export const SbSelect = defineComponent({
class="sb-select__input"
{...context.attrs}
>
{
/**
* The select options list
* @slot default
*/
context.slots.default?.()
}
{context.slots.default?.()}
</select>
</div>
);

View file

@ -2,7 +2,4 @@
position: absolute;
width: auto;
height: auto;
display: flex;
flex-wrap: wrap;
z-index: var(--z-toolbar);
}

View file

@ -1,4 +1,4 @@
import debounce from 'lodash/debounce';
import { debounce } from 'lodash-es';
import {
defineComponent,
watch,
@ -8,10 +8,6 @@ import { useBlockSizing } from '../use-resize-observer';
import './Toolbar.scss';
/**
* Toolbar in the schlechtenburg theme
* @sbui
*/
export const SbToolbar = defineComponent({
name: 'sb-toolbar',
@ -42,13 +38,7 @@ export const SbToolbar = defineComponent({
style={styles}
onClick={($event: MouseEvent) => $event.stopPropagation()}
>
{
/**
* The toolbar contents
* @slot default
*/
context.slots.default?.()
}
{context.slots?.default?.()}
</div>
);
},

View file

@ -1,7 +1,6 @@
.sb-tree-block-select {
&__list {
list-style: none;
color: var(--fg);
margin: 0;
padding: 0;
@ -10,6 +9,9 @@
}
}
&__node {
}
&__block {
padding: 0;
margin: 0;
@ -21,7 +23,7 @@
border: 0;
font: inherit;
color: inherit;
padding: 0.25rem 0.5rem;
padding: 0.5rem 1rem;
width: 100%;
text-align: left;
}

View file

@ -1,5 +1,5 @@
import { defineComponent } from 'vue';
import { ITreeNode } from '../types';
import { TreeNode } from '../types';
import { useBlockTree } from '../use-block-tree';
import { useActivation } from '../use-activation';
@ -18,7 +18,7 @@ export const SbTreeBlockSelect = defineComponent({
activeBlockId,
} = useActivation();
const treeToHtml = (tree: ITreeNode, close: Function) => <li
const treeToHtml = (tree: TreeNode, close: Function) => <li
class={{
'sb-tree-block-select__block': true,
'sb-tree-block-select__block_active': activeBlockId.value === tree.id,
@ -34,13 +34,12 @@ export const SbTreeBlockSelect = defineComponent({
>{tree.name}</button>
{tree.children?.length
? <ul class="sb-tree-block-select__list">
{tree.children?.map((child: ITreeNode) => treeToHtml(child, close))}
{tree.children?.map((child: TreeNode) => treeToHtml(child, close))}
</ul>
: null
}
</li>;
return () => (
blockTree.value
? <SbContextMenu
@ -49,7 +48,7 @@ export const SbTreeBlockSelect = defineComponent({
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>,
>{treeToHtml(blockTree.value as TreeNode, close)}</ul>,
}}
/>
: ''

View file

@ -0,0 +1,3 @@
export default {
};

View file

@ -1,9 +0,0 @@
.sb-hover-cover {
&:hover {
outline: 1px dashed var(--interact);
}
&_child-hovered:hover {
outline: none;
}
}

View file

@ -1,64 +0,0 @@
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)
},
};

View file

@ -7,6 +7,8 @@ export * from './use-activation';
export * from './use-dynamic-blocks';
export * from './use-resize-observer';
export * from './directives/activation-cover.js';
export * from './components/Main';
export * from './components/Block';
export * from './components/BlockPicker';

View file

@ -1,8 +1,5 @@
/**
* The mode the Schlechtenburg editor is currently in
*/
export enum SbMode {
Edit = 'edit',
View = 'view',
Display = 'display',
}
export const SymMode = Symbol('Schlechtenburg mode');
export const Mode = Symbol('Schlechtenburg mode');

View file

@ -1,172 +1,37 @@
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 {
export interface TreeNode {
id: string;
name: string;
icon?: string;
children: ITreeNode[];
children: TreeNode[];
}
/**
* 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> {
export interface BlockData<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;
export interface BlockProps<T> {
blockId: string;
data?: T,
eventUpdate?: OnUpdateSelfCb<T>;
eventPrependBlock?: OnPrependBlockCb;
eventAppendBlock?: OnAppendBlockCb;
eventRemoveSelf?: OnRemoveSelfCb;
eventActivateNext?: OnActivateNextCb;
eventActivatePrevious?: OnActivatePreviousCb;
onUpdate?: (b?: BlockData<T>) => void;
onPrependBlock?: (b?: BlockData<T>) => void;
onAppendBlock?: (b?: BlockData<T>) => void;
onRemoveSelf?: () => void;
onActivateNext?: () => void;
onActivatePrevious?: () => void;
}
/**
* Any Block that you create
*
* @see IBlockProps
*/
export interface IBlockDefinition<T> {
export interface BlockDefinition<T> {
name: string;
icon?: string;
getDefaultData: T;
edit: Component<IBlockProps<T>>;
view: Component<IBlockProps<T>>;
edit: Component<BlockProps<T>>;
display: Component<BlockProps<T>>;
}
/**
* Schlechtenburg maintains a library of blocks that are available
*
* @internal
*/
export interface IBlockLibrary {
[name: string]: IBlockDefinition<any>;
export interface BlockLibrary {
[name: string]: BlockDefinition<any>;
}

View file

@ -3,34 +3,15 @@ import {
ref,
inject,
computed,
onBeforeUnmount,
} from 'vue';
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 deactivate = (id: string|null = currentBlockId) => {
if (activeBlockId.value !== id) {
return;
}
activeBlockId.value = null;
const activate = (id?: string|null) => {
activeBlockId.value = id !== undefined ? id : currentBlockId;
};
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;
@ -43,7 +24,6 @@ export function useActivation(currentBlockId: string|null = null) {
activeBlockId,
isActive,
activate,
deactivate,
requestActivation,
};
}

View file

@ -7,22 +7,20 @@ import {
onUnmounted,
} from 'vue';
import {
ITreeNode,
IBlockData,
TreeNode,
BlockData,
} 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 blockTree: Ref<TreeNode|null> = inject(SymBlockTree, ref(null));
const registerWithParent = inject(SymBlockTreeRegister, (_: TreeNode) => {});
const unregisterWithParent = inject(SymBlockTreeUnregister, (_: TreeNode) => {});
const self: ITreeNode = reactive({
const self: TreeNode = reactive({
id: '',
name: '',
icon: '',
@ -30,45 +28,32 @@ export function useBlockTree() {
});
// Provide a registration function to child blocks
provide(SymBlockTreeRegister, (block: ITreeNode, index:number = -1) => {
if (self.children.find((child: ITreeNode) => child.id === block.id)) {
provide(SymBlockTreeRegister, (block: TreeNode) => {
if (self.children.find((child: TreeNode) => child.id === block.id)) {
return;
}
if (index < 0) {
}
const normalizedIndex = index < 0 ? 0 : index;
self.children =[
...self.children.slice(0, normalizedIndex),
self.children = [
...self.children,
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);
provide(SymBlockTreeUnregister, ({ id }: TreeNode) => {
self.children = self.children.filter((child: TreeNode) => child.id !== id);
});
const { mode } = useDynamicBlocks();
const register = (block: IBlockData<any>, index: number = 0) => {
const register = (block: BlockData<any>) => {
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);
registerWithParent(self);
}
// Unregister from parent when we get destroyed

View file

@ -3,13 +3,13 @@ import {
inject,
reactive,
} from 'vue';
import { IBlockLibrary } from './types';
import { SymMode, SbMode } from './mode';
import { BlockLibrary } from './types';
import { Mode, SbMode } from './mode';
export const SymBlockLibrary = Symbol('Schlechtenburg block library');
export function useDynamicBlocks() {
const mode = inject(SymMode, ref(SbMode.Edit));
const customBlocks: IBlockLibrary = inject(SymBlockLibrary, reactive({}));
const mode = inject(Mode, ref(SbMode.Edit));
const customBlocks: BlockLibrary = inject(SymBlockLibrary, reactive({}));
const getBlock = (name: string) => customBlocks[name];
return {

View file

@ -1,8 +1,9 @@
/// <reference types="resize-observer-browser" />
import {
Ref,
ref,
inject,
onBeforeMount,
watch,
provide,
} from 'vue';
@ -33,18 +34,16 @@ export function useResizeObserver(el: Ref<null|HTMLElement>, symbol: symbol) {
};
};
onBeforeMount(() => {
const resizeObserver = new ResizeObserver(triggerSizeCalculation);
const mutationObserver = new MutationObserver(triggerSizeCalculation);
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 };
}

File diff suppressed because it is too large Load diff

View file

@ -6,18 +6,12 @@
"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__"
},
"files": [
"lib",
"docs"
"lib"
],
"publishConfig": {
"access": "public"
@ -27,17 +21,13 @@
"url": "git@git.b12f.io:b12f/schlechtenburg.git"
},
"dependencies": {
"lodash": "^4.17.21",
"uuid": "^8.3.2"
},
"peerDependencies": {
"vue": "^3.2.31"
"lodash-es": "^4.17.21",
"uuid": "^8.3.2",
"vue": "^3.0.7"
},
"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.2.31"
"@types/resize-observer-browser": "^0.1.5",
"@types/uuid": "^8.3.0"
}
}

View file

@ -1,9 +0,0 @@
{
"extends": "../../tsconfig.json",
"include": [
"lib/**/*.ts",
"lib/**/*.d.ts",
"lib/**/*.tsx",
"lib/**/*.vue"
]
}

1
packages/docs/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/dist

11
packages/docs/README.md Normal file
View file

@ -0,0 +1,11 @@
# `@schlechtenburg/docs`
> TODO: description
## Usage
```
const docs = require('@schlechtenburg/docs');
// TODO: DEMONSTRATE API
```

View file

@ -0,0 +1,7 @@
'use strict';
const docs = require('..');
describe('@schlechtenburg/docs', () => {
it('needs tests');
});

13
packages/docs/index.html Normal file
View file

@ -0,0 +1,13 @@
<!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="/lib/main.ts"></script>
</body>
</html>

View file

@ -0,0 +1,6 @@
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: #2c3e50;
}

41
packages/docs/lib/App.tsx Normal file
View file

@ -0,0 +1,41 @@
import {
onBeforeMount,
defineComponent,
reactive,
} from 'vue';
import { SbMain, BlockData, SbMode } from '@schlechtenburg/core';
export default defineComponent({
name: 'App',
setup() {
const block: BlockData<any> = reactive({
name: 'none',
id: '0',
data: null,
});
onBeforeMount(async () => {
const res = await fetch('./initial-data.json');
const data = await res.json();
block.name = data.name;
block.id = data.id;
block.data = data.data;
});
return () => {
return <div id="app">
<SbMain
block={block}
onUpdate={(newBlock: BlockData<any>) => {
block.data = newBlock.data;
}}
customBlocks={[ ]}
key="edit"
mode={SbMode.Edit}
/>
</div>;
};
},
});

View file

@ -0,0 +1,7 @@
'use strict';
module.exports = docs;
function docs() {
// TODO
}

View file

@ -0,0 +1,32 @@
*,
*::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;
--z-context-menu: 3000;
}
body {
margin: 0;
min-height: 100vh;
}

View file

@ -0,0 +1,5 @@
import { createApp } from 'vue'
import App from './App';
import './main.scss';
createApp(App).mount('#app');

View file

@ -0,0 +1,46 @@
{
"name": "@schlechtenburg/docs",
"version": "0.0.0",
"description": "> TODO: description",
"author": "Benjamin Bädorf <hello@benjaminbaedorf.eu>",
"homepage": "",
"license": "GPL-3.0-or-later",
"main": "lib/index.ts",
"directories": {
"lib": "lib",
"test": "__tests__"
},
"files": [
"lib"
],
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git@git.b12f.io:b12f/schlechtenburg.git"
},
"scripts": {
"dev": "concurrently 'vuedx-typecheck --no-pretty --watch ./lib' 'vite'",
"build": "vuedx-typecheck --no-pretty ./lib && vite build"
},
"dependencies": {
"@schlechtenburg/core": "^0.0.0",
"@schlechtenburg/heading": "^0.0.0",
"@schlechtenburg/image": "^0.0.0",
"@schlechtenburg/layout": "^0.0.0",
"@schlechtenburg/paragraph": "^0.0.0",
"lodash-es": "^4.17.21",
"vue": "^3.0.7"
},
"devDependencies": {
"@vitejs/plugin-vue-jsx": "^1.1.2",
"@vue/compiler-sfc": "^3.0.7",
"@vuedx/typecheck": "^0.6.3",
"@vuedx/typescript-plugin-vue": "^0.6.3",
"concurrently": "^6.0.0",
"sass": "^1.32.8",
"typescript": "^4.2.3",
"vite": "^2.0.5"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,26 @@
import vueJsx from '@vitejs/plugin-vue-jsx';
export default {
base: './',
resolve: {
alias: {
'@schlechtenburg/core': '../core/lib/index.ts',
'@schlechtenburg/paragraph': '../paragraph/lib/index.ts',
'@schlechtenburg/heading': '../heading/lib/index.ts',
'@schlechtenburg/image': '../image/lib/index.ts',
'@schlechtenburg/layout': '../layout/lib/index.ts',
},
},
plugins: [
vueJsx({}),
],
esbuild: {
jsxFactory: 'h',
jsxFragment: 'Fragment',
},
build: {
minify: false,
sourcemap: true,
outDir: 'dist',
},
};

View file

@ -1 +0,0 @@
[]

File diff suppressed because it is too large Load diff

View file

@ -1,220 +1 @@
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>
);
},
});
export default {};

View file

@ -1,5 +1,4 @@
import { defineAsyncComponent } from 'vue';
import { IBlockDefinition } from '@schlechtenburg/core';
import { getDefaultData } from './util';
export * from './util';
@ -9,5 +8,5 @@ export default {
name,
getDefaultData,
edit: defineAsyncComponent(() => import('./edit')),
view: defineAsyncComponent(() => import('./view')),
} as IBlockDefinition;
display: defineAsyncComponent(() => import('./edit')),
};

View file

@ -1,40 +0,0 @@
.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; } }
}
}

View file

@ -1,11 +1,2 @@
export interface IHeadingData {
value: string;
align: string;
level: number;
}
export const getDefaultData: () => IHeadingData = () => ({
value: '',
align: 'left',
level: 1,
});
export const a = 1;
export const getDefaultData = () => ({});

View file

@ -1,44 +0,0 @@
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,
},
);
},
});

File diff suppressed because it is too large Load diff

View file

@ -11,8 +11,7 @@
"test": "__tests__"
},
"files": [
"lib",
"docs"
"lib"
],
"publishConfig": {
"access": "public"
@ -22,20 +21,10 @@
"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",
"@schlechtenburg/paragraph": "^0.0.0"
},
"devDependencies": {
"@vuedx/typecheck": "^0.6.3",
"@vuedx/typescript-plugin-vue": "^0.6.3",
"vue": "^3.2.31"
"vue": "^3.0.7"
}
}

View file

@ -1,9 +0,0 @@
{
"extends": "../../tsconfig.json",
"include": [
"lib/**/*.ts",
"lib/**/*.d.ts",
"lib/**/*.tsx",
"lib/**/*.vue"
]
}

View file

@ -1 +0,0 @@
[]

File diff suppressed because it is too large Load diff

View file

@ -5,7 +5,7 @@ import {
} from '@schlechtenburg/core';
import {
getDefaultData,
IImageData,
ImageData,
} from './util';
import './style.scss';
@ -17,7 +17,7 @@ export default defineComponent({
props: {
data: {
type: (null as unknown) as PropType<IImageData>,
type: (null as unknown) as PropType<ImageData>,
default: getDefaultData,
},
},

View file

@ -11,13 +11,12 @@ import {
SbToolbar,
SbButton,
SbBlock,
IBlockData,
OnUpdateSelfCb,
BlockData,
} from '@schlechtenburg/core';
import { IParagraphData } from '@schlechtenburg/paragraph';
import { ParagraphData } from '@schlechtenburg/paragraph';
import {
getDefaultData,
IImageData,
ImageData,
} from './util';
import './style.scss';
@ -28,12 +27,9 @@ export default defineComponent({
model,
props: {
eventUpdate: {
type: (null as unknown) as PropType<OnUpdateSelfCb<IImageData>>,
default: () => {},
},
onUpdate: { type: Function, default: () => {} },
data: {
type: (null as unknown) as PropType<IImageData>,
type: (null as unknown) as PropType<ImageData>,
default: getDefaultData,
},
},
@ -68,7 +64,7 @@ export default defineComponent({
throw new Error('Couldn\'t load image src');
}
props.eventUpdate({
props.onUpdate({
src,
alt: props.data.alt,
description: props.data.description,
@ -79,8 +75,8 @@ export default defineComponent({
}
};
const onDescriptionUpdate = (description: IBlockData<IParagraphData>) => {
props.eventUpdate({
const onDescriptionUpdate = (description: BlockData<ParagraphData>) => {
props.onUpdate({
...props.data,
description,
});
@ -108,7 +104,7 @@ export default defineComponent({
/>
<SbBlock
block={localData.description}
onUpdate={(updated: IBlockData<IParagraphData>) => onDescriptionUpdate(updated)}
onUpdate={(updated: BlockData<ParagraphData>) => onDescriptionUpdate(updated)}
/>
</>
: <SbButton {...{ onClick: selectImage }}>Select Image</SbButton>

View file

@ -8,5 +8,5 @@ export default {
name,
getDefaultData,
edit: defineAsyncComponent(() => import('./edit')),
view: defineAsyncComponent(() => import('./view')),
display: defineAsyncComponent(() => import('./display')),
};

View file

@ -1,20 +1,20 @@
import {
IBlockData,
BlockData,
generateBlockId,
} from '@schlechtenburg/core';
import {
name as paragraphName,
IParagraphData,
ParagraphData,
getDefaultData as getDefaultParagraphData
} from '@schlechtenburg/paragraph';
export interface IImageData {
export interface ImageData {
src: string;
alt: string;
description: IBlockData<IParagraphData>;
description: BlockData<ParagraphData>;
}
export const getDefaultData: () => IImageData = () => ({
export const getDefaultData: () => ImageData = () => ({
src: '',
alt: '',
description: {

File diff suppressed because it is too large Load diff

View file

@ -11,8 +11,7 @@
"test": "__tests__"
},
"files": [
"lib",
"docs"
"lib"
],
"publishConfig": {
"access": "public"
@ -22,20 +21,11 @@
"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",
"@schlechtenburg/paragraph": "^0.0.0"
},
"devDependencies": {
"@vuedx/typecheck": "^0.6.3",
"@vuedx/typescript-plugin-vue": "^0.6.3",
"vue": "^3.2.31"
"@schlechtenburg/paragraph": "^0.0.0",
"vue": "^3.0.7"
}
}

View file

@ -1,9 +0,0 @@
{
"extends": "../../tsconfig.json",
"include": [
"lib/**/*.ts",
"lib/**/*.d.ts",
"lib/**/*.tsx",
"lib/**/*.vue"
]
}

View file

@ -1 +0,0 @@
[]

File diff suppressed because it is too large Load diff

View file

@ -8,7 +8,7 @@ import {
SbBlock,
} from '@schlechtenburg/core';
import {
ILayoutData,
LayoutData,
getDefaultData,
} from './util';
@ -21,7 +21,7 @@ export default defineComponent({
props: {
data: {
type: (null as unknown) as PropType<ILayoutData>,
type: (null as unknown) as PropType<LayoutData>,
default: getDefaultData,
},
},

View file

@ -7,8 +7,7 @@ import {
} from 'vue';
import {
model,
IBlockData,
OnUpdateSelfCb,
BlockData,
useActivation,
SbBlock,
@ -19,7 +18,7 @@ import {
} from '@schlechtenburg/core';
import {
ILayoutData,
LayoutData,
getDefaultData,
} from './util';
@ -31,12 +30,9 @@ export default defineComponent({
model,
props: {
eventUpdate: {
type: (null as unknown) as PropType<OnUpdateSelfCb<ILayoutData>>,
default: () => {},
},
onUpdate: { type: Function, default: () => {} },
data: {
type: (null as unknown) as PropType<ILayoutData>,
type: (null as unknown) as PropType<LayoutData>,
default: getDefaultData,
},
},
@ -44,7 +40,7 @@ export default defineComponent({
setup(props) {
const { activate } = useActivation();
const localData: ILayoutData = reactive({
const localData: LayoutData = reactive({
orientation: props.data.orientation,
children: [...props.data.children],
});
@ -60,17 +56,17 @@ export default defineComponent({
}));
const toggleOrientation = () => {
props.eventUpdate({
props.onUpdate({
orientation: localData.orientation === 'vertical' ? 'horizontal' : 'vertical',
});
};
const onChildUpdate = (child: IBlockData<any>, updated: IBlockData<any>) => {
const onChildUpdate = (child: BlockData<any>, updated: BlockData<any>) => {
const index = localData.children.indexOf(child);
if (index === -1) {
return;
}
props.eventUpdate({
props.onUpdate({
children: [
...localData.children.slice(0, index),
{
@ -82,22 +78,22 @@ export default defineComponent({
});
};
const appendBlock = (block: IBlockData<any>) => {
const appendBlock = (block: BlockData<any>) => {
localData.children = [
...localData.children,
block,
];
props.eventUpdate({ children: [...localData.children] });
props.onUpdate({ children: [...localData.children] });
activate(block.id);
};
const insertBlock = (index: number, block: IBlockData<any>) => {
const insertBlock = (index: number, block: BlockData<any>) => {
localData.children = [
...localData.children.slice(0, index + 1),
block,
...localData.children.slice(index + 1),
];
props.eventUpdate({ children: [...localData.children] });
props.onUpdate({ children: [...localData.children] });
activate(block.id);
};
@ -106,7 +102,7 @@ export default defineComponent({
...localData.children.slice(0, index),
...localData.children.slice(index + 1),
];
props.eventUpdate({ children: [...localData.children] });
props.onUpdate({ children: [...localData.children] });
const newActiveIndex = Math.max(index - 1, 0);
activate(localData.children[newActiveIndex].id);
@ -138,7 +134,7 @@ export default defineComponent({
...localData.children.slice(index + 1),
];
props.eventUpdate({ children: [...localData.children] });
props.onUpdate({ children: [...localData.children] });
};
const moveForward = (index: number) => {
@ -155,7 +151,7 @@ export default defineComponent({
...localData.children.slice(index + 2),
];
props.eventUpdate({ children: [...localData.children] });
props.onUpdate({ children: [...localData.children] });
};
return () => (
@ -169,34 +165,31 @@ export default defineComponent({
>{localData.orientation}</SbButton>
</SbToolbar>
<>
{...localData.children.map((child, index) => (
<SbBlock
{...{ key: child.id }}
data-order={index}
indexAsChild={index}
block={child}
eventUpdate={(updated: IBlockData<any>) => onChildUpdate(child, updated)}
eventRemoveSelf={() => removeBlock(index)}
eventPrependBlock={(block: IBlockData<any>) => insertBlock(index - 1, block)}
eventAppendBlock={(block: IBlockData<any>) => insertBlock(index, block)}
eventActivatePrevious={() => activateBlock(index - 1,)}
eventActivateNext={() => activateBlock(index + 1,)}
>
{{
'context-toolbar': () =>
<SbBlockOrdering
eventMoveBackward={() => moveBackward(index)}
eventMoveForward={() => moveForward(index)}
eventRemove={() => removeBlock(index)}
orientation={localData.orientation}
/>,
}}
</SbBlock>
))}
</>
{...localData.children.map((child, index) => (
<SbBlock
{...{ key: child.id }}
data-order={index}
block={child}
onUpdate={(updated: BlockData<any>) => onChildUpdate(child, updated)}
onRemoveSelf={() => removeBlock(index)}
onPrependBlock={(block: BlockData<any>) => insertBlock(index - 1, block)}
onAppendBlock={(block: BlockData<any>) => insertBlock(index, block)}
onActivatePrevious={() => activateBlock(index - 1,)}
onActivateNext={() => activateBlock(index + 1,)}
>
{{
'context-toolbar': () =>
<SbBlockOrdering
onMoveBackward={() => moveBackward(index)}
onMoveForward={() => moveForward(index)}
onRemove={() => removeBlock(index)}
orientation={localData.orientation}
/>,
}}
</SbBlock>
))}
<SbBlockPlaceholder eventInsertBlock={appendBlock}></SbBlockPlaceholder>
<SbBlockPlaceholder onInsertBlock={appendBlock} />
</div>
);
},

View file

@ -8,5 +8,5 @@ export default {
name,
getDefaultData,
edit: defineAsyncComponent(() => import('./edit')),
view: defineAsyncComponent(() => import('./view')),
display: defineAsyncComponent(() => import('./display')),
};

View file

@ -1,11 +1,11 @@
import { IBlockData } from '@schlechtenburg/core';
import { BlockData } from '@schlechtenburg/core';
export interface ILayoutData {
export interface LayoutData {
orientation: string;
children: IBlockData<any>[];
children: BlockData<any>[];
}
export const getDefaultData: () => ILayoutData = () => ({
export const getDefaultData: () => LayoutData = () => ({
orientation: 'vertical',
children: [],
});

Some files were not shown because too many files have changed in this diff Show more