Compare commits
No commits in common. "master" and "vue3" have entirely different histories.
|
@ -1,24 +1,7 @@
|
||||||
# Editor configuration, see http://editorconfig.org
|
[*.{js,jsx,ts,tsx,vue}]
|
||||||
root = true
|
|
||||||
|
|
||||||
[*]
|
|
||||||
end_of_line = lf
|
|
||||||
insert_final_newline = true
|
|
||||||
trim_trailing_whitespace = true
|
|
||||||
charset = utf-8
|
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
|
end_of_line = lf
|
||||||
# Ignore diffs/patches
|
trim_trailing_whitespace = true
|
||||||
[*.{diff,patch}]
|
insert_final_newline = true
|
||||||
end_of_line = unset
|
max_line_length = 100
|
||||||
insert_final_newline = unset
|
|
||||||
trim_trailing_whitespace = unset
|
|
||||||
indent_size = unset
|
|
||||||
charset = unset
|
|
||||||
indent_style = unset
|
|
||||||
indent_size = unset
|
|
||||||
|
|
||||||
[*.md]
|
|
||||||
max_line_length = off
|
|
||||||
trim_trailing_whitespace = false
|
|
||||||
|
|
8
.gitignore
vendored
8
.gitignore
vendored
|
@ -1,13 +1,5 @@
|
||||||
.direnv
|
|
||||||
node_modules
|
node_modules
|
||||||
.DS_Store
|
.DS_Store
|
||||||
dist
|
dist
|
||||||
dist-ssr
|
dist-ssr
|
||||||
*.local
|
*.local
|
||||||
tags
|
|
||||||
.temp
|
|
||||||
.cache
|
|
||||||
docs/.vitepress/cache
|
|
||||||
docs/.vitepress/dist
|
|
||||||
__screenshots__
|
|
||||||
__snapshots__
|
|
||||||
|
|
660
LICENSE.md
660
LICENSE.md
|
@ -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/>.
|
|
|
@ -1,47 +0,0 @@
|
||||||
import { defineConfig } from 'vitepress';
|
|
||||||
import { defineConfig as defineViteConfig } from 'vite';
|
|
||||||
import vueJsx from '@vitejs/plugin-vue-jsx'
|
|
||||||
import { join } from 'path';
|
|
||||||
|
|
||||||
export default defineConfig({
|
|
||||||
lang: 'en-US',
|
|
||||||
title: 'Schlechtenburg',
|
|
||||||
description: 'Experimental WYSIWYG editor framework made with Vue 3 and TypeScript',
|
|
||||||
lastUpdated: true,
|
|
||||||
|
|
||||||
themeConfig: {
|
|
||||||
sidebar: [
|
|
||||||
{
|
|
||||||
text: 'User Guide',
|
|
||||||
items: [
|
|
||||||
{ text: 'Introduction', link: '/' },
|
|
||||||
{ text: 'Try it out', link: '/try' },
|
|
||||||
{ text: 'Why Schlechtenburg?', link: '/why' },
|
|
||||||
{ text: 'Installation and usage', link: '/installation' },
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: 'Creating Blocks',
|
|
||||||
items: [
|
|
||||||
{ text: 'Basics', link: '/creating-blocks/' },
|
|
||||||
{ text: 'Examples', link: '/creating-blocks/examples' },
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
vite: defineViteConfig({
|
|
||||||
plugins: [
|
|
||||||
vueJsx(),
|
|
||||||
],
|
|
||||||
resolve: {
|
|
||||||
alias: {
|
|
||||||
'@schlechtenburg/core': join(__dirname, '../../packages/core/lib/index.ts'),
|
|
||||||
'@schlechtenburg/paragraph': join(__dirname, '../../packages/paragraph/lib/index.ts'),
|
|
||||||
'@schlechtenburg/heading': join(__dirname, '../../packages/heading/lib/index.ts'),
|
|
||||||
'@schlechtenburg/image': join(__dirname, '../../packages/image/lib/index.ts'),
|
|
||||||
'@schlechtenburg/layout': join(__dirname, '../../packages/layout/lib/index.ts'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
});
|
|
|
@ -1,42 +0,0 @@
|
||||||
.example-editor {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
margin-left: 4rem;
|
|
||||||
|
|
||||||
&--mode {
|
|
||||||
display: flex;
|
|
||||||
justify-content: stretch;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
&--mode-tab {
|
|
||||||
display: flex;
|
|
||||||
margin-top: 1px;
|
|
||||||
padding: 0.25rem 1rem;
|
|
||||||
border-top: 1px solid var(--vp-c-divider-light);
|
|
||||||
border-right: 1px solid var(--vp-c-divider-light);
|
|
||||||
|
|
||||||
input {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
&_checked {
|
|
||||||
color: var(--vp-c-brand);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&--sb {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
border: 1px solid var(--vp-c-divider-light);
|
|
||||||
}
|
|
||||||
|
|
||||||
&--json {
|
|
||||||
margin: 0;
|
|
||||||
border: 1px solid var(--vp-c-divider-light);
|
|
||||||
|
|
||||||
background-color: var(--vp-c-text-1);
|
|
||||||
color: var(--vp-c-bg);
|
|
||||||
overflow: scroll;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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>;
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
|
@ -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>;
|
|
||||||
},
|
|
||||||
});
|
|
165
docs/api.json
165
docs/api.json
|
@ -1,165 +0,0 @@
|
||||||
{
|
|
||||||
"id": 6,
|
|
||||||
"name": "Documentation",
|
|
||||||
"variant": "project",
|
|
||||||
"kind": 1,
|
|
||||||
"flags": {},
|
|
||||||
"children": [
|
|
||||||
{
|
|
||||||
"id": 7,
|
|
||||||
"name": "@schlechtenburg/core",
|
|
||||||
"variant": "declaration",
|
|
||||||
"kind": 2,
|
|
||||||
"flags": {},
|
|
||||||
"readme": [
|
|
||||||
{
|
|
||||||
"kind": "text",
|
|
||||||
"text": "# "
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"kind": "code",
|
|
||||||
"text": "`@schlechtenburg/core`"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"kind": "text",
|
|
||||||
"text": "\n\n> TODO: description\n\n## Usage\n\n"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"kind": "code",
|
|
||||||
"text": "```\nconst core = require('@schlechtenburg/core');\n\n// TODO: DEMONSTRATE API\n```"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 8,
|
|
||||||
"name": "@schlechtenburg/heading",
|
|
||||||
"variant": "declaration",
|
|
||||||
"kind": 2,
|
|
||||||
"flags": {},
|
|
||||||
"readme": [
|
|
||||||
{
|
|
||||||
"kind": "text",
|
|
||||||
"text": "# "
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"kind": "code",
|
|
||||||
"text": "`@schlechtenburg/heading`"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"kind": "text",
|
|
||||||
"text": "\n\n> TODO: description\n\n## Usage\n\n"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"kind": "code",
|
|
||||||
"text": "```\nconst heading = require('@schlechtenburg/heading');\n\n// TODO: DEMONSTRATE API\n```"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 9,
|
|
||||||
"name": "@schlechtenburg/standalone",
|
|
||||||
"variant": "declaration",
|
|
||||||
"kind": 2,
|
|
||||||
"flags": {},
|
|
||||||
"readme": [
|
|
||||||
{
|
|
||||||
"kind": "text",
|
|
||||||
"text": "# "
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"kind": "code",
|
|
||||||
"text": "`@schlechtenburg/core`"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"kind": "text",
|
|
||||||
"text": "\n\n> TODO: description\n\n## Usage\n\n"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"kind": "code",
|
|
||||||
"text": "```\nconst core = require('@schlechtenburg/core');\n\n// TODO: DEMONSTRATE API\n```"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 10,
|
|
||||||
"name": "@schlechtenburg/paragraph",
|
|
||||||
"variant": "declaration",
|
|
||||||
"kind": 2,
|
|
||||||
"flags": {},
|
|
||||||
"readme": [
|
|
||||||
{
|
|
||||||
"kind": "text",
|
|
||||||
"text": "# "
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"kind": "code",
|
|
||||||
"text": "`@schlechtenburg/paragraph`"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"kind": "text",
|
|
||||||
"text": "\n\n> TODO: description\n\n## Usage\n\n"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"kind": "code",
|
|
||||||
"text": "```\nconst paragraph = require('@schlechtenburg/paragraph');\n\n// TODO: DEMONSTRATE API\n```"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 11,
|
|
||||||
"name": "@schlechtenburg/layout",
|
|
||||||
"variant": "declaration",
|
|
||||||
"kind": 2,
|
|
||||||
"flags": {},
|
|
||||||
"readme": [
|
|
||||||
{
|
|
||||||
"kind": "text",
|
|
||||||
"text": "# "
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"kind": "code",
|
|
||||||
"text": "`@schlechtenburg/layout`"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"kind": "text",
|
|
||||||
"text": "\n\n> TODO: description\n\n## Usage\n\n"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"kind": "code",
|
|
||||||
"text": "```\nconst layout = require('@schlechtenburg/layout');\n\n// TODO: DEMONSTRATE API\n```"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 12,
|
|
||||||
"name": "@schlechtenburg/image",
|
|
||||||
"variant": "declaration",
|
|
||||||
"kind": 2,
|
|
||||||
"flags": {},
|
|
||||||
"readme": [
|
|
||||||
{
|
|
||||||
"kind": "text",
|
|
||||||
"text": "# "
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"kind": "code",
|
|
||||||
"text": "`@schlechtenburg/image`"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"kind": "text",
|
|
||||||
"text": "\n\n> TODO: description\n\n## Usage\n\n"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"kind": "code",
|
|
||||||
"text": "```\nconst image = require('@schlechtenburg/image');\n\n// TODO: DEMONSTRATE API\n```"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"packageName": "schlechtenburg",
|
|
||||||
"symbolIdMap": {},
|
|
||||||
"files": {
|
|
||||||
"entries": {},
|
|
||||||
"reflections": {}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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.
|
|
|
@ -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
|
@ -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>
|
|
|
@ -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
|
|
||||||
---
|
|
|
@ -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,
|
|
||||||
]}
|
|
||||||
/>;
|
|
||||||
}
|
|
||||||
```
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
21
docs/main.ts
21
docs/main.ts
|
@ -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');
|
|
|
@ -1,8 +0,0 @@
|
||||||
---
|
|
||||||
layout: page
|
|
||||||
---
|
|
||||||
<script setup>
|
|
||||||
import ExampleEditor from './ExampleEditor';
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<ExampleEditor></ExampleEditor>
|
|
|
@ -1 +0,0 @@
|
||||||
# Usage
|
|
81
docs/why.md
81
docs/why.md
|
@ -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.
|
|
116
flake.lock
116
flake.lock
|
@ -1,116 +0,0 @@
|
||||||
{
|
|
||||||
"nodes": {
|
|
||||||
"devshell": {
|
|
||||||
"inputs": {
|
|
||||||
"flake-utils": "flake-utils",
|
|
||||||
"nixpkgs": [
|
|
||||||
"nixpkgs"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1713195852,
|
|
||||||
"narHash": "sha256-MEb4Hx/Aw7pcsmcHXBuldFsrVTfl9Q9dz1JSlxUanmE=",
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "devshell",
|
|
||||||
"rev": "2c8e04e5c29299bec53c2e5a73da0f9afa8dabb5",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "devshell",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"flake-utils": {
|
|
||||||
"inputs": {
|
|
||||||
"systems": "systems"
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1701680307,
|
|
||||||
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"flake-utils_2": {
|
|
||||||
"inputs": {
|
|
||||||
"systems": "systems_2"
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1710146030,
|
|
||||||
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1728018373,
|
|
||||||
"narHash": "sha256-NOiTvBbRLIOe5F6RbHaAh6++BNjsb149fGZd1T4+KBg=",
|
|
||||||
"owner": "nixos",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "bc947f541ae55e999ffdb4013441347d83b00feb",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nixos",
|
|
||||||
"ref": "nixos-unstable",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": {
|
|
||||||
"inputs": {
|
|
||||||
"devshell": "devshell",
|
|
||||||
"flake-utils": "flake-utils_2",
|
|
||||||
"nixpkgs": "nixpkgs"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"systems": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1681028828,
|
|
||||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
|
||||||
"owner": "nix-systems",
|
|
||||||
"repo": "default",
|
|
||||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nix-systems",
|
|
||||||
"repo": "default",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"systems_2": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1681028828,
|
|
||||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
|
||||||
"owner": "nix-systems",
|
|
||||||
"repo": "default",
|
|
||||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nix-systems",
|
|
||||||
"repo": "default",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": "root",
|
|
||||||
"version": 7
|
|
||||||
}
|
|
34
flake.nix
34
flake.nix
|
@ -1,34 +0,0 @@
|
||||||
{
|
|
||||||
description = "Schlechtenburg";
|
|
||||||
|
|
||||||
inputs = {
|
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
|
||||||
|
|
||||||
flake-utils.url = "github:numtide/flake-utils";
|
|
||||||
|
|
||||||
devshell.url = "github:numtide/devshell";
|
|
||||||
devshell.inputs.nixpkgs.follows = "nixpkgs";
|
|
||||||
};
|
|
||||||
|
|
||||||
outputs = { self, flake-utils, devshell, nixpkgs }:
|
|
||||||
flake-utils.lib.simpleFlake {
|
|
||||||
inherit self nixpkgs;
|
|
||||||
name = "schlechtenburg";
|
|
||||||
preOverlays = [ devshell.overlays.default ];
|
|
||||||
shell = { pkgs }: pkgs.devshell.mkShell {
|
|
||||||
devshell.packages = with pkgs; [
|
|
||||||
nodejs
|
|
||||||
nodePackages.typescript
|
|
||||||
nodePackages.typescript-language-server
|
|
||||||
nodePackages.vue-language-server
|
|
||||||
playwright
|
|
||||||
];
|
|
||||||
|
|
||||||
env = [
|
|
||||||
{ name = "PLAYWRIGHT_NODEJS_PATH"; value = "${pkgs.nodejs}/bin/node"; }
|
|
||||||
{ name = "PLAYWRIGHT_BROWSERS_PATH"; value = "${pkgs.playwright-driver.browsers}"; }
|
|
||||||
{ name = "PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS"; value = "true"; }
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
13
index.html
Normal file
13
index.html
Normal 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="/src/main.ts"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -2,6 +2,5 @@
|
||||||
"packages": [
|
"packages": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
"version": "0.0.0",
|
"version": "0.0.0"
|
||||||
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
|
|
||||||
}
|
}
|
||||||
|
|
4
notes.md
4
notes.md
|
@ -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.
|
|
21407
package-lock.json
generated
21407
package-lock.json
generated
File diff suppressed because it is too large
Load diff
46
package.json
46
package.json
|
@ -1,40 +1,22 @@
|
||||||
{
|
{
|
||||||
"name": "schlechtenburg",
|
"name": "schlechtenburg",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "GPL-3.0-or-later",
|
||||||
"scripts": {
|
"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",
|
"dev": "vite",
|
||||||
"typecheck": "lerna run --stream typecheck",
|
"build": "vuedx-typecheck . && vite build"
|
||||||
"docs:dev": "vitepress dev docs",
|
|
||||||
"docs:build": "vitepress build docs",
|
|
||||||
"docs:serve": "vitepress serve docs",
|
|
||||||
"test:browser": "vitest"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/jsdom": "^21.1.7",
|
|
||||||
"@vitejs/plugin-vue": "^5.1.4",
|
|
||||||
"@vitejs/plugin-vue-jsx": "^3.1.0",
|
|
||||||
"@vitest/browser": "^2.1.2",
|
|
||||||
"@vue/test-utils": "^2.4.6",
|
|
||||||
"deep-freeze": "^0.0.1",
|
|
||||||
"lerna": "^8.1.8",
|
|
||||||
"sass": "^1.75.0",
|
|
||||||
"typedoc": "^0.26.7",
|
|
||||||
"typescript": "^5.6.2",
|
|
||||||
"vitepress": "^1.3.4",
|
|
||||||
"vitest": "^2.1.2",
|
|
||||||
"vitest-browser-vue": "^0.0.1",
|
|
||||||
"vue": "^3.5.10"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lodash-es": "^4.17.21"
|
"lodash-es": "^4.17.20",
|
||||||
|
"vue": "^3.0.4"
|
||||||
},
|
},
|
||||||
"workspaces": [
|
"devDependencies": {
|
||||||
"packages/core",
|
"@vue/compiler-sfc": "^3.0.4",
|
||||||
"packages/heading",
|
"@vuedx/typecheck": "^0.3.1-insiders-1606311019.0",
|
||||||
"packages/image",
|
"@vuedx/typescript-plugin-vue": "^0.3.1-insiders-1606311019.0",
|
||||||
"packages/paragraph",
|
"lerna": "^3.22.1",
|
||||||
"packages/layout",
|
"sass": "^1.30.0",
|
||||||
"packages/rich-text"
|
"typescript": "^4.1.2",
|
||||||
]
|
"vite": "^1.0.0-rc.13"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
7
packages/core/__tests__/core.test.js
Normal file
7
packages/core/__tests__/core.test.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const core = require('..');
|
||||||
|
|
||||||
|
describe('@schlechtenburg/core', () => {
|
||||||
|
it('needs tests');
|
||||||
|
});
|
|
@ -1,33 +0,0 @@
|
||||||
import { describe, expect, it } from 'vitest'
|
|
||||||
import { withSetup } from '../../../test';
|
|
||||||
import { useActivation } from '..';
|
|
||||||
|
|
||||||
describe('@schlechtenburg/core', () => {
|
|
||||||
const a = 'a';
|
|
||||||
const b = 'b';
|
|
||||||
|
|
||||||
it('Should activate', async () => {
|
|
||||||
const {
|
|
||||||
activeBlockId,
|
|
||||||
isActive,
|
|
||||||
activate,
|
|
||||||
deactivate,
|
|
||||||
} = await withSetup(() => useActivation(a));
|
|
||||||
|
|
||||||
activate(a);
|
|
||||||
expect(activeBlockId.value).toBe(a);
|
|
||||||
expect(isActive.value).toBeTruthy();
|
|
||||||
|
|
||||||
activate(b);
|
|
||||||
expect(activeBlockId.value).toBe(b);
|
|
||||||
expect(isActive.value).toBeFalsy();
|
|
||||||
|
|
||||||
deactivate(activeBlockId.value);
|
|
||||||
expect(isActive.value).toBeFalsy();
|
|
||||||
expect(activeBlockId.value).toBe(null);
|
|
||||||
|
|
||||||
activate();
|
|
||||||
expect(activeBlockId.value).toBe(a);
|
|
||||||
expect(isActive.value).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -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
242
packages/core/lib/ResizeObserver.d.ts
vendored
Normal 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;
|
||||||
|
}
|
|
@ -1,15 +0,0 @@
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
|
||||||
|
|
||||||
export const generateBlockId = uuidv4;
|
|
||||||
|
|
||||||
export const model = {
|
|
||||||
prop: 'block',
|
|
||||||
event: 'update',
|
|
||||||
};
|
|
||||||
|
|
||||||
export const blockProps = {
|
|
||||||
blockId: {
|
|
||||||
type: String,
|
|
||||||
default: generateBlockId,
|
|
||||||
},
|
|
||||||
};
|
|
34
packages/core/lib/blocks.ts
Normal file
34
packages/core/lib/blocks.ts
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import { Component } from 'vue';
|
||||||
|
|
||||||
|
export interface BlockDefinition {
|
||||||
|
name: string;
|
||||||
|
getDefaultData: any;
|
||||||
|
edit: Component;
|
||||||
|
display: Component;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BlockLibraryDefinition {
|
||||||
|
[name: string]: BlockDefinition;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BlockProps<T> {
|
||||||
|
blockId: string;
|
||||||
|
data: T;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Block<T> extends BlockProps<T> {
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const model = {
|
||||||
|
prop: 'block',
|
||||||
|
event: 'update',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const blockProps = {
|
||||||
|
blockId: {
|
||||||
|
type: String,
|
||||||
|
default: () => `${+(new Date())}`,
|
||||||
|
},
|
||||||
|
data: { type: Object, default: () => ({}) },
|
||||||
|
};
|
|
@ -5,23 +5,22 @@
|
||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
justify-items: stretch;
|
justify-items: stretch;
|
||||||
height: auto;
|
height: auto;
|
||||||
min-width: 32px;
|
|
||||||
min-height: 32px;
|
|
||||||
|
|
||||||
> * > .sb-toolbar {
|
> * > .sb-toolbar {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&__edit-cover {
|
||||||
|
}
|
||||||
|
|
||||||
> .sb-block-ordering {
|
> .sb-block-ordering {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
&_active,
|
&_active {
|
||||||
&_active:hover {
|
outline: 1px solid var(--grey-2);
|
||||||
z-index: 1;
|
|
||||||
outline: 4px solid var(--interact);
|
|
||||||
|
|
||||||
> * > .sb-toolbar {
|
> * > .sb-toolbar {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
|
@ -34,8 +33,4 @@
|
||||||
pointer-events: all;
|
pointer-events: all;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&_highlighted {
|
|
||||||
outline: 2px solid var(--interact);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,116 +6,61 @@ import {
|
||||||
ref,
|
ref,
|
||||||
Ref,
|
Ref,
|
||||||
} from 'vue';
|
} from 'vue';
|
||||||
import {
|
import { Block } from '../blocks';
|
||||||
IBlockData,
|
|
||||||
OnUpdateBlockCb,
|
|
||||||
OnActivateNextCb,
|
|
||||||
OnRemoveSelfCb,
|
|
||||||
OnAppendBlockCb,
|
|
||||||
OnPrependBlockCb,
|
|
||||||
OnActivatePreviousCb,
|
|
||||||
} from '../types';
|
|
||||||
import { SbMode } from '../mode';
|
import { SbMode } from '../mode';
|
||||||
import { useResizeObserver, SymBlockDimensions } from '../use-resize-observer';
|
import { useResizeObserver, BlockDimensions } from '../use-resize-observer';
|
||||||
import { useActivation } from '../use-activation';
|
import { useActivation } from '../use-activation';
|
||||||
import { useBlockTree } from '../use-block-tree';
|
|
||||||
import { useDynamicBlocks } from '../use-dynamic-blocks';
|
import { useDynamicBlocks } from '../use-dynamic-blocks';
|
||||||
import hoverCover from '../directives/hover-cover';
|
|
||||||
|
|
||||||
import SbMissingBlock from './MissingBlock';
|
import { SbBlockOrdering } from './BlockOrdering';
|
||||||
|
import SbMissingBlock from './BlockMissing/index';
|
||||||
|
|
||||||
import './Block.scss';
|
import './Block.scss';
|
||||||
|
|
||||||
/**
|
interface BlockProps {
|
||||||
* Displays a Schlechtenburg block either the mode of the schlechtenburg instance.
|
block: Block;
|
||||||
* You can use this to display child blocks inside your own blocks.
|
eventUpdate: (b?: Block) => void;
|
||||||
*/
|
eventPrependBlock: (b?: Block) => void;
|
||||||
|
eventAppendBlock: (b?: Block) => void;
|
||||||
|
eventRemoveBlock: () => void;
|
||||||
|
eventMoveUp: () => void;
|
||||||
|
eventMoveDown: () => void;
|
||||||
|
sortable: string;
|
||||||
|
}
|
||||||
|
|
||||||
export const SbBlock = defineComponent({
|
export const SbBlock = defineComponent({
|
||||||
name: 'sb-block',
|
name: 'sb-block',
|
||||||
|
|
||||||
directives: {
|
|
||||||
hoverCover,
|
|
||||||
},
|
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
/**
|
|
||||||
* The state for the block.
|
|
||||||
*/
|
|
||||||
block: {
|
block: {
|
||||||
type: (null as unknown) as PropType<IBlockData<any>>,
|
type: (null as unknown) as PropType<Block>,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
/**
|
sortable: {
|
||||||
* The state for the block.
|
type: String,
|
||||||
*/
|
default: null,
|
||||||
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: () => () => {},
|
|
||||||
},
|
},
|
||||||
|
eventUpdate: { type: Function, default: () => {} },
|
||||||
|
eventPrependBlock: { type: Function, default: () => {} },
|
||||||
|
eventAppendBlock: { type: Function, default: () => {} },
|
||||||
|
eventRemoveBlock: { type: Function, default: () => {} },
|
||||||
|
eventMoveUp: { type: Function, default: () => {} },
|
||||||
|
eventMoveDown: { type: Function, default: () => {} },
|
||||||
},
|
},
|
||||||
|
|
||||||
setup(props, context) {
|
setup(props: BlockProps, context) {
|
||||||
const el: Ref<null|HTMLElement> = ref(null);
|
const el: Ref<null|HTMLElement> = ref(null);
|
||||||
const { mode, getBlock } = useDynamicBlocks();
|
const { mode, getBlock } = useDynamicBlocks();
|
||||||
const {
|
const { isActive, activate } = useActivation(props.block.blockId);
|
||||||
isActive,
|
|
||||||
activate,
|
|
||||||
} = useActivation(props.block.id);
|
|
||||||
const classes = computed(() => ({
|
const classes = computed(() => ({
|
||||||
'sb-block': true,
|
'sb-block': true,
|
||||||
'sb-block_active': isActive.value,
|
'sb-block_active': isActive.value,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const { triggerSizeCalculation } = useResizeObserver(el, SymBlockDimensions);
|
const { triggerSizeCalculation } = useResizeObserver(el, BlockDimensions);
|
||||||
watch(() => props.block.data, triggerSizeCalculation);
|
watch(() => props.block.data, triggerSizeCalculation);
|
||||||
|
|
||||||
const { register } = useBlockTree();
|
const onChildUpdate = (updated: {[key: string]: any}) => {
|
||||||
register(props.block, props.indexAsChild);
|
|
||||||
watch(props.block, () => { register(props.block, props.indexAsChild); });
|
|
||||||
|
|
||||||
const eventChildUpdate = (updated: {[key: string]: any}) => {
|
|
||||||
props.eventUpdate({
|
props.eventUpdate({
|
||||||
...props.block,
|
...props.block,
|
||||||
data: {
|
data: {
|
||||||
|
@ -126,52 +71,43 @@ export const SbBlock = defineComponent({
|
||||||
};
|
};
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
const BlockComponent = getBlock(props.block.name)?.[mode.value] as any;
|
const BlockComponent = getBlock(props.block.name) as any;
|
||||||
|
|
||||||
if (!BlockComponent) {
|
if (!BlockComponent) {
|
||||||
const MissingBlock = SbMissingBlock[mode.value];
|
const MissingBlock = SbMissingBlock[mode.value];
|
||||||
return <MissingBlock
|
return <MissingBlock
|
||||||
name={props.block.name}
|
name={props.block.name}
|
||||||
blockId={props.block.id}
|
blockId={props.block.blockId}
|
||||||
/>;
|
/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode.value === SbMode.View) {
|
if (mode.value === SbMode.Display) {
|
||||||
return <BlockComponent
|
return () => (
|
||||||
data={props.block.data}
|
<BlockComponent
|
||||||
blockId={props.block.id}
|
data={props.block.data}
|
||||||
/>;
|
blockId={props.block.blockId}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return <div
|
return <div
|
||||||
ref={el}
|
ref={el}
|
||||||
class={classes.value}
|
class={classes.value}
|
||||||
v-hover-cover
|
|
||||||
>
|
>
|
||||||
{
|
<div class="sb-block__edit-cover"></div>
|
||||||
/**
|
{context.slots['context-toolbar'] ? context.slots['context-toolbar']() : null}
|
||||||
* This is an alternative toolbar location that parent blocks can use to offer UI elements specific to child blocks.
|
|
||||||
* @slot context-toolbar
|
|
||||||
*/
|
|
||||||
context.slots['context-toolbar'] ? context.slots['context-toolbar']() : null
|
|
||||||
}
|
|
||||||
<BlockComponent
|
<BlockComponent
|
||||||
data={props.block.data}
|
data={props.block.data}
|
||||||
blockId={props.block.id}
|
blockId={props.block.blockId}
|
||||||
eventUpdate={eventChildUpdate}
|
eventUpdate={onChildUpdate}
|
||||||
eventPrependBlock={props.eventPrependBlock}
|
eventPrependBlock={props.eventPrependBlock}
|
||||||
eventAppendBlock={props.eventAppendBlock}
|
eventAppendBlock={props.eventAppendBlock}
|
||||||
eventRemoveSelf={props.eventRemoveSelf}
|
eventRemoveBlock={props.eventRemoveBlock}
|
||||||
eventActivatePrevious={props.eventActivatePrevious}
|
onClick={($event: MouseEvent) => {
|
||||||
eventActivateNext={props.eventActivateNext}
|
$event.stopPropagation();
|
||||||
|
activate();
|
||||||
{...{
|
|
||||||
onClick: ($event: MouseEvent) => {
|
|
||||||
$event.stopPropagation();
|
|
||||||
activate();
|
|
||||||
},
|
|
||||||
...context.attrs,
|
|
||||||
}}
|
}}
|
||||||
|
{...context.attrs}
|
||||||
/>
|
/>
|
||||||
</div>;
|
</div>;
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,18 +2,25 @@ import { defineComponent, PropType } from 'vue';
|
||||||
import {
|
import {
|
||||||
model,
|
model,
|
||||||
blockProps,
|
blockProps,
|
||||||
} from '../../block-helpers';
|
BlockProps,
|
||||||
|
} from '../../blocks';
|
||||||
|
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
|
||||||
|
interface MissingBlockProps extends BlockProps<any> {
|
||||||
|
eventUpdate: (b?: any) => void;
|
||||||
|
eventAppendBlock: (b?: any) => void;
|
||||||
|
eventRemoveBlock: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'sb-missing-block',
|
name: 'sb-missing-block',
|
||||||
|
|
||||||
model,
|
model,
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
...blockProps,
|
|
||||||
name: String,
|
name: String,
|
||||||
|
...blockProps,
|
||||||
data: {
|
data: {
|
||||||
type: (null as unknown) as PropType<any>,
|
type: (null as unknown) as PropType<any>,
|
||||||
default: null,
|
default: null,
|
||||||
|
@ -23,9 +30,12 @@ export default defineComponent({
|
||||||
eventRemoveBlock: { type: Function, default: () => {} },
|
eventRemoveBlock: { type: Function, default: () => {} },
|
||||||
},
|
},
|
||||||
|
|
||||||
setup(props) {
|
setup(props: MissingBlockProps) {
|
||||||
|
console.log(props, props.name, props.data, props.blockId);
|
||||||
return () => (
|
return () => (
|
||||||
<div class="sb-missing-block">Missing block: {props.name}</div>
|
<div class="sb-missing-block">
|
||||||
|
Missing block: {props.name}
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
7
packages/core/lib/components/BlockMissing/index.ts
Normal file
7
packages/core/lib/components/BlockMissing/index.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import { defineAsyncComponent } from 'vue';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'sb-missing-block',
|
||||||
|
edit: defineAsyncComponent(() => import('./display')),
|
||||||
|
display: defineAsyncComponent(() => import('./display')),
|
||||||
|
};
|
|
@ -1,4 +1,4 @@
|
||||||
import debounce from 'lodash/debounce';
|
import { debounce } from 'lodash-es';
|
||||||
import {
|
import {
|
||||||
watch,
|
watch,
|
||||||
reactive,
|
reactive,
|
||||||
|
@ -15,13 +15,13 @@ export const SbBlockOrdering = defineComponent({
|
||||||
name: 'sb-block-ordering',
|
name: 'sb-block-ordering',
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
orientation: {
|
sortable: {
|
||||||
type: String,
|
type: String,
|
||||||
default: null,
|
default: null,
|
||||||
},
|
},
|
||||||
eventRemove: { type: Function, default: () => {} },
|
eventRemoveBlock: { type: Function, default: () => {} },
|
||||||
eventMoveBackward: { type: Function, default: () => {} },
|
eventMoveUp: { type: Function, default: () => {} },
|
||||||
eventMoveForward: { type: Function, default: () => {} },
|
eventMoveDown: { type: Function, default: () => {} },
|
||||||
},
|
},
|
||||||
|
|
||||||
setup(props) {
|
setup(props) {
|
||||||
|
@ -32,7 +32,7 @@ export const SbBlockOrdering = defineComponent({
|
||||||
|
|
||||||
const classes = computed(() => ({
|
const classes = computed(() => ({
|
||||||
'sb-block-ordering': true,
|
'sb-block-ordering': true,
|
||||||
[`sb-block-ordering_${props.orientation}`]: !!props.orientation,
|
[`sb-block-ordering_${props.sortable}`]: !!props.sortable,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const { editorDimensions, blockDimensions } = useBlockSizing();
|
const { editorDimensions, blockDimensions } = useBlockSizing();
|
||||||
|
@ -47,7 +47,7 @@ export const SbBlockOrdering = defineComponent({
|
||||||
});
|
});
|
||||||
watch(editorDimensions, resetStyles);
|
watch(editorDimensions, resetStyles);
|
||||||
watch(blockDimensions, resetStyles);
|
watch(blockDimensions, resetStyles);
|
||||||
watch(() => props.orientation, resetStyles);
|
watch(() => props.sortable, resetStyles);
|
||||||
|
|
||||||
return () => (
|
return () => (
|
||||||
<div
|
<div
|
||||||
|
@ -55,9 +55,9 @@ export const SbBlockOrdering = defineComponent({
|
||||||
style={styles}
|
style={styles}
|
||||||
onClick={($event: MouseEvent) => $event.stopPropagation()}
|
onClick={($event: MouseEvent) => $event.stopPropagation()}
|
||||||
>
|
>
|
||||||
<SbButton {...{onClick: props.eventMoveBackward}}>{props.orientation === 'vertical' ? '↑' : '←'}</SbButton>
|
<SbButton onClick={props.eventMoveUp}>{props.sortable === 'vertical' ? '↑' : '←'}</SbButton>
|
||||||
<SbButton {...{onClick: props.eventRemove}}>x</SbButton>
|
<SbButton onClick={props.eventRemoveBlock}>x</SbButton>
|
||||||
<SbButton {...{onClick: props.eventMoveForward}}>{props.orientation === 'vertical' ? '↓' : '→'}</SbButton>
|
<SbButton onClick={props.eventMoveDown}>{props.sortable === 'vertical' ? '↓' : '→'}</SbButton>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
.sb-block-picker {
|
.sb-block-picker {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
&__add-button {
|
&__add-button {
|
||||||
padding: 24px 32px;
|
padding: 24px 32px;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,58 +3,60 @@ import {
|
||||||
ref,
|
ref,
|
||||||
defineComponent,
|
defineComponent,
|
||||||
} from 'vue';
|
} from 'vue';
|
||||||
import { useDynamicBlocks } from '../use-dynamic-blocks';
|
import {
|
||||||
import { IBlockDefinition } from '../types';
|
useDynamicBlocks,
|
||||||
import { generateBlockId } from '../block-helpers';
|
BlockDefinition,
|
||||||
|
} from '../use-dynamic-blocks';
|
||||||
|
|
||||||
import { SbButton } from './Button';
|
import { SbButton } from './Button';
|
||||||
import { SbContextMenu, IContextMenuSlotContext } from './ContextMenu';
|
import { SbModal } from './Modal';
|
||||||
|
|
||||||
import './BlockPicker.scss';
|
import './BlockPicker.scss';
|
||||||
|
|
||||||
export const SbBlockPicker = defineComponent({
|
export const SbBlockPicker = defineComponent({
|
||||||
name: 'sb-block-picker',
|
name: 'sb-block-picker',
|
||||||
|
|
||||||
props: {
|
props: {},
|
||||||
eventPickedBlock: { type: Function, default: () => {} },
|
|
||||||
},
|
|
||||||
|
|
||||||
setup(props, context) {
|
setup(props, context) {
|
||||||
const open = ref(false);
|
const open = ref(false);
|
||||||
|
|
||||||
const { customBlocks } = useDynamicBlocks();
|
const { customBlocks } = useDynamicBlocks();
|
||||||
|
|
||||||
const blockList = computed(() => Object.keys(customBlocks).map((key) => customBlocks[key]));
|
const blockList = computed(() => Object.keys(customBlocks).map((key) => customBlocks[key]));
|
||||||
|
|
||||||
const selectBlock = (block: IBlockDefinition<any>) => {
|
const selectBlock = (block: BlockDefinition) => () => {
|
||||||
open.value = false;
|
open.value = false;
|
||||||
props.eventPickedBlock({
|
context.emit('picked-block', {
|
||||||
name: block.name,
|
name: block.name,
|
||||||
id: generateBlockId(),
|
blockId: `${+(new Date())}`,
|
||||||
data: block.getDefaultData(),
|
data: block.getDefaultData(),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return () => (
|
return () => (
|
||||||
<div class="sb-block-picker">
|
<div class="sb-block-picker">
|
||||||
<SbContextMenu
|
<SbButton
|
||||||
class="sb-tree-block-select"
|
class="sb-block-picker__add-button"
|
||||||
v-slots={{
|
type="button"
|
||||||
context: (slotContext:IContextMenuSlotContext) => context.slots.context
|
onClick={($event: MouseEvent) => {
|
||||||
? context.slots.context(slotContext)
|
open.value = true;
|
||||||
: <SbButton {...{ onClick: slotContext.toggle }}>Insert a block</SbButton>,
|
$event.stopPropagation();
|
||||||
default: ({ close }: { close: Function }) => blockList.value.map((block: IBlockDefinition<any>) => (
|
|
||||||
<SbButton
|
|
||||||
{...{
|
|
||||||
type: 'button',
|
|
||||||
onClick: () => {
|
|
||||||
selectBlock(block);
|
|
||||||
close();
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>{block.name}</SbButton>)),
|
|
||||||
}}
|
}}
|
||||||
></SbContextMenu>
|
>Add a block</SbButton>
|
||||||
|
<SbModal
|
||||||
|
open={open.value}
|
||||||
|
onClick={($event: MouseEvent) => $event.stopPropagation()}
|
||||||
|
eventClose={() => {
|
||||||
|
open.value = false;
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{...blockList.value.map((block: BlockDefinition) => (
|
||||||
|
<SbButton
|
||||||
|
type="button"
|
||||||
|
onClick={selectBlock(block)}
|
||||||
|
>{block.name}</SbButton>
|
||||||
|
))}
|
||||||
|
</SbModal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
.sb-block-placeholder {
|
.sb-block-placeholder {
|
||||||
flex-basis: 100%;
|
width: 100%;
|
||||||
flex-shrink: 2;
|
|
||||||
position: relative;
|
position: relative;
|
||||||
overflow: visible;
|
overflow: visible;
|
||||||
|
|
||||||
|
@ -8,12 +7,4 @@
|
||||||
background-color: var(--grey-1);
|
background-color: var(--grey-1);
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sb-block-picker {
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,18 @@
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { IBlockData } from '../types';
|
import { BlockDefinition } from '../blocks';
|
||||||
|
|
||||||
import { SbBlockPicker } from './BlockPicker';
|
import { SbBlockPicker } from './BlockPicker';
|
||||||
|
|
||||||
import './BlockPlaceholder.scss';
|
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({
|
export const SbBlockPlaceholder = defineComponent({
|
||||||
name: 'sb-block-placeholder',
|
name: 'sb-block-placeholder',
|
||||||
|
|
||||||
props: {
|
setup(props, context) {
|
||||||
/**
|
|
||||||
* Called when the user picked a block that should be inserted here.
|
|
||||||
*/
|
|
||||||
eventInsertBlock: { type: Function, default: () => {} },
|
|
||||||
},
|
|
||||||
|
|
||||||
setup(props) {
|
|
||||||
return () => (
|
return () => (
|
||||||
<div class="sb-block-placeholder">
|
<div class="sb-block-placeholder">
|
||||||
<SbBlockPicker
|
<SbBlockPicker
|
||||||
eventPickedBlock={(block: IBlockData<any>) => props.eventInsertBlock(block)}
|
onPickedBlock={(block: BlockDefinition) => context.emit('insert-block', block)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
import { defineComponent } from 'vue';
|
|
||||||
|
|
||||||
import './BlockToolbar.scss';
|
|
||||||
|
|
||||||
export const SbBlockToolbar = defineComponent({
|
|
||||||
name: 'sb-block-toolbar',
|
|
||||||
|
|
||||||
setup() {
|
|
||||||
return () => (
|
|
||||||
<div class="sb-block-toolbar"></div>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
|
@ -2,16 +2,12 @@ import { defineComponent } from 'vue';
|
||||||
|
|
||||||
import './Button.scss';
|
import './Button.scss';
|
||||||
|
|
||||||
/**
|
|
||||||
* A button in the schlechtenburg theme
|
|
||||||
* @sbui
|
|
||||||
*/
|
|
||||||
export const SbButton = defineComponent({
|
export const SbButton = defineComponent({
|
||||||
name: 'sb-button',
|
name: 'sb-button',
|
||||||
|
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
|
|
||||||
setup(_, context) {
|
setup(props, context) {
|
||||||
return () => (
|
return () => (
|
||||||
<button
|
<button
|
||||||
{...{
|
{...{
|
||||||
|
@ -19,13 +15,7 @@ export const SbButton = defineComponent({
|
||||||
class: (context.attrs.class || '') + ' sb-button',
|
class: (context.attrs.class || '') + ' sb-button',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{
|
{context.slots.default()}
|
||||||
/**
|
|
||||||
* The button contents
|
|
||||||
* @slot default
|
|
||||||
*/
|
|
||||||
context.slots.default?.()
|
|
||||||
}
|
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
.sb-context {
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sb-context-menu {
|
|
||||||
display: none;
|
|
||||||
flex-direction: column;
|
|
||||||
background: var(--grey-0);
|
|
||||||
border: 1px solid var(--grey-3);
|
|
||||||
top: 100%;
|
|
||||||
left: 0;
|
|
||||||
margin: 0;
|
|
||||||
padding: 0.5rem 0.25rem;
|
|
||||||
z-index: var(--z-context-menu);
|
|
||||||
|
|
||||||
max-height: 70vh;
|
|
||||||
max-width: 100vw;
|
|
||||||
overflow: auto;
|
|
||||||
|
|
||||||
&[open] {
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,84 +0,0 @@
|
||||||
import {
|
|
||||||
watch,
|
|
||||||
defineComponent,
|
|
||||||
ref,
|
|
||||||
Ref,
|
|
||||||
} from 'vue';
|
|
||||||
import { SbButton } from './Button';
|
|
||||||
|
|
||||||
import './ContextMenu.scss';
|
|
||||||
|
|
||||||
export interface IContextMenuSlotContext {
|
|
||||||
opened: Ref<boolean>;
|
|
||||||
open: () => void;
|
|
||||||
close: () => void;
|
|
||||||
toggle: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const SbContextMenu = defineComponent({
|
|
||||||
name: 'sb-context-menu',
|
|
||||||
|
|
||||||
props: {
|
|
||||||
onClose: { type: Function, default: () => {} },
|
|
||||||
onOpen: { type: Function, default: () => {} },
|
|
||||||
},
|
|
||||||
|
|
||||||
setup(props, context) {
|
|
||||||
const opened = ref(false);
|
|
||||||
const open = () => { opened.value = true; };
|
|
||||||
const close = () => { opened.value = false; };
|
|
||||||
const closeOnEscape = ($event: KeyboardEvent) => {
|
|
||||||
if ($event.key === 'Escape') {
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const toggle = () => { opened.value ? close() : open() };
|
|
||||||
|
|
||||||
watch(opened, (curr, prev) => {
|
|
||||||
if (curr === prev) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!curr) {
|
|
||||||
document.body.removeEventListener('click', close);
|
|
||||||
document.body.removeEventListener('keypress', closeOnEscape);
|
|
||||||
props.onClose();
|
|
||||||
} else {
|
|
||||||
setTimeout(() => {
|
|
||||||
document.body.addEventListener('click', close);
|
|
||||||
document.body.addEventListener('keypress', closeOnEscape);
|
|
||||||
props.onOpen();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return () => (
|
|
||||||
<div class="sb-context">
|
|
||||||
{
|
|
||||||
context.slots.context?.({
|
|
||||||
opened,
|
|
||||||
toggle,
|
|
||||||
close,
|
|
||||||
open,
|
|
||||||
}) || <SbButton {...{ onClick: toggle }}>Menu</SbButton>
|
|
||||||
}
|
|
||||||
<dialog
|
|
||||||
class="sb-context-menu"
|
|
||||||
open={opened.value ? true : undefined}
|
|
||||||
onClick={($event: Event) => {
|
|
||||||
// Make sure clicks inside do not autoclose this
|
|
||||||
$event.stopPropagation();
|
|
||||||
}}
|
|
||||||
{...{ onClose: close /* TODO: DialogHTMLAttributes needs an onClose handler type */ }}
|
|
||||||
>
|
|
||||||
{context.slots.default?.({
|
|
||||||
opened,
|
|
||||||
toggle,
|
|
||||||
close,
|
|
||||||
open,
|
|
||||||
}) || null}
|
|
||||||
</dialog>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
|
@ -1,119 +0,0 @@
|
||||||
import {
|
|
||||||
defineComponent,
|
|
||||||
provide,
|
|
||||||
shallowReactive,
|
|
||||||
ref,
|
|
||||||
watch,
|
|
||||||
PropType,
|
|
||||||
Ref,
|
|
||||||
} from 'vue';
|
|
||||||
import {
|
|
||||||
IBlockData,
|
|
||||||
IBlockDefinition,
|
|
||||||
IBlockLibrary,
|
|
||||||
ITreeNode,
|
|
||||||
OnUpdateBlockCb,
|
|
||||||
} from '../types';
|
|
||||||
import { model } from '../block-helpers';
|
|
||||||
import { SymMode, SbMode } from '../mode';
|
|
||||||
import { SymBlockLibrary} from '../use-dynamic-blocks';
|
|
||||||
import {
|
|
||||||
SymBlockTree,
|
|
||||||
SymBlockTreeRegister,
|
|
||||||
SymBlockTreeUnregister,
|
|
||||||
} from '../use-block-tree';
|
|
||||||
import { SymEditorDimensions, useResizeObserver } from '../use-resize-observer';
|
|
||||||
import { SymActiveBlock } from '../use-activation';
|
|
||||||
|
|
||||||
import { SbMainMenu } from './MainMenu';
|
|
||||||
import { SbBlockToolbar } from './BlockToolbar';
|
|
||||||
import { SbBlock } from './Block';
|
|
||||||
|
|
||||||
export interface ISbMainProps {
|
|
||||||
availableBlocks: IBlockDefinition<any>[];
|
|
||||||
block: IBlockData<any>;
|
|
||||||
eventUpdate: OnUpdateBlockCb;
|
|
||||||
mode: SbMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
import './Main.scss';
|
|
||||||
|
|
||||||
export const SbMain = defineComponent({
|
|
||||||
name: 'sb-main',
|
|
||||||
|
|
||||||
model,
|
|
||||||
|
|
||||||
props: {
|
|
||||||
availableBlocks: {
|
|
||||||
type: Array as PropType<IBlockDefinition<any>[]>,
|
|
||||||
default: () => [],
|
|
||||||
},
|
|
||||||
block: {
|
|
||||||
type: Object as PropType<IBlockData<any>>,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* Called when the block should be updated.
|
|
||||||
*/
|
|
||||||
eventUpdate: {
|
|
||||||
type: (null as unknown) as PropType<OnUpdateBlockCb>,
|
|
||||||
default: () => {},
|
|
||||||
},
|
|
||||||
mode: {
|
|
||||||
type: String as PropType<SbMode>,
|
|
||||||
validator(value: any) {
|
|
||||||
return Object.values(SbMode).includes(value);
|
|
||||||
},
|
|
||||||
default: SbMode.Edit,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
setup(props: ISbMainProps) {
|
|
||||||
const el: Ref<null|HTMLElement> = ref(null);
|
|
||||||
useResizeObserver(el, SymEditorDimensions);
|
|
||||||
|
|
||||||
const mode = ref(props.mode);
|
|
||||||
provide(SymMode, mode);
|
|
||||||
|
|
||||||
watch(() => props.mode, (newMode) => {
|
|
||||||
mode.value = newMode;
|
|
||||||
});
|
|
||||||
|
|
||||||
const activeBlock = ref(null);
|
|
||||||
provide(SymActiveBlock, activeBlock);
|
|
||||||
|
|
||||||
const blockTree: Ref<ITreeNode|null> = ref(null);
|
|
||||||
provide(SymBlockTree, blockTree);
|
|
||||||
provide(SymBlockTreeRegister, (block: ITreeNode) => { blockTree.value = block; });
|
|
||||||
provide(SymBlockTreeUnregister, () => { blockTree.value = null; });
|
|
||||||
|
|
||||||
const blockLibrary: IBlockLibrary = shallowReactive({
|
|
||||||
...props.availableBlocks.reduce(
|
|
||||||
(blocks: IBlockLibrary, block: IBlockDefinition<any>) => ({ ...blocks, [block.name]: block }),
|
|
||||||
{},
|
|
||||||
),
|
|
||||||
});
|
|
||||||
|
|
||||||
provide(SymBlockLibrary, blockLibrary);
|
|
||||||
|
|
||||||
return () => (
|
|
||||||
<div
|
|
||||||
class="sb-main"
|
|
||||||
ref={el}
|
|
||||||
>
|
|
||||||
{
|
|
||||||
mode.value === SbMode.Edit
|
|
||||||
? <>
|
|
||||||
<SbMainMenu block={props.block} />
|
|
||||||
<SbBlockToolbar />
|
|
||||||
</>
|
|
||||||
: null
|
|
||||||
}
|
|
||||||
<SbBlock
|
|
||||||
block={props.block}
|
|
||||||
eventUpdate={props.eventUpdate}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
|
@ -1,5 +0,0 @@
|
||||||
.sb-main-menu {
|
|
||||||
display: flex;
|
|
||||||
padding-bottom: 4rem;
|
|
||||||
background-color: var(--grey-0);
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
import {
|
|
||||||
defineComponent,
|
|
||||||
PropType,
|
|
||||||
} from 'vue';
|
|
||||||
import { IBlockData } from '../types';
|
|
||||||
import { SbTreeBlockSelect } from './TreeBlockSelect';
|
|
||||||
|
|
||||||
import './MainMenu.scss';
|
|
||||||
|
|
||||||
export const SbMainMenu = defineComponent({
|
|
||||||
name: 'sb-main-menu',
|
|
||||||
|
|
||||||
props: {
|
|
||||||
block: {
|
|
||||||
type: (null as unknown) as PropType<IBlockData<any>>,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
setup() {
|
|
||||||
return () => (
|
|
||||||
<div class="sb-main-menu">
|
|
||||||
<SbTreeBlockSelect />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
|
@ -1,7 +0,0 @@
|
||||||
import { defineAsyncComponent } from 'vue';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'sb-missing-block',
|
|
||||||
edit: defineAsyncComponent(() => import('./view')),
|
|
||||||
view: defineAsyncComponent(() => import('./view')),
|
|
||||||
};
|
|
|
@ -2,7 +2,7 @@
|
||||||
&__overlay {
|
&__overlay {
|
||||||
background-color: var(--grey-3-t);
|
background-color: var(--grey-3-t);
|
||||||
position: fixed;
|
position: fixed;
|
||||||
z-index: var(--z-modal);
|
z-index: 10;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
|
|
|
@ -5,6 +5,11 @@ import {
|
||||||
|
|
||||||
import './Modal.scss';
|
import './Modal.scss';
|
||||||
|
|
||||||
|
interface ModalProps {
|
||||||
|
open: boolean;
|
||||||
|
eventClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
export const SbModal = defineComponent({
|
export const SbModal = defineComponent({
|
||||||
name: 'sb-modal',
|
name: 'sb-modal',
|
||||||
|
|
||||||
|
@ -13,10 +18,10 @@ export const SbModal = defineComponent({
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
onClose: { type: Function, default: () => {} },
|
eventClose: { type: Function, default: () => {} },
|
||||||
},
|
},
|
||||||
|
|
||||||
setup(props, context) {
|
setup(props: ModalProps, context) {
|
||||||
const classes = computed(() => ({
|
const classes = computed(() => ({
|
||||||
'sb-modal': true,
|
'sb-modal': true,
|
||||||
'sb-modal_open': props.open,
|
'sb-modal_open': props.open,
|
||||||
|
@ -28,11 +33,11 @@ export const SbModal = defineComponent({
|
||||||
class="sb-modal__overlay"
|
class="sb-modal__overlay"
|
||||||
onClick={($event: MouseEvent) => {
|
onClick={($event: MouseEvent) => {
|
||||||
$event.stopPropagation();
|
$event.stopPropagation();
|
||||||
props.onClose();
|
props.eventClose();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div class="sb-modal__content">
|
<div class="sb-modal__content">
|
||||||
{context.slots.default?.()}
|
{context.slots.default()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
5
packages/core/lib/components/Schlechtenburg.scss
Normal file
5
packages/core/lib/components/Schlechtenburg.scss
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
.sb-main {
|
||||||
|
position: relative;
|
||||||
|
background-color: var(--bg);
|
||||||
|
padding: 50px 40px;
|
||||||
|
}
|
85
packages/core/lib/components/Schlechtenburg.tsx
Normal file
85
packages/core/lib/components/Schlechtenburg.tsx
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
import {
|
||||||
|
defineComponent,
|
||||||
|
provide,
|
||||||
|
shallowReactive,
|
||||||
|
ref,
|
||||||
|
watch,
|
||||||
|
PropType,
|
||||||
|
Ref,
|
||||||
|
} from 'vue';
|
||||||
|
import {
|
||||||
|
model,
|
||||||
|
Block,
|
||||||
|
BlockDefinition,
|
||||||
|
BlockLibraryDefinition,
|
||||||
|
} from '../blocks';
|
||||||
|
import { Mode, SbMode } from '../mode';
|
||||||
|
import { BlockLibrary } from '../use-dynamic-blocks';
|
||||||
|
import { EditorDimensions, useResizeObserver } from '../use-resize-observer';
|
||||||
|
import { ActiveBlock } from '../use-activation';
|
||||||
|
|
||||||
|
import { SbBlock } from './Block';
|
||||||
|
|
||||||
|
import './Schlechtenburg.scss';
|
||||||
|
|
||||||
|
export interface SchlechtenburgProps {
|
||||||
|
customBlocks: BlockDefinition[];
|
||||||
|
eventUpdate: (b: Block<any>) => void;
|
||||||
|
block: Block<any>;
|
||||||
|
mode: SbMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Schlechtenburg = defineComponent({
|
||||||
|
name: 'schlechtenburg-main',
|
||||||
|
|
||||||
|
model,
|
||||||
|
|
||||||
|
props: {
|
||||||
|
customBlocks: { type: Array as PropType<BlockDefinition[]>, default: () => [] },
|
||||||
|
block: { type: Object as PropType<Block<any>>, required: true },
|
||||||
|
eventUpdate: { type: Function, default: () => {} },
|
||||||
|
mode: {
|
||||||
|
type: String as PropType<SbMode>,
|
||||||
|
validator(value: any) {
|
||||||
|
return Object.values(SbMode).includes(value);
|
||||||
|
},
|
||||||
|
default: SbMode.Edit,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
setup(props: SchlechtenburgProps) {
|
||||||
|
const el: Ref<null|HTMLElement> = ref(null);
|
||||||
|
useResizeObserver(el, EditorDimensions);
|
||||||
|
|
||||||
|
const mode = ref(props.mode);
|
||||||
|
provide(Mode, mode);
|
||||||
|
|
||||||
|
const activeBlock = ref(null);
|
||||||
|
provide(ActiveBlock, activeBlock);
|
||||||
|
|
||||||
|
const blockLibrary: BlockLibraryDefinition = shallowReactive({
|
||||||
|
...props.customBlocks.reduce(
|
||||||
|
(blocks: {[name: string]: Block<any>}, block: Block<any>) => ({ ...blocks, [block.name]: block }),
|
||||||
|
{},
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
provide(BlockLibrary, blockLibrary);
|
||||||
|
|
||||||
|
watch(props.block, () => {
|
||||||
|
console.log('Update', props.block);
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => (
|
||||||
|
<div
|
||||||
|
class="sb-main"
|
||||||
|
ref={el}
|
||||||
|
>
|
||||||
|
<SbBlock
|
||||||
|
block={props.block}
|
||||||
|
eventUpdate={props.eventUpdate}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
|
@ -2,7 +2,6 @@
|
||||||
background-color: var(--grey-0);
|
background-color: var(--grey-0);
|
||||||
border: 1px solid var(--grey-2);
|
border: 1px solid var(--grey-2);
|
||||||
position: relative;
|
position: relative;
|
||||||
font-size: 1rem;
|
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
border: 1px solid var(--interact);
|
border: 1px solid var(--interact);
|
||||||
|
|
|
@ -1,29 +1,19 @@
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import './Select.scss';
|
import './Select.scss';
|
||||||
|
|
||||||
/**
|
|
||||||
* A select input in the schlechtenburg theme
|
|
||||||
* @sbui
|
|
||||||
*/
|
|
||||||
export const SbSelect = defineComponent({
|
export const SbSelect = defineComponent({
|
||||||
name: 'sb-select',
|
name: 'sb-select',
|
||||||
|
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
|
|
||||||
setup(_, context) {
|
setup(props, context) {
|
||||||
return () => (
|
return () => (
|
||||||
<div class="sb-select">
|
<div class="sb-select">
|
||||||
<select
|
<select
|
||||||
class="sb-select__input"
|
class="sb-select__input"
|
||||||
{...context.attrs}
|
{...context.attrs}
|
||||||
>
|
>
|
||||||
{
|
{context.slots.default()}
|
||||||
/**
|
|
||||||
* The select options list
|
|
||||||
* @slot default
|
|
||||||
*/
|
|
||||||
context.slots.default?.()
|
|
||||||
}
|
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -2,7 +2,4 @@
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: auto;
|
width: auto;
|
||||||
height: auto;
|
height: auto;
|
||||||
display: flex;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
z-index: var(--z-toolbar);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import debounce from 'lodash/debounce';
|
import { debounce } from 'lodash-es';
|
||||||
import {
|
import {
|
||||||
defineComponent,
|
defineComponent,
|
||||||
watch,
|
watch,
|
||||||
|
@ -8,10 +8,6 @@ import { useBlockSizing } from '../use-resize-observer';
|
||||||
|
|
||||||
import './Toolbar.scss';
|
import './Toolbar.scss';
|
||||||
|
|
||||||
/**
|
|
||||||
* Toolbar in the schlechtenburg theme
|
|
||||||
* @sbui
|
|
||||||
*/
|
|
||||||
export const SbToolbar = defineComponent({
|
export const SbToolbar = defineComponent({
|
||||||
name: 'sb-toolbar',
|
name: 'sb-toolbar',
|
||||||
|
|
||||||
|
@ -42,13 +38,7 @@ export const SbToolbar = defineComponent({
|
||||||
style={styles}
|
style={styles}
|
||||||
onClick={($event: MouseEvent) => $event.stopPropagation()}
|
onClick={($event: MouseEvent) => $event.stopPropagation()}
|
||||||
>
|
>
|
||||||
{
|
{context.slots?.default?.()}
|
||||||
/**
|
|
||||||
* The toolbar contents
|
|
||||||
* @slot default
|
|
||||||
*/
|
|
||||||
context.slots.default?.()
|
|
||||||
}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
.sb-tree-block-select {
|
|
||||||
&__list {
|
|
||||||
list-style: none;
|
|
||||||
color: var(--fg);
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
|
|
||||||
&_base {
|
|
||||||
padding-right: 1rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&__block {
|
|
||||||
padding: 0;
|
|
||||||
margin: 0;
|
|
||||||
padding-left: 1rem;
|
|
||||||
|
|
||||||
&-name {
|
|
||||||
display: block;
|
|
||||||
background: transparent;
|
|
||||||
border: 0;
|
|
||||||
font: inherit;
|
|
||||||
color: inherit;
|
|
||||||
padding: 0.25rem 0.5rem;
|
|
||||||
width: 100%;
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
&_active {
|
|
||||||
& > .sb-tree-block-select__block-name {
|
|
||||||
outline: 1px solid var(--interact);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,58 +0,0 @@
|
||||||
import { defineComponent } from 'vue';
|
|
||||||
import { ITreeNode } from '../types';
|
|
||||||
import { useBlockTree } from '../use-block-tree';
|
|
||||||
import { useActivation } from '../use-activation';
|
|
||||||
|
|
||||||
import { SbContextMenu } from './ContextMenu';
|
|
||||||
import { SbButton } from './Button';
|
|
||||||
|
|
||||||
import './TreeBlockSelect.scss';
|
|
||||||
|
|
||||||
export const SbTreeBlockSelect = defineComponent({
|
|
||||||
name: 'sb-main-menu',
|
|
||||||
|
|
||||||
setup() {
|
|
||||||
const { blockTree } = useBlockTree();
|
|
||||||
const {
|
|
||||||
activate,
|
|
||||||
activeBlockId,
|
|
||||||
} = useActivation();
|
|
||||||
|
|
||||||
const treeToHtml = (tree: ITreeNode, close: Function) => <li
|
|
||||||
class={{
|
|
||||||
'sb-tree-block-select__block': true,
|
|
||||||
'sb-tree-block-select__block_active': activeBlockId.value === tree.id,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
class="sb-tree-block-select__block-name"
|
|
||||||
onClick={() => {
|
|
||||||
activate(tree.id);
|
|
||||||
close();
|
|
||||||
}}
|
|
||||||
onMouseenter={() => activate(tree.id)}
|
|
||||||
>{tree.name}</button>
|
|
||||||
{tree.children?.length
|
|
||||||
? <ul class="sb-tree-block-select__list">
|
|
||||||
{tree.children?.map((child: ITreeNode) => treeToHtml(child, close))}
|
|
||||||
</ul>
|
|
||||||
: null
|
|
||||||
}
|
|
||||||
</li>;
|
|
||||||
|
|
||||||
|
|
||||||
return () => (
|
|
||||||
blockTree.value
|
|
||||||
? <SbContextMenu
|
|
||||||
class="sb-tree-block-select"
|
|
||||||
v-slots={{
|
|
||||||
context: ({ toggle }: { toggle: Function }) => <SbButton {...{ onClick: toggle }}>Tree</SbButton>,
|
|
||||||
default: ({ close }: { close: Function }) => <ul
|
|
||||||
class="sb-tree-block-select__list sb-tree-block-select__list_base"
|
|
||||||
>{treeToHtml(blockTree.value as ITreeNode, close)}</ul>,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
: ''
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
3
packages/core/lib/directives/activation-cover.js
Normal file
3
packages/core/lib/directives/activation-cover.js
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export default {
|
||||||
|
|
||||||
|
};
|
|
@ -1,9 +0,0 @@
|
||||||
.sb-hover-cover {
|
|
||||||
&:hover {
|
|
||||||
outline: 1px dashed var(--interact);
|
|
||||||
}
|
|
||||||
|
|
||||||
&_child-hovered:hover {
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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)
|
|
||||||
},
|
|
||||||
};
|
|
|
@ -1,13 +1,13 @@
|
||||||
export * from './mode';
|
export * from './mode';
|
||||||
export * from './types';
|
export * from './blocks';
|
||||||
|
|
||||||
export * from './block-helpers';
|
|
||||||
|
|
||||||
export * from './use-activation';
|
export * from './use-activation';
|
||||||
export * from './use-dynamic-blocks';
|
export * from './use-dynamic-blocks';
|
||||||
export * from './use-resize-observer';
|
export * from './use-resize-observer';
|
||||||
|
|
||||||
export * from './components/Main';
|
export * from './directives/activation-cover.js';
|
||||||
|
|
||||||
|
export * from './components/Schlechtenburg';
|
||||||
export * from './components/Block';
|
export * from './components/Block';
|
||||||
export * from './components/BlockPicker';
|
export * from './components/BlockPicker';
|
||||||
export * from './components/BlockOrdering';
|
export * from './components/BlockOrdering';
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
/**
|
|
||||||
* The mode the Schlechtenburg editor is currently in
|
|
||||||
*/
|
|
||||||
export enum SbMode {
|
export enum SbMode {
|
||||||
Edit = 'edit',
|
Edit = 'edit',
|
||||||
View = 'view',
|
Display = 'display',
|
||||||
}
|
}
|
||||||
export const SymMode = Symbol('Schlechtenburg mode');
|
export const Mode = Symbol('Schlechtenburg mode');
|
||||||
|
|
8
packages/core/lib/types.d.ts
vendored
8
packages/core/lib/types.d.ts
vendored
|
@ -1,8 +0,0 @@
|
||||||
/*
|
|
||||||
import {HTMLAttributes} from "vue";
|
|
||||||
|
|
||||||
interface DialogHTMLAttributes extends HTMLAttributes {
|
|
||||||
open?: boolean;
|
|
||||||
onClose?: Function;
|
|
||||||
}
|
|
||||||
*/
|
|
|
@ -1,172 +0,0 @@
|
||||||
import { Component } from 'vue';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Schlechtenburg keeps track of the rendered block tree.
|
|
||||||
* This is useful for e.g. the tree select component in the editor header.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
export interface ITreeNode {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
icon?: string;
|
|
||||||
children: ITreeNode[];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Schlechtenburg inputs and outputs a plain JS Object that can be JSON stringified. This is the
|
|
||||||
* interface type for that data structure. `T` will be the data type of the specific block being
|
|
||||||
*
|
|
||||||
* @see SbMain
|
|
||||||
*/
|
|
||||||
export interface IBlockData<T> {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
data: T;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback type for sending full block updates. SbBlock takes this as a prop.
|
|
||||||
*
|
|
||||||
* ```
|
|
||||||
* <SbBlock eventUpdate={myFn as OnUpdateSelfCb}></SbBlock>
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @see SbBlock
|
|
||||||
*/
|
|
||||||
export type OnUpdateBlockCb = (updated: IBlockData<any>) => void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback type for sending partial self-updates in edit mode.
|
|
||||||
*
|
|
||||||
* ```
|
|
||||||
* props: {
|
|
||||||
* eventUpdate: {
|
|
||||||
* type: (null as unknown) as PropType<OnUpdateSelfCb<IYourComponentData>>,
|
|
||||||
* default: () => {},
|
|
||||||
* },
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @see SbBlock
|
|
||||||
*/
|
|
||||||
export type OnUpdateSelfCb<T> = (updated: Partial<T>) => void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback type for sending blocks that should be prepended as a sibling before the current block
|
|
||||||
*
|
|
||||||
* ```
|
|
||||||
* props: {
|
|
||||||
* eventPrependBlock: {
|
|
||||||
* type: (null as unknown) as PropType<OnPrependBlockCb<IComponentToBePrependedData>>,
|
|
||||||
* default: () => {},
|
|
||||||
* },
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @see SbBlock
|
|
||||||
*/
|
|
||||||
export type OnPrependBlockCb = (block: IBlockData<any>) => void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback type for sending blocks that should be appended as a sibling after the current block
|
|
||||||
*
|
|
||||||
* ```
|
|
||||||
* props: {
|
|
||||||
* eventAppendBlock: {
|
|
||||||
* type: (null as unknown) as PropType<OnAppendBlockCb<IComponentToBeAppendedData>>,
|
|
||||||
* default: () => {},
|
|
||||||
* },
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @see SbBlock
|
|
||||||
*/
|
|
||||||
export type OnAppendBlockCb = (block: IBlockData<any>) => void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback type for removing the current block.
|
|
||||||
*
|
|
||||||
* ```
|
|
||||||
* props: {
|
|
||||||
* eventRemoveSelf: {
|
|
||||||
* type: (null as unknown) as PropType<OnRemoveSelfCb>,
|
|
||||||
* default: () => {},
|
|
||||||
* },
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @see SbBlock
|
|
||||||
*/
|
|
||||||
export type OnRemoveSelfCb = () => void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback type for activating the previous block.
|
|
||||||
*
|
|
||||||
* ```
|
|
||||||
* props: {
|
|
||||||
* eventActivatePrevious: {
|
|
||||||
* type: (null as unknown) as PropType<OnActivatePreviousCb>,
|
|
||||||
* default: (_i:number) => {},
|
|
||||||
* },
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @see SbBlock
|
|
||||||
*/
|
|
||||||
export type OnActivatePreviousCb = (_i:number) => void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Callback type for activating the next block.
|
|
||||||
*
|
|
||||||
* ```
|
|
||||||
* props: {
|
|
||||||
* eventActivateNext: {
|
|
||||||
* type: (null as unknown) as PropType<OnActivateNextCb>,
|
|
||||||
* default: (_i:number) => {},
|
|
||||||
* },
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @see SbBlock
|
|
||||||
*/
|
|
||||||
export type OnActivateNextCb = (_i:number) => void;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Any Block that you create
|
|
||||||
*
|
|
||||||
* @see IBlockDefinition
|
|
||||||
*/
|
|
||||||
export interface IBlockProps<T> {
|
|
||||||
blockId?: string;
|
|
||||||
data?: T,
|
|
||||||
eventUpdate?: OnUpdateSelfCb<T>;
|
|
||||||
eventPrependBlock?: OnPrependBlockCb;
|
|
||||||
eventAppendBlock?: OnAppendBlockCb;
|
|
||||||
eventRemoveSelf?: OnRemoveSelfCb;
|
|
||||||
eventActivateNext?: OnActivateNextCb;
|
|
||||||
eventActivatePrevious?: OnActivatePreviousCb;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Any Block that you create
|
|
||||||
*
|
|
||||||
* @see IBlockProps
|
|
||||||
*/
|
|
||||||
export interface IBlockDefinition<T> {
|
|
||||||
name: string;
|
|
||||||
icon?: string;
|
|
||||||
getDefaultData: T;
|
|
||||||
edit: Component<IBlockProps<T>>;
|
|
||||||
view: Component<IBlockProps<T>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Schlechtenburg maintains a library of blocks that are available
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
export interface IBlockLibrary {
|
|
||||||
[name: string]: IBlockDefinition<any>;
|
|
||||||
}
|
|
|
@ -3,34 +3,15 @@ import {
|
||||||
ref,
|
ref,
|
||||||
inject,
|
inject,
|
||||||
computed,
|
computed,
|
||||||
onBeforeUnmount,
|
|
||||||
} from 'vue';
|
} from 'vue';
|
||||||
|
|
||||||
export const SymActiveBlock = Symbol('Schlechtenburg active block');
|
export const ActiveBlock = Symbol('Schlechtenburg active block');
|
||||||
export function useActivation(currentBlockId: string|null = null) {
|
export function useActivation(currentBlockId: string) {
|
||||||
const activeBlockId: Ref<string|null> = inject(SymActiveBlock, ref(null));
|
const activeBlockId: Ref<string|null> = inject(ActiveBlock, ref(null));
|
||||||
|
|
||||||
const isActive = computed(() => activeBlockId.value === currentBlockId);
|
const isActive = computed(() => activeBlockId.value === currentBlockId);
|
||||||
|
const activate = (blockId?: string|null) => {
|
||||||
const deactivate = (id: string|null = currentBlockId) => {
|
activeBlockId.value = blockId !== undefined ? blockId : currentBlockId;
|
||||||
if (activeBlockId.value !== id) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
activeBlockId.value = null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const deactivateCb = (_:Event) => deactivate();
|
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
|
||||||
document.removeEventListener('click', deactivateCb);
|
|
||||||
})
|
|
||||||
|
|
||||||
const activate = (id: string|null = currentBlockId) => {
|
|
||||||
document.addEventListener('click', deactivateCb, { once: true });
|
|
||||||
activeBlockId.value = id;
|
|
||||||
};
|
|
||||||
|
|
||||||
const requestActivation = () => {
|
const requestActivation = () => {
|
||||||
if (activeBlockId.value) {
|
if (activeBlockId.value) {
|
||||||
return;
|
return;
|
||||||
|
@ -40,10 +21,8 @@ export function useActivation(currentBlockId: string|null = null) {
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
activeBlockId,
|
|
||||||
isActive,
|
isActive,
|
||||||
activate,
|
activate,
|
||||||
deactivate,
|
|
||||||
requestActivation,
|
requestActivation,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,85 +0,0 @@
|
||||||
import {
|
|
||||||
ref,
|
|
||||||
Ref,
|
|
||||||
reactive,
|
|
||||||
inject,
|
|
||||||
provide,
|
|
||||||
onUnmounted,
|
|
||||||
} from 'vue';
|
|
||||||
import {
|
|
||||||
ITreeNode,
|
|
||||||
IBlockData,
|
|
||||||
} from './types';
|
|
||||||
import { useDynamicBlocks } from './use-dynamic-blocks';
|
|
||||||
import { SbMode } from './mode';
|
|
||||||
|
|
||||||
export const SymBlockTree= Symbol('Schlechtenburg block tree');
|
|
||||||
export const SymBlockTreeRegister = Symbol('Schlechtenburg block tree register');
|
|
||||||
export const SymBlockTreeUnregister = Symbol('Schlechtenburg block tree unregister');
|
|
||||||
|
|
||||||
export function useBlockTree() {
|
|
||||||
const blockTree: Ref<ITreeNode|null> = inject(SymBlockTree, ref(null));
|
|
||||||
const registerWithParent = inject(SymBlockTreeRegister, (_b: ITreeNode, _i: number) => {});
|
|
||||||
const unregisterWithParent = inject(SymBlockTreeUnregister, (_b: ITreeNode) => {});
|
|
||||||
|
|
||||||
const self: ITreeNode = reactive({
|
|
||||||
id: '',
|
|
||||||
name: '',
|
|
||||||
icon: '',
|
|
||||||
children: [],
|
|
||||||
});
|
|
||||||
|
|
||||||
// Provide a registration function to child blocks
|
|
||||||
provide(SymBlockTreeRegister, (block: ITreeNode, index:number = -1) => {
|
|
||||||
if (self.children.find((child: ITreeNode) => child.id === block.id)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (index < 0) {
|
|
||||||
}
|
|
||||||
|
|
||||||
const normalizedIndex = index < 0 ? 0 : index;
|
|
||||||
|
|
||||||
self.children =[
|
|
||||||
...self.children.slice(0, normalizedIndex),
|
|
||||||
block,
|
|
||||||
...self.children.slice(normalizedIndex),
|
|
||||||
];
|
|
||||||
});
|
|
||||||
|
|
||||||
// Provide an unregistration function to child blocks
|
|
||||||
provide(SymBlockTreeUnregister, ({ id }: ITreeNode) => {
|
|
||||||
self.children = self.children.filter((child: ITreeNode) => child.id !== id);
|
|
||||||
});
|
|
||||||
|
|
||||||
const { mode } = useDynamicBlocks();
|
|
||||||
|
|
||||||
const register = (block: IBlockData<any>, index: number = 0) => {
|
|
||||||
if (!block.id) {
|
|
||||||
throw new Error(`Cannot register a block without an id: ${JSON.stringify(block)}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode.value !== SbMode.Edit) {
|
|
||||||
console.warn('Ignoring block tree registration requests outside of edit mode.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.id = block.id;
|
|
||||||
self.name = block.name;
|
|
||||||
|
|
||||||
// Register ourselves at the parent block
|
|
||||||
registerWithParent(self, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unregister from parent when we get destroyed
|
|
||||||
onUnmounted(() => {
|
|
||||||
if (self.id) {
|
|
||||||
unregisterWithParent(self);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
blockTree,
|
|
||||||
register,
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -3,14 +3,14 @@ import {
|
||||||
inject,
|
inject,
|
||||||
reactive,
|
reactive,
|
||||||
} from 'vue';
|
} from 'vue';
|
||||||
import { IBlockLibrary } from './types';
|
import { BlockLibraryDefinition } from './blocks';
|
||||||
import { SymMode, SbMode } from './mode';
|
import { Mode, SbMode } from './mode';
|
||||||
|
|
||||||
export const SymBlockLibrary = Symbol('Schlechtenburg block library');
|
export const BlockLibrary = Symbol('Schlechtenburg block library');
|
||||||
export function useDynamicBlocks() {
|
export function useDynamicBlocks() {
|
||||||
const mode = inject(SymMode, ref(SbMode.Edit));
|
const mode = inject(Mode, ref(SbMode.Edit));
|
||||||
const customBlocks: IBlockLibrary = inject(SymBlockLibrary, reactive({}));
|
const customBlocks: BlockLibraryDefinition = inject(BlockLibrary, reactive({}));
|
||||||
const getBlock = (name: string) => customBlocks[name];
|
const getBlock = (name: string) => customBlocks[name]?.[mode.value];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
mode,
|
mode,
|
||||||
|
|
|
@ -2,7 +2,6 @@ import {
|
||||||
Ref,
|
Ref,
|
||||||
ref,
|
ref,
|
||||||
inject,
|
inject,
|
||||||
onBeforeMount,
|
|
||||||
watch,
|
watch,
|
||||||
provide,
|
provide,
|
||||||
} from 'vue';
|
} from 'vue';
|
||||||
|
@ -14,8 +13,8 @@ interface BlockRect {
|
||||||
top: number;
|
top: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SymBlockDimensions = Symbol('Schlechtenburg block dimensions');
|
export const BlockDimensions = Symbol('Schlechtenburg block dimensions');
|
||||||
export const SymEditorDimensions = Symbol('Schlechtenburg editor dimensions');
|
export const EditorDimensions = Symbol('Schlechtenburg editor dimensions');
|
||||||
export function useResizeObserver(el: Ref<null|HTMLElement>, symbol: symbol) {
|
export function useResizeObserver(el: Ref<null|HTMLElement>, symbol: symbol) {
|
||||||
const dimensions: Ref<null|BlockRect> = ref(null);
|
const dimensions: Ref<null|BlockRect> = ref(null);
|
||||||
provide(symbol, dimensions);
|
provide(symbol, dimensions);
|
||||||
|
@ -33,25 +32,23 @@ export function useResizeObserver(el: Ref<null|HTMLElement>, symbol: symbol) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
onBeforeMount(() => {
|
const resizeObserver = new ResizeObserver(triggerSizeCalculation);
|
||||||
const resizeObserver = new ResizeObserver(triggerSizeCalculation);
|
const mutationObserver = new MutationObserver(triggerSizeCalculation);
|
||||||
const mutationObserver = new MutationObserver(triggerSizeCalculation);
|
|
||||||
|
|
||||||
watch(el, () => {
|
watch(el, () => {
|
||||||
if (!el.value) {
|
if (!el.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
resizeObserver.observe(el.value);
|
resizeObserver.observe(el.value);
|
||||||
mutationObserver.observe(el.value, { attributes: true, childList: false, subtree: false });
|
mutationObserver.observe(el.value, { attributes: true, childList: false, subtree: false });
|
||||||
});
|
});
|
||||||
})
|
|
||||||
|
|
||||||
return { triggerSizeCalculation, dimensions };
|
return { triggerSizeCalculation, dimensions };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useBlockSizing() {
|
export function useBlockSizing() {
|
||||||
const editorDimensions: Ref<BlockRect|null> = inject(SymEditorDimensions, ref(null));
|
const editorDimensions: Ref<BlockRect|null> = inject(EditorDimensions, ref(null));
|
||||||
const blockDimensions: Ref<BlockRect|null> = inject(SymBlockDimensions, ref(null));
|
const blockDimensions: Ref<BlockRect|null> = inject(BlockDimensions, ref(null));
|
||||||
|
|
||||||
return { editorDimensions, blockDimensions };
|
return { editorDimensions, blockDimensions };
|
||||||
}
|
}
|
||||||
|
|
1843
packages/core/package-lock.json
generated
1843
packages/core/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -6,18 +6,12 @@
|
||||||
"homepage": "",
|
"homepage": "",
|
||||||
"license": "GPL-3.0-or-later",
|
"license": "GPL-3.0-or-later",
|
||||||
"main": "lib/index.ts",
|
"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": {
|
"directories": {
|
||||||
"doc": "docs",
|
"lib": "lib",
|
||||||
"lib": "lib"
|
"test": "__tests__"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib",
|
"lib"
|
||||||
"docs"
|
|
||||||
],
|
],
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
|
@ -27,17 +21,7 @@
|
||||||
"url": "git@git.b12f.io:b12f/schlechtenburg.git"
|
"url": "git@git.b12f.io:b12f/schlechtenburg.git"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lodash": "^4.17.21",
|
"vue": "^3.0.4",
|
||||||
"uuid": "^8.3.2"
|
"lodash-es": "^4.17.20"
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"vue": "^3.2.31"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/lodash-es": "^4.17.4",
|
|
||||||
"@types/uuid": "^8.3.0",
|
|
||||||
"@vuedx/typecheck": "^0.6.3",
|
|
||||||
"@vuedx/typescript-plugin-vue": "^0.6.3",
|
|
||||||
"vue": "^3.4.23"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
"extends": "../../tsconfig.json",
|
|
||||||
"include": [
|
|
||||||
"lib/**/*.ts",
|
|
||||||
"lib/**/*.d.ts",
|
|
||||||
"lib/**/*.tsx",
|
|
||||||
"lib/**/*.vue"
|
|
||||||
]
|
|
||||||
}
|
|
7
packages/heading/__tests__/heading.test.js
Normal file
7
packages/heading/__tests__/heading.test.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const heading = require('..');
|
||||||
|
|
||||||
|
describe('@schlechtenburg/heading', () => {
|
||||||
|
it('needs tests');
|
||||||
|
});
|
|
@ -1,16 +0,0 @@
|
||||||
import { describe, expect, it } from 'vitest'
|
|
||||||
import { mount } from '@vue/test-utils';
|
|
||||||
import SbHeadingEdit from '../lib/edit';
|
|
||||||
import SbHeadingView from '../lib/view';
|
|
||||||
|
|
||||||
describe('@schlechtenburg/heading', () => {
|
|
||||||
it('edit should render', () => {
|
|
||||||
const edit = mount(SbHeadingEdit);
|
|
||||||
expect(edit.find('p').element).toBeTruthy();
|
|
||||||
expect(edit.find('div.sb-toolbar').element).toBeTruthy();
|
|
||||||
});
|
|
||||||
it('view should render', () => {
|
|
||||||
const edit = mount(SbHeadingView);
|
|
||||||
expect(edit.find('h1').element).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1 +0,0 @@
|
||||||
[]
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,220 +1 @@
|
||||||
import {
|
export default {};
|
||||||
defineComponent,
|
|
||||||
reactive,
|
|
||||||
computed,
|
|
||||||
ref,
|
|
||||||
Ref,
|
|
||||||
onMounted,
|
|
||||||
watch,
|
|
||||||
PropType,
|
|
||||||
} from 'vue';
|
|
||||||
import {
|
|
||||||
model,
|
|
||||||
useActivation,
|
|
||||||
SbToolbar,
|
|
||||||
SbSelect,
|
|
||||||
OnUpdateSelfCb,
|
|
||||||
OnAppendBlockCb,
|
|
||||||
OnRemoveSelfCb,
|
|
||||||
OnActivateNextCb,
|
|
||||||
OnActivatePreviousCb,
|
|
||||||
generateBlockId,
|
|
||||||
} from '@schlechtenburg/core';
|
|
||||||
import {
|
|
||||||
getDefaultData,
|
|
||||||
IHeadingData
|
|
||||||
} from './util';
|
|
||||||
import { getDefaultData as getDefaultParagraphData } from '@schlechtenburg/paragraph';
|
|
||||||
|
|
||||||
import './style.scss';
|
|
||||||
|
|
||||||
export default defineComponent({
|
|
||||||
name: 'sb-heading-edit',
|
|
||||||
|
|
||||||
model,
|
|
||||||
|
|
||||||
props: {
|
|
||||||
blockId: { type: String, required: true },
|
|
||||||
data: {
|
|
||||||
type: (null as unknown) as PropType<IHeadingData>,
|
|
||||||
default: getDefaultData,
|
|
||||||
},
|
|
||||||
eventUpdate: {
|
|
||||||
type: (null as unknown) as PropType<OnUpdateSelfCb<IHeadingData>>,
|
|
||||||
default: () => {},
|
|
||||||
},
|
|
||||||
eventAppendBlock: {
|
|
||||||
type: (null as unknown) as PropType<OnAppendBlockCb>,
|
|
||||||
default: () => {},
|
|
||||||
},
|
|
||||||
eventRemoveSelf: {
|
|
||||||
type: (null as unknown) as PropType<OnRemoveSelfCb>,
|
|
||||||
default: () => {},
|
|
||||||
},
|
|
||||||
eventActivateNext: {
|
|
||||||
type: (null as unknown) as PropType<OnActivateNextCb>,
|
|
||||||
default: () => {},
|
|
||||||
},
|
|
||||||
eventActivatePrevious: {
|
|
||||||
type: (null as unknown) as PropType<OnActivatePreviousCb>,
|
|
||||||
default: () => {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
setup(props) {
|
|
||||||
const localData = (reactive({
|
|
||||||
value: props.data.value,
|
|
||||||
align: props.data.align,
|
|
||||||
level: props.data.level,
|
|
||||||
focused: false,
|
|
||||||
}) as unknown) as {
|
|
||||||
value: string;
|
|
||||||
align: string;
|
|
||||||
level: number;
|
|
||||||
focused: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
const inputEl: Ref<null|HTMLElement> = ref(null);
|
|
||||||
|
|
||||||
const { isActive, activate } = useActivation(props.blockId);
|
|
||||||
|
|
||||||
const focusInput = () => {
|
|
||||||
if (inputEl.value && isActive.value) {
|
|
||||||
inputEl.value.focus();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
focusInput();
|
|
||||||
if (inputEl.value) {
|
|
||||||
inputEl.value.innerHTML = localData.value;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
watch(isActive, focusInput);
|
|
||||||
|
|
||||||
watch(() => props.data, () => {
|
|
||||||
localData.value = props.data.value;
|
|
||||||
localData.align = props.data.align;
|
|
||||||
localData.level = props.data.level;
|
|
||||||
if (inputEl.value) {
|
|
||||||
inputEl.value.innerHTML = localData.value;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const onTextUpdate = ($event: Event) => {
|
|
||||||
localData.value = ($event.target as HTMLElement).innerHTML;
|
|
||||||
};
|
|
||||||
|
|
||||||
const classes = computed(() => ({
|
|
||||||
'sb-heading': true,
|
|
||||||
'sb-heading_focused': localData.focused,
|
|
||||||
[`sb-heading_align-${localData.align}`]: true,
|
|
||||||
[`sb-heading_${localData.level}`]: true,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const setLevel = ($event: Event) => {
|
|
||||||
props.eventUpdate({
|
|
||||||
...localData,
|
|
||||||
level: parseInt(($event.target as HTMLSelectElement).value, 10),
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const setAlignment = ($event: Event) => {
|
|
||||||
props.eventUpdate({
|
|
||||||
...localData,
|
|
||||||
align: ($event.target as HTMLSelectElement).value,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const onFocus = () => {
|
|
||||||
localData.focused = true;
|
|
||||||
activate();
|
|
||||||
};
|
|
||||||
|
|
||||||
const onBlur = () => {
|
|
||||||
localData.focused = false;
|
|
||||||
props.eventUpdate({
|
|
||||||
value: localData.value,
|
|
||||||
align: localData.align,
|
|
||||||
level: localData.level,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const onKeydown = ($event: KeyboardEvent) => {
|
|
||||||
if ($event.key === 'Enter' && !$event.shiftKey) {
|
|
||||||
const id = generateBlockId();
|
|
||||||
props.eventAppendBlock({
|
|
||||||
id,
|
|
||||||
name: 'sb-paragraph',
|
|
||||||
data: getDefaultParagraphData(),
|
|
||||||
});
|
|
||||||
|
|
||||||
activate(id);
|
|
||||||
|
|
||||||
$event.preventDefault();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onKeyup = ($event: KeyboardEvent) => {
|
|
||||||
if ($event.key === 'Backspace' && localData.value === '') {
|
|
||||||
props.eventRemoveSelf();
|
|
||||||
}
|
|
||||||
|
|
||||||
const selection = window.getSelection();
|
|
||||||
const node = selection?.focusNode;
|
|
||||||
const childNodes = Array.from(inputEl?.value?.childNodes || []);
|
|
||||||
const index = node ? childNodes.indexOf(node as ChildNode) : -1;
|
|
||||||
if (node === inputEl.value || index === 0 || index === childNodes.length -1) {
|
|
||||||
switch ($event.key) {
|
|
||||||
case 'ArrowDown':
|
|
||||||
props.eventActivateNext();
|
|
||||||
break;
|
|
||||||
case 'ArrowUp':
|
|
||||||
props.eventActivatePrevious();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return () => (
|
|
||||||
<div class={classes.value}>
|
|
||||||
<SbToolbar>
|
|
||||||
<SbSelect
|
|
||||||
{...{
|
|
||||||
value: localData.level,
|
|
||||||
onChange: setLevel,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<option value={1}>h1</option>
|
|
||||||
<option value={2}>h2</option>
|
|
||||||
<option value={3}>h3</option>
|
|
||||||
<option value={4}>h4</option>
|
|
||||||
<option value={5}>h5</option>
|
|
||||||
<option value={6}>h6</option>
|
|
||||||
</SbSelect>
|
|
||||||
<SbSelect
|
|
||||||
{...{
|
|
||||||
value: localData.align,
|
|
||||||
onChange: setAlignment,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<option>left</option>
|
|
||||||
<option>center</option>
|
|
||||||
<option>right</option>
|
|
||||||
</SbSelect>
|
|
||||||
</SbToolbar>
|
|
||||||
<p
|
|
||||||
class="sb-heading__input"
|
|
||||||
ref={inputEl}
|
|
||||||
contenteditable
|
|
||||||
onInput={onTextUpdate}
|
|
||||||
onFocus={onFocus}
|
|
||||||
onBlur={onBlur}
|
|
||||||
onKeydown={onKeydown}
|
|
||||||
onKeyup={onKeyup}
|
|
||||||
></p>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
import { defineAsyncComponent } from 'vue';
|
import { defineAsyncComponent } from 'vue';
|
||||||
import { IBlockDefinition } from '@schlechtenburg/core';
|
|
||||||
import { getDefaultData } from './util';
|
import { getDefaultData } from './util';
|
||||||
|
|
||||||
export * from './util';
|
|
||||||
export const name = 'sb-heading';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name,
|
name: 'sb-heading',
|
||||||
getDefaultData,
|
getDefaultData,
|
||||||
edit: defineAsyncComponent(() => import('./edit')),
|
edit: defineAsyncComponent(() => import('./edit')),
|
||||||
view: defineAsyncComponent(() => import('./view')),
|
display: defineAsyncComponent(() => import('./edit')),
|
||||||
} as IBlockDefinition;
|
};
|
||||||
|
|
|
@ -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; } }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +1,2 @@
|
||||||
export interface IHeadingData {
|
export const a = 1;
|
||||||
value: string;
|
export const getDefaultData = () => ({});
|
||||||
align: string;
|
|
||||||
level: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getDefaultData: () => IHeadingData = () => ({
|
|
||||||
value: '',
|
|
||||||
align: 'left',
|
|
||||||
level: 1,
|
|
||||||
});
|
|
||||||
|
|
|
@ -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,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
1510
packages/heading/package-lock.json
generated
1510
packages/heading/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -4,15 +4,14 @@
|
||||||
"description": "> TODO: description",
|
"description": "> TODO: description",
|
||||||
"author": "Benjamin Bädorf <hello@benjaminbaedorf.eu>",
|
"author": "Benjamin Bädorf <hello@benjaminbaedorf.eu>",
|
||||||
"homepage": "",
|
"homepage": "",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "GPL-3.0-or-later",
|
||||||
"main": "lib/index.ts",
|
"main": "lib/index.ts",
|
||||||
"directories": {
|
"directories": {
|
||||||
"doc": "docs",
|
"lib": "lib",
|
||||||
"lib": "lib"
|
"test": "__tests__"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"lib",
|
"lib"
|
||||||
"docs"
|
|
||||||
],
|
],
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
|
@ -22,20 +21,10 @@
|
||||||
"url": "git@git.b12f.io:b12f/schlechtenburg.git"
|
"url": "git@git.b12f.io:b12f/schlechtenburg.git"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "npm run json-to-md:watch",
|
|
||||||
"typecheck": "vuedx-typecheck --no-pretty ./lib",
|
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
|
||||||
"vue": "^3.2.31"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@schlechtenburg/core": "^0.0.0",
|
"@schlechtenburg/core": "^0.0.0",
|
||||||
"@schlechtenburg/paragraph": "^0.0.0"
|
"vue": "^3.0.4"
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@vuedx/typecheck": "^0.6.3",
|
|
||||||
"@vuedx/typescript-plugin-vue": "^0.6.3",
|
|
||||||
"vue": "^3.2.31"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
"extends": "../../tsconfig.json",
|
|
||||||
"include": [
|
|
||||||
"lib/**/*.ts",
|
|
||||||
"lib/**/*.d.ts",
|
|
||||||
"lib/**/*.tsx",
|
|
||||||
"lib/**/*.vue"
|
|
||||||
]
|
|
||||||
}
|
|
7
packages/image/__tests__/image.test.js
Normal file
7
packages/image/__tests__/image.test.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const image = require('..');
|
||||||
|
|
||||||
|
describe('@schlechtenburg/image', () => {
|
||||||
|
it('needs tests');
|
||||||
|
});
|
|
@ -1,16 +0,0 @@
|
||||||
import { describe, expect, it } from 'vitest'
|
|
||||||
import { mount } from '@vue/test-utils';
|
|
||||||
import SbImageEdit from '../lib/edit';
|
|
||||||
import SbImageView from '../lib/view';
|
|
||||||
|
|
||||||
describe('@schlechtenburg/image', () => {
|
|
||||||
it('edit should render', () => {
|
|
||||||
const edit = mount(SbImageEdit);
|
|
||||||
expect(edit.find('figure').element).toBeTruthy();
|
|
||||||
expect(edit.find('div.sb-toolbar').element).toBeTruthy();
|
|
||||||
});
|
|
||||||
it('view should render', () => {
|
|
||||||
const edit = mount(SbImageView);
|
|
||||||
expect(edit.find('img').element).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1 +0,0 @@
|
||||||
[]
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,11 +1,14 @@
|
||||||
import { defineComponent, PropType } from 'vue';
|
import { defineComponent, PropType } from 'vue';
|
||||||
import {
|
import {
|
||||||
model,
|
model,
|
||||||
|
blockProps,
|
||||||
SbBlock,
|
SbBlock,
|
||||||
} from '@schlechtenburg/core';
|
} from '@schlechtenburg/core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getDefaultData,
|
getDefaultData,
|
||||||
IImageData,
|
ImageData,
|
||||||
|
ImageProps,
|
||||||
} from './util';
|
} from './util';
|
||||||
|
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
@ -16,13 +19,14 @@ export default defineComponent({
|
||||||
model,
|
model,
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
|
...blockProps,
|
||||||
data: {
|
data: {
|
||||||
type: (null as unknown) as PropType<IImageData>,
|
type: (null as unknown) as PropType<ImageData>,
|
||||||
default: getDefaultData,
|
default: getDefaultData,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
setup(props) {
|
setup(props: ImageProps) {
|
||||||
return () => <figure class="sb-image">
|
return () => <figure class="sb-image">
|
||||||
<img
|
<img
|
||||||
class="sb-image__content"
|
class="sb-image__content"
|
|
@ -8,16 +8,16 @@ import {
|
||||||
} from 'vue';
|
} from 'vue';
|
||||||
import {
|
import {
|
||||||
model,
|
model,
|
||||||
|
blockProps,
|
||||||
SbToolbar,
|
SbToolbar,
|
||||||
SbButton,
|
SbButton,
|
||||||
SbBlock,
|
SbBlock
|
||||||
IBlockData,
|
|
||||||
OnUpdateSelfCb,
|
|
||||||
} from '@schlechtenburg/core';
|
} from '@schlechtenburg/core';
|
||||||
import { IParagraphData } from '@schlechtenburg/paragraph';
|
|
||||||
import {
|
import {
|
||||||
getDefaultData,
|
getDefaultData,
|
||||||
IImageData,
|
ImageData,
|
||||||
|
ImageProps,
|
||||||
} from './util';
|
} from './util';
|
||||||
|
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
@ -28,17 +28,15 @@ export default defineComponent({
|
||||||
model,
|
model,
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
eventUpdate: {
|
...blockProps,
|
||||||
type: (null as unknown) as PropType<OnUpdateSelfCb<IImageData>>,
|
eventUpdate: { type: Function, default: () => {} },
|
||||||
default: () => {},
|
|
||||||
},
|
|
||||||
data: {
|
data: {
|
||||||
type: (null as unknown) as PropType<IImageData>,
|
type: (null as unknown) as PropType<ImageData>,
|
||||||
default: getDefaultData,
|
default: getDefaultData,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
setup(props) {
|
setup(props: ImageProps) {
|
||||||
const localData = reactive({
|
const localData = reactive({
|
||||||
src: props.data.src,
|
src: props.data.src,
|
||||||
alt: props.data.alt,
|
alt: props.data.alt,
|
||||||
|
@ -63,13 +61,8 @@ export default defineComponent({
|
||||||
if (fileInput.value && fileInput.value.files && fileInput.value.files.length) {
|
if (fileInput.value && fileInput.value.files && fileInput.value.files.length) {
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.addEventListener('load', () => {
|
reader.addEventListener('load', () => {
|
||||||
const src = reader?.result?.toString();
|
|
||||||
if (!src) {
|
|
||||||
throw new Error('Couldn\'t load image src');
|
|
||||||
}
|
|
||||||
|
|
||||||
props.eventUpdate({
|
props.eventUpdate({
|
||||||
src,
|
src: reader.result,
|
||||||
alt: props.data.alt,
|
alt: props.data.alt,
|
||||||
description: props.data.description,
|
description: props.data.description,
|
||||||
});
|
});
|
||||||
|
@ -79,7 +72,7 @@ export default defineComponent({
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onDescriptionUpdate = (description: IBlockData<IParagraphData>) => {
|
const onDescriptionUpdate = (description) => {
|
||||||
props.eventUpdate({
|
props.eventUpdate({
|
||||||
...props.data,
|
...props.data,
|
||||||
description,
|
description,
|
||||||
|
@ -90,7 +83,7 @@ export default defineComponent({
|
||||||
<figure class="sb-image">
|
<figure class="sb-image">
|
||||||
<SbToolbar>
|
<SbToolbar>
|
||||||
{localData.src
|
{localData.src
|
||||||
? <SbButton {...{ onClick: selectImage }}>Select Image</SbButton>
|
? <SbButton onClick={selectImage}>Change Image</SbButton>
|
||||||
: null}
|
: null}
|
||||||
<input
|
<input
|
||||||
type="file"
|
type="file"
|
||||||
|
@ -108,11 +101,10 @@ export default defineComponent({
|
||||||
/>
|
/>
|
||||||
<SbBlock
|
<SbBlock
|
||||||
block={localData.description}
|
block={localData.description}
|
||||||
onUpdate={(updated: IBlockData<IParagraphData>) => onDescriptionUpdate(updated)}
|
eventUpdate={(updated: Block) => onDescriptionUpdate(updated)}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
: <SbButton {...{ onClick: selectImage }}>Select Image</SbButton>
|
: <SbButton onClick={selectImage}>Select Image</SbButton>}
|
||||||
}
|
|
||||||
</figure>
|
</figure>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
import { defineAsyncComponent } from 'vue';
|
import { defineAsyncComponent } from 'vue';
|
||||||
import { getDefaultData } from './util';
|
import { getDefaultData } from './util';
|
||||||
|
|
||||||
export * from './util';
|
|
||||||
export const name = 'sb-image';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name,
|
name: 'sb-image',
|
||||||
getDefaultData,
|
getDefaultData,
|
||||||
edit: defineAsyncComponent(() => import('./edit')),
|
edit: defineAsyncComponent(() => import('./edit')),
|
||||||
view: defineAsyncComponent(() => import('./view')),
|
display: defineAsyncComponent(() => import('./display')),
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,25 +1,22 @@
|
||||||
import {
|
import {
|
||||||
IBlockData,
|
ParagraphData,
|
||||||
generateBlockId,
|
|
||||||
} from '@schlechtenburg/core';
|
|
||||||
import {
|
|
||||||
name as paragraphName,
|
|
||||||
IParagraphData,
|
|
||||||
getDefaultData as getDefaultParagraphData
|
getDefaultData as getDefaultParagraphData
|
||||||
} from '@schlechtenburg/paragraph';
|
} from '@schlechtenburg/paragraph';
|
||||||
|
import { BlockData, BlockProps } from '/@/blocks';
|
||||||
|
|
||||||
export interface IImageData {
|
export interface ImageData {
|
||||||
src: string;
|
src: string;
|
||||||
alt: string;
|
alt: string;
|
||||||
description: IBlockData<IParagraphData>;
|
description: ParagraphData;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getDefaultData: () => IImageData = () => ({
|
export interface ImageProps extends BlockProps {
|
||||||
|
data: ImageData;
|
||||||
|
eventUpdate: (b?: BlockData) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getDefaultData: () => ImageData = () => ({
|
||||||
src: '',
|
src: '',
|
||||||
alt: '',
|
alt: '',
|
||||||
description: {
|
description: getDefaultParagraphData(),
|
||||||
id: generateBlockId(),
|
|
||||||
name: paragraphName,
|
|
||||||
data: getDefaultParagraphData(),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue