Phase 0: Fundament für Inhaus
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7197eaebf2
commit
9c0f8de791
15771 changed files with 1564103 additions and 5 deletions
373
vendor/ueberdosis/tiptap-php/src/Core/DOMParser.php
vendored
Normal file
373
vendor/ueberdosis/tiptap-php/src/Core/DOMParser.php
vendored
Normal file
|
|
@ -0,0 +1,373 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Core;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMElement;
|
||||
use Tiptap\Utils\InlineStyle;
|
||||
use Tiptap\Utils\Minify;
|
||||
|
||||
class DOMParser
|
||||
{
|
||||
protected $DOM;
|
||||
|
||||
protected $schema;
|
||||
|
||||
protected $storedMarks = [];
|
||||
|
||||
public function __construct($schema)
|
||||
{
|
||||
$this->schema = $schema;
|
||||
}
|
||||
|
||||
public function process(string $value): array
|
||||
{
|
||||
$this->setDocument($value);
|
||||
|
||||
$content = $this->processChildren(
|
||||
$this->getDocumentBody()
|
||||
);
|
||||
|
||||
return [
|
||||
'type' => $this->schema->topNode::$name,
|
||||
'content' => $content,
|
||||
];
|
||||
}
|
||||
|
||||
private function setDocument(string $value): DOMParser
|
||||
{
|
||||
libxml_use_internal_errors(true);
|
||||
|
||||
$this->DOM = new DOMDocument;
|
||||
/**
|
||||
* @psalm-suppress ArgumentTypeCoercion
|
||||
*/
|
||||
$this->DOM->loadHTML(
|
||||
$this->makeValidXMLDocument(
|
||||
$this->minify($value)
|
||||
)
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function minify(string $value): string
|
||||
{
|
||||
return (new Minify)->process($value);
|
||||
}
|
||||
|
||||
private function makeValidXMLDocument($value): string
|
||||
{
|
||||
return '<?xml encoding="utf-8" ?>' . $value;
|
||||
}
|
||||
|
||||
private function getDocumentBody(): DOMElement
|
||||
{
|
||||
return $this->DOM->getElementsByTagName('body')->item(0);
|
||||
}
|
||||
|
||||
private function processChildren($node): array
|
||||
{
|
||||
$nodes = [];
|
||||
|
||||
foreach ($node->childNodes as $child) {
|
||||
if ($class = $this->getNodeFor($child)) {
|
||||
$item = $this->parseAttributes($class, $child);
|
||||
|
||||
if ($item === null) {
|
||||
if ($child->hasChildNodes()) {
|
||||
$nodes = array_merge($nodes, $this->processChildren($child));
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($child->hasChildNodes()) {
|
||||
$item = array_merge($item, [
|
||||
'content' => $this->processChildren($child),
|
||||
]);
|
||||
}
|
||||
|
||||
if (count($this->storedMarks)) {
|
||||
$item = array_merge($item, [
|
||||
'marks' => $this->storedMarks,
|
||||
]);
|
||||
}
|
||||
|
||||
array_push($nodes, $item);
|
||||
} elseif ($class = $this->getMarkFor($child)) {
|
||||
array_push($this->storedMarks, $this->parseAttributes($class, $child));
|
||||
|
||||
if ($child->hasChildNodes()) {
|
||||
$nodes = array_merge($nodes, $this->processChildren($child));
|
||||
}
|
||||
|
||||
array_pop($this->storedMarks);
|
||||
} elseif ($child->hasChildNodes()) {
|
||||
$nodes = array_merge($nodes, $this->processChildren($child));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If similar nodes with different text follow each other,
|
||||
// we can merge them into a single node.
|
||||
return $this->mergeSimilarNodes($nodes);
|
||||
}
|
||||
|
||||
private function isMultidimensionalArray($array)
|
||||
{
|
||||
foreach ($array as $value) {
|
||||
if (is_array($value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function mergeSimilarNodes($nodes)
|
||||
{
|
||||
$result = [];
|
||||
|
||||
/**
|
||||
* @psalm-suppress UnusedFunctionCall
|
||||
*/
|
||||
array_reduce($nodes, function ($carry, $node) use (&$result) {
|
||||
// Ignore multidimensional arrays
|
||||
if ($this->isMultidimensionalArray($node) || $this->isMultidimensionalArray($carry)) {
|
||||
$result[] = $node;
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
// Check if text is the only difference
|
||||
$differentKeys = array_keys(array_diff($carry, $node));
|
||||
if ($differentKeys != ['text']) {
|
||||
$result[] = $node;
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
// Merge it!
|
||||
$result[count($result) - 1]['text'] .= $node['text'];
|
||||
|
||||
return $result[count($result) - 1];
|
||||
}, []);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
private function getNodeFor($item)
|
||||
{
|
||||
return $this->getExtensionFor($item, $this->schema->nodes);
|
||||
}
|
||||
|
||||
private function getMarkFor($item)
|
||||
{
|
||||
return $this->getExtensionFor($item, $this->schema->marks);
|
||||
}
|
||||
|
||||
private function getExtensionFor($node, $classes)
|
||||
{
|
||||
$parseRules = [];
|
||||
|
||||
foreach ($classes as $class) {
|
||||
$classParseRules = $this->getClassParseRules($class, $node);
|
||||
$parseRules = array_merge($parseRules, $classParseRules);
|
||||
}
|
||||
|
||||
usort($parseRules, fn ($parseRuleA, $parseRuleB) => $parseRuleB['priority'] - $parseRuleA['priority']);
|
||||
|
||||
foreach ($parseRules as $parseRule) {
|
||||
if ($this->checkParseRule($parseRule, $node)) {
|
||||
return $parseRule['class'];
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function getClassParseRules($class, $node): array
|
||||
{
|
||||
$parseRules = $class->parseHTML($node);
|
||||
|
||||
if (! is_array($parseRules)) {
|
||||
return [];
|
||||
}
|
||||
$classParseRules = [];
|
||||
foreach ($parseRules as $parseRule) {
|
||||
$parseRule['class'] = $class;
|
||||
$parseRule['priority'] = $parseRule['priority'] ?? 50;
|
||||
$classParseRules[] = $parseRule;
|
||||
}
|
||||
|
||||
return $classParseRules;
|
||||
}
|
||||
|
||||
private function checkParseRule($parseRule, $DOMNode): bool
|
||||
{
|
||||
// ['tag' => 'span[type="mention"]']
|
||||
if (isset($parseRule['tag'])) {
|
||||
if (preg_match('/([a-zA-Z-]*)\[([a-z-]+)(="?([a-zA-Z]*)"?)?\]$/', $parseRule['tag'], $matches)) {
|
||||
$tag = $matches[1];
|
||||
$attribute = $matches[2];
|
||||
if (isset($matches[4])) {
|
||||
$value = $matches[4];
|
||||
}
|
||||
} else {
|
||||
$tag = $parseRule['tag'];
|
||||
}
|
||||
|
||||
if ($tag !== $DOMNode->nodeName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($attribute) && ! $DOMNode->hasAttribute($attribute)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($attribute) && isset($value) && $DOMNode->getAttribute($attribute) !== $value) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ['style' => 'font-weight=italic']
|
||||
if (isset($parseRule['style'])) {
|
||||
if (preg_match('/([a-zA-Z-]*)(="?([a-zA-Z-]*)"?)?$/', $parseRule['style'], $matches)) {
|
||||
$style = $matches[1];
|
||||
|
||||
if (isset($matches[3])) {
|
||||
$value = $matches[3];
|
||||
}
|
||||
} else {
|
||||
$style = $parseRule['style'];
|
||||
}
|
||||
|
||||
if (! InlineStyle::hasAttribute($DOMNode, $style)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($value) && InlineStyle::getAttribute($DOMNode, $style) !== $value) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ['getAttrs' => function($DOMNode) { … }]
|
||||
if (isset($parseRule['getAttrs'])) {
|
||||
if (isset($parseRule['style']) && InlineStyle::hasAttribute($DOMNode, $parseRule['style'])) {
|
||||
$parameter = InlineStyle::getAttribute($DOMNode, $parseRule['style']);
|
||||
} else {
|
||||
$parameter = $DOMNode;
|
||||
}
|
||||
|
||||
if ($parseRule['getAttrs']($parameter) === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
! is_array($parseRule)
|
||||
|| ! count($parseRule)
|
||||
|| (
|
||||
! isset($parseRule['tag'])
|
||||
&& ! isset($parseRule['style'])
|
||||
&& ! isset($parseRule['getAttrs'])
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return (array|mixed|string)[]|null
|
||||
*
|
||||
* @psalm-return array{type: mixed, text?: string, attrs?: array}|null
|
||||
*/
|
||||
private function parseAttributes($class, $DOMNode): ?array
|
||||
{
|
||||
$item = [
|
||||
'type' => $class::$name,
|
||||
];
|
||||
|
||||
if ($class::$name === 'text') {
|
||||
$text = ltrim($DOMNode->nodeValue, "\n");
|
||||
|
||||
if ($text === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$item = array_merge($item, [
|
||||
'text' => $text,
|
||||
]);
|
||||
}
|
||||
|
||||
$parseRules = $class->parseHTML();
|
||||
|
||||
if (! is_array($parseRules)) {
|
||||
return $item;
|
||||
}
|
||||
|
||||
foreach ($parseRules as $parseRule) {
|
||||
if (! $this->checkParseRule($parseRule, $DOMNode)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$attributes = $parseRule['attrs'] ?? [];
|
||||
if (count($attributes)) {
|
||||
if (! isset($item['attrs'])) {
|
||||
$item['attrs'] = [];
|
||||
}
|
||||
|
||||
$item['attrs'] = array_merge($item['attrs'], $attributes);
|
||||
}
|
||||
|
||||
if (isset($parseRule['getAttrs'])) {
|
||||
if (isset($parseRule['style']) && InlineStyle::hasAttribute($DOMNode, $parseRule['style'])) {
|
||||
$parameter = InlineStyle::getAttribute($DOMNode, $parseRule['style']);
|
||||
} else {
|
||||
$parameter = $DOMNode;
|
||||
}
|
||||
|
||||
$attributes = $parseRule['getAttrs']($parameter);
|
||||
|
||||
if (! is_array($attributes)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! isset($item['attrs'])) {
|
||||
$item['attrs'] = [];
|
||||
}
|
||||
|
||||
$item['attrs'] = array_merge($item['attrs'], $attributes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* public function addAttributes()
|
||||
* {
|
||||
* return [
|
||||
* 'href' => [
|
||||
* 'parseHTML' => function ($DOMNode) {
|
||||
* $attrs['href'] = $DOMNode->getAttribute('href');
|
||||
* }
|
||||
* ],
|
||||
* ];
|
||||
* }
|
||||
*/
|
||||
foreach ($this->schema->getAttributeConfigurations($class) as $attribute => $configuration) {
|
||||
if (isset($configuration['parseHTML'])) {
|
||||
$value = $configuration['parseHTML']($DOMNode);
|
||||
} else {
|
||||
$value = $DOMNode->getAttribute($attribute) ?: null;
|
||||
}
|
||||
|
||||
if ($value !== null) {
|
||||
$item['attrs'][$attribute] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
408
vendor/ueberdosis/tiptap-php/src/Core/DOMSerializer.php
vendored
Normal file
408
vendor/ueberdosis/tiptap-php/src/Core/DOMSerializer.php
vendored
Normal file
|
|
@ -0,0 +1,408 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Core;
|
||||
|
||||
use DOMDocument;
|
||||
use stdClass;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class DOMSerializer
|
||||
{
|
||||
protected $document;
|
||||
|
||||
protected $schema;
|
||||
|
||||
public function __construct($schema)
|
||||
{
|
||||
$this->schema = $schema;
|
||||
}
|
||||
|
||||
private function renderNode($node, $previousNode = null, $nextNode = null, &$markStack = []): string
|
||||
{
|
||||
$html = [];
|
||||
$markTagsToClose = [];
|
||||
|
||||
if (isset($node->marks)) {
|
||||
foreach ($node->marks as $mark) {
|
||||
foreach ($this->schema->marks as $class) {
|
||||
$renderClass = $class;
|
||||
|
||||
if (! $this->isMarkOrNode($mark, $renderClass)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! $this->markShouldOpen($mark, $previousNode)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$html[] = $this->renderOpeningTag($renderClass, $mark);
|
||||
# push recently created mark tag to the stack
|
||||
$markStack[] = [$renderClass, $mark];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->schema->nodes as $extension) {
|
||||
if (! $this->isMarkOrNode($node, $extension)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$html[] = $this->renderOpeningTag($extension, $node);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// ["content" => …]
|
||||
$lastKey = array_key_last($html);
|
||||
$lastElement = $html[$lastKey] ?? null;
|
||||
if (! is_null($lastKey) && isset($lastElement['content'])) {
|
||||
$html[$lastKey] = $lastElement['content'];
|
||||
}
|
||||
// child nodes
|
||||
elseif (isset($node->content)) {
|
||||
$nestedNodeMarkStack = [];
|
||||
foreach ($node->content as $index => $nestedNode) {
|
||||
$previousNestedNode = $node->content[$index - 1] ?? null;
|
||||
$nextNestedNode = $node->content[$index + 1] ?? null;
|
||||
|
||||
$html[] = $this->renderNode($nestedNode, $previousNestedNode, $nextNestedNode, $nestedNodeMarkStack);
|
||||
}
|
||||
}
|
||||
// renderText($node)
|
||||
elseif (isset($extension) && method_exists($extension, 'renderText')) {
|
||||
$html[] = $extension->renderText($node);
|
||||
}
|
||||
// text
|
||||
elseif (isset($node->text)) {
|
||||
$html[] = htmlspecialchars($node->text, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
foreach ($this->schema->nodes as $extension) {
|
||||
if (! $this->isMarkOrNode($node, $extension)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$html[] = $this->renderClosingTag($extension->renderHTML($node));
|
||||
}
|
||||
|
||||
if (isset($node->marks)) {
|
||||
foreach (array_reverse($node->marks) as $mark) {
|
||||
foreach ($this->schema->marks as $extension) {
|
||||
if (! $this->isMarkOrNode($mark, $extension)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! $this->markShouldClose($mark, $nextNode)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
# remember which mark tags to close
|
||||
$markTagsToClose[] = [$extension, $mark];
|
||||
}
|
||||
}
|
||||
# close mark tags and reopen when necessary
|
||||
$html = array_merge($html, $this->closeAndReopenTags($markTagsToClose, $markStack));
|
||||
}
|
||||
|
||||
return join($html);
|
||||
}
|
||||
|
||||
private function closeAndReopenTags(array $markTagsToClose, array &$markStack): array
|
||||
{
|
||||
$markTagsToReopen = [];
|
||||
$closingTags = $this->closeMarkTags($markTagsToClose, $markStack, $markTagsToReopen);
|
||||
$reopeningTags = $this->reopenMarkTags($markTagsToReopen, $markStack);
|
||||
|
||||
return array_merge($closingTags, $reopeningTags);
|
||||
}
|
||||
|
||||
private function closeMarkTags($markTagsToClose, &$markStack, &$markTagsToReopen): array
|
||||
{
|
||||
$html = [];
|
||||
while (! empty($markTagsToClose)) {
|
||||
# close mark tag from the top of the stack
|
||||
$markTag = array_pop($markStack);
|
||||
$markExtension = $markTag[0];
|
||||
$mark = $markTag[1];
|
||||
$html[] = $this->renderClosingTag($markExtension->renderHTML($mark));
|
||||
|
||||
# check if the last closed tag is overlapping and has to be reopened
|
||||
# find the first matching mark to close
|
||||
$foundIndex = null;
|
||||
foreach ($markTagsToClose as $index => $markToClose) {
|
||||
if ($markExtension == $markToClose[0] && $mark == $markToClose[1]) {
|
||||
$foundIndex = $index;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($foundIndex === null) {
|
||||
$markTagsToReopen[] = $markTag;
|
||||
} else {
|
||||
# specific mark tag does not have to be reopened, but deleted from the 'to close' list
|
||||
unset($markTagsToClose[$foundIndex]);
|
||||
$markTagsToClose = array_values($markTagsToClose); // Re-index array
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
private function reopenMarkTags($markTagsToReopen, &$markStack): array
|
||||
{
|
||||
$html = [];
|
||||
# reopen the overlapping mark tags and push them to the stack
|
||||
foreach (array_reverse($markTagsToReopen) as $markTagToOpen) {
|
||||
$renderClass = $markTagToOpen[0];
|
||||
$mark = $markTagToOpen[1];
|
||||
$html[] = $this->renderOpeningTag($renderClass, $mark);
|
||||
$markStack[] = [$renderClass, $mark];
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
private function isMarkOrNode($markOrNode, $renderClass): bool
|
||||
{
|
||||
return isset($markOrNode->type) && $markOrNode->type === $renderClass::$name;
|
||||
}
|
||||
|
||||
private function markShouldOpen($mark, $previousNode): bool
|
||||
{
|
||||
return $this->nodeHasMark($previousNode, $mark);
|
||||
}
|
||||
|
||||
private function markShouldClose($mark, $nextNode): bool
|
||||
{
|
||||
return $this->nodeHasMark($nextNode, $mark);
|
||||
}
|
||||
|
||||
private function nodeHasMark($node, $mark): bool
|
||||
{
|
||||
if (! $node) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (! property_exists($node, 'marks')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// The other node has same mark
|
||||
foreach ($node->marks as $otherMark) {
|
||||
if ($mark == $otherMark) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function renderOpeningTag($extension, $nodeOrMark, $renderHTML = false)
|
||||
{
|
||||
/**
|
||||
* public function addAttributes()
|
||||
* {
|
||||
* return [
|
||||
* 'color' => [
|
||||
* 'renderHTML' => function ($attributes) {
|
||||
* return [
|
||||
* 'style' => "color: {$attributes['color']}",
|
||||
* ];
|
||||
* }
|
||||
* ],
|
||||
* ];
|
||||
* }
|
||||
*/
|
||||
$HTMLAttributes = [];
|
||||
|
||||
foreach ($this->schema->getAttributeConfigurations($extension) as $attribute => $configuration) {
|
||||
// 'rendered' => false
|
||||
if (isset($configuration['rendered']) && $configuration['rendered'] === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 'default' => 'foobar'
|
||||
if (! isset($nodeOrMark->attrs->{$attribute}) && isset($configuration['default'])) {
|
||||
if (! isset($nodeOrMark->attrs)) {
|
||||
$nodeOrMark->attrs = new stdClass;
|
||||
}
|
||||
|
||||
$nodeOrMark->attrs->{$attribute} = $configuration['default'];
|
||||
}
|
||||
|
||||
// 'renderHTML' => fn($attributes) …
|
||||
if (isset($configuration['renderHTML'])) {
|
||||
$value = $configuration['renderHTML']($nodeOrMark->attrs ?? new stdClass);
|
||||
} else {
|
||||
$value = [
|
||||
$attribute => $nodeOrMark->attrs->{$attribute} ?? null,
|
||||
];
|
||||
}
|
||||
|
||||
if ($value !== null) {
|
||||
$HTMLAttributes = HTML::mergeAttributes($HTMLAttributes, $value);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove empty attributes
|
||||
$HTMLAttributes = array_filter($HTMLAttributes, fn ($HTMLAttribute) => $HTMLAttribute !== null);
|
||||
|
||||
if ($renderHTML === false) {
|
||||
$renderHTML = $extension->renderHTML($nodeOrMark, $HTMLAttributes);
|
||||
}
|
||||
|
||||
// ["content" => …]
|
||||
if (isset($renderHTML['content'])) {
|
||||
return $renderHTML;
|
||||
}
|
||||
|
||||
// null
|
||||
if (is_null($renderHTML)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// ['table', ['tbody', 0]]
|
||||
// ['table', ['class' => 'foobar'], ['tbody', 0]]
|
||||
if (is_array($renderHTML)) {
|
||||
$html = [];
|
||||
|
||||
foreach ($renderHTML as $index => $renderInstruction) {
|
||||
// ['div', …]
|
||||
if (is_string($renderInstruction)) {
|
||||
if (is_integer($index) && $nextTag = $renderHTML[$index + 1] ?? null) {
|
||||
// ['table', ['class' => 'custom-class']]
|
||||
if (! in_array(0, $nextTag, true)) {
|
||||
if (is_array($nextTag) && $this->isAnAttributeArray($nextTag)) {
|
||||
$attributes = HTML::renderAttributes($nextTag);
|
||||
} else {
|
||||
$attributes = '';
|
||||
}
|
||||
|
||||
// <a href="#">
|
||||
$html[] = "<{$renderInstruction}{$attributes}>";
|
||||
} else {
|
||||
$html[] = "<{$renderInstruction}>";
|
||||
}
|
||||
} else {
|
||||
$html[] = "<{$renderInstruction}>";
|
||||
}
|
||||
|
||||
// ['div', 'span']
|
||||
if (isset($nextTag) && is_array($nextTag) && ! in_array(0, $nextTag, true)) {
|
||||
if (! $this->isAnAttributeArray($nextTag)) {
|
||||
$html[] = $this->renderOpeningTag($extension, $nodeOrMark, $nextTag);
|
||||
$html[] = $this->renderClosingTag($nextTag);
|
||||
}
|
||||
}
|
||||
|
||||
// ['div', ?, 'span']
|
||||
if (is_integer($index) && $nextTag = $renderHTML[$index + 2] ?? null) {
|
||||
if (! in_array(0, $nextTag, true)) {
|
||||
if (! $this->isAnAttributeArray($nextTag)) {
|
||||
$html[] = $this->renderOpeningTag($extension, $nodeOrMark, $nextTag);
|
||||
$html[] = $this->renderClosingTag($nextTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
// ['tbody', 0]
|
||||
elseif (is_array($renderInstruction) && in_array(0, $renderInstruction, true)) {
|
||||
$html[] = $this->renderOpeningTag($extension, $nodeOrMark, $renderInstruction);
|
||||
}
|
||||
// ['class' => 'foobar']
|
||||
elseif (is_array($renderInstruction)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return join($html);
|
||||
}
|
||||
|
||||
throw new \Exception('[renderOpeningTag] Failed to use renderHTML: ' . json_encode($renderHTML));
|
||||
}
|
||||
|
||||
private function isAnAttributeArray($items): bool
|
||||
{
|
||||
if (! is_array($items)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$keys = array_keys($items);
|
||||
|
||||
return $keys !== array_keys($keys);
|
||||
}
|
||||
|
||||
private function isSelfClosing($tag): bool
|
||||
{
|
||||
$dom = new DOMDocument('1.0', 'utf-8');
|
||||
$element = $dom->createElement($tag, 'test');
|
||||
$dom->appendChild($element);
|
||||
$rendered = $dom->saveHTML();
|
||||
|
||||
return substr_count($rendered, $tag) === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
private function renderClosingTag($renderHTML)
|
||||
{
|
||||
// null
|
||||
if (is_null($renderHTML)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// ["content" => …]
|
||||
if (isset($renderHTML['content'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
// ['table', ['tbody']]
|
||||
if (is_array($renderHTML)) {
|
||||
$html = [];
|
||||
|
||||
foreach (array_reverse($renderHTML) as $renderInstruction) {
|
||||
// 'div'
|
||||
if (is_string($renderInstruction)) {
|
||||
if ($this->isSelfClosing($renderInstruction)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$html[] = "</{$renderInstruction}>";
|
||||
}
|
||||
// ['div', 0]
|
||||
elseif (is_array($renderInstruction) && in_array(0, $renderInstruction, true)) {
|
||||
$html[] = $this->renderClosingTag($renderInstruction);
|
||||
}
|
||||
}
|
||||
|
||||
return join($html);
|
||||
}
|
||||
|
||||
throw new \Exception('[renderClosingTag] Failed to use renderHTML: ' . json_encode($renderHTML));
|
||||
}
|
||||
|
||||
public function process(array $value): string
|
||||
{
|
||||
$html = [];
|
||||
|
||||
// transform document to object
|
||||
$this->document = json_decode(json_encode($value));
|
||||
|
||||
$content = is_array($this->document->content) ? $this->document->content : [];
|
||||
|
||||
$markStack = [];
|
||||
|
||||
foreach ($content as $index => $node) {
|
||||
$previousNode = $content[$index - 1] ?? null;
|
||||
$nextNode = $content[$index + 1] ?? null;
|
||||
|
||||
$html[] = $this->renderNode($node, $previousNode, $nextNode, $markStack);
|
||||
}
|
||||
|
||||
return join($html);
|
||||
}
|
||||
}
|
||||
32
vendor/ueberdosis/tiptap-php/src/Core/Extension.php
vendored
Normal file
32
vendor/ueberdosis/tiptap-php/src/Core/Extension.php
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Core;
|
||||
|
||||
class Extension
|
||||
{
|
||||
public static $name;
|
||||
|
||||
public static $priority = 100;
|
||||
|
||||
public $options = [];
|
||||
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
$this->options = array_merge($this->addOptions(), $options);
|
||||
}
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function addGlobalAttributes()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function addExtensions()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
15
vendor/ueberdosis/tiptap-php/src/Core/JSONSerializer.php
vendored
Normal file
15
vendor/ueberdosis/tiptap-php/src/Core/JSONSerializer.php
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Core;
|
||||
|
||||
class JSONSerializer
|
||||
{
|
||||
protected $document;
|
||||
|
||||
public function process(array $value): string
|
||||
{
|
||||
$this->document = json_decode(json_encode($value));
|
||||
|
||||
return json_encode($this->document);
|
||||
}
|
||||
}
|
||||
23
vendor/ueberdosis/tiptap-php/src/Core/Mark.php
vendored
Normal file
23
vendor/ueberdosis/tiptap-php/src/Core/Mark.php
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Core;
|
||||
|
||||
class Mark extends Extension
|
||||
{
|
||||
public static $priority = 100;
|
||||
|
||||
public function addAttributes()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function renderHTML($mark)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
27
vendor/ueberdosis/tiptap-php/src/Core/Node.php
vendored
Normal file
27
vendor/ueberdosis/tiptap-php/src/Core/Node.php
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Core;
|
||||
|
||||
class Node extends Extension
|
||||
{
|
||||
public static $priority = 100;
|
||||
|
||||
public static $topNode = false;
|
||||
|
||||
public static $marks = '_';
|
||||
|
||||
public function addAttributes()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function renderHTML($node)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
119
vendor/ueberdosis/tiptap-php/src/Core/Schema.php
vendored
Normal file
119
vendor/ueberdosis/tiptap-php/src/Core/Schema.php
vendored
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Core;
|
||||
|
||||
class Schema
|
||||
{
|
||||
public array $allExtensions = [];
|
||||
|
||||
public array $nodes = [];
|
||||
public array $marks = [];
|
||||
public array $extensions = [];
|
||||
|
||||
public $defaultNode;
|
||||
public $topNode;
|
||||
|
||||
public array $globalAttributes = [];
|
||||
|
||||
public function __construct(array $extensions = [])
|
||||
{
|
||||
$this->allExtensions = $this->loadExtensions($extensions);
|
||||
usort($this->allExtensions, fn ($a, $b) => $b::$priority - $a::$priority);
|
||||
|
||||
$this->nodes = array_filter($this->allExtensions, function ($extension) {
|
||||
return is_subclass_of($extension, \Tiptap\Core\Node::class);
|
||||
});
|
||||
|
||||
$this->marks = array_filter($this->allExtensions, function ($extension) {
|
||||
return is_subclass_of($extension, \Tiptap\Core\Mark::class);
|
||||
});
|
||||
|
||||
$this->extensions = array_filter($this->allExtensions, function ($extension) {
|
||||
return is_subclass_of($extension, \Tiptap\Core\Extension::class);
|
||||
});
|
||||
|
||||
$this->defaultNode = reset($this->nodes);
|
||||
$this->topNode = current(array_filter($this->nodes, fn ($node) => $node::$topNode));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function loadExtensions($extensions = [])
|
||||
{
|
||||
foreach ($extensions as $extension) {
|
||||
if (method_exists($extension, 'addExtensions') && count($extension->addExtensions())) {
|
||||
$extensions = array_merge(
|
||||
$extensions,
|
||||
$this->loadExtensions($extension->addExtensions()),
|
||||
);
|
||||
}
|
||||
|
||||
if (method_exists($extension, 'addGlobalAttributes')) {
|
||||
$globalAttributes = $extension->addGlobalAttributes();
|
||||
|
||||
foreach ($globalAttributes as $globalAttributeConfiguration) {
|
||||
foreach ($globalAttributeConfiguration['types'] ?? [] as $type) {
|
||||
$this->globalAttributes[$type] = array_merge(
|
||||
$this->globalAttributes[$type] ?? [],
|
||||
$globalAttributeConfiguration['attributes']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $extensions;
|
||||
}
|
||||
|
||||
public function apply($document)
|
||||
{
|
||||
if (! is_array($document['content'])) {
|
||||
return $document;
|
||||
}
|
||||
|
||||
$document['content'] = array_map(function ($node) {
|
||||
foreach ($this->allExtensions as $extension) {
|
||||
if (! isset($node['type']) || $node['type'] !== $extension::$name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (property_exists($extension, 'marks')) {
|
||||
if ($extension::$marks === '') {
|
||||
$node = $this->filterMarks($node);
|
||||
|
||||
unset($node['marks']);
|
||||
}
|
||||
|
||||
// TODO: Support for multiple marks is missing
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return $node;
|
||||
}, $document['content']);
|
||||
|
||||
return $document;
|
||||
}
|
||||
|
||||
public function filterMarks(&$node)
|
||||
{
|
||||
unset($node['marks']);
|
||||
|
||||
if (isset($node['content'])) {
|
||||
$node['content'] = array_map(function ($child) {
|
||||
return $this->filterMarks($child);
|
||||
}, $node['content']);
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
public function getAttributeConfigurations($class): array
|
||||
{
|
||||
return array_merge(
|
||||
$this->globalAttributes[$class::$name] ?? [],
|
||||
$class->addAttributes(),
|
||||
);
|
||||
}
|
||||
}
|
||||
51
vendor/ueberdosis/tiptap-php/src/Core/TextSerializer.php
vendored
Normal file
51
vendor/ueberdosis/tiptap-php/src/Core/TextSerializer.php
vendored
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Core;
|
||||
|
||||
class TextSerializer
|
||||
{
|
||||
protected $document;
|
||||
|
||||
protected $schema;
|
||||
|
||||
protected $configuration = [
|
||||
'blockSeparator' => "\n\n",
|
||||
];
|
||||
|
||||
public function __construct($schema, $configuration = [])
|
||||
{
|
||||
$this->schema = $schema;
|
||||
$this->configuration = array_merge($this->configuration, $configuration);
|
||||
}
|
||||
|
||||
public function process(array $value): string
|
||||
{
|
||||
$html = [];
|
||||
|
||||
// transform document to object
|
||||
$this->document = json_decode(json_encode($value));
|
||||
|
||||
$content = is_array($this->document->content) ? $this->document->content : [];
|
||||
|
||||
foreach ($content as $node) {
|
||||
$html[] = $this->renderNode($node);
|
||||
}
|
||||
|
||||
return join($this->configuration['blockSeparator'], $html);
|
||||
}
|
||||
|
||||
private function renderNode($node): string
|
||||
{
|
||||
$text = [];
|
||||
|
||||
if (isset($node->content)) {
|
||||
foreach ($node->content as $nestedNode) {
|
||||
$text[] = $this->renderNode($nestedNode);
|
||||
}
|
||||
} elseif (isset($node->text)) {
|
||||
$text[] = htmlspecialchars($node->text, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
return join($this->configuration['blockSeparator'], $text);
|
||||
}
|
||||
}
|
||||
150
vendor/ueberdosis/tiptap-php/src/Editor.php
vendored
Normal file
150
vendor/ueberdosis/tiptap-php/src/Editor.php
vendored
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap;
|
||||
|
||||
use Exception;
|
||||
use Tiptap\Core\DOMParser;
|
||||
use Tiptap\Core\DOMSerializer;
|
||||
use Tiptap\Core\JSONSerializer;
|
||||
use Tiptap\Core\Schema;
|
||||
use Tiptap\Core\TextSerializer;
|
||||
use Tiptap\Extensions\StarterKit;
|
||||
|
||||
class Editor
|
||||
{
|
||||
protected $document;
|
||||
|
||||
public $schema;
|
||||
|
||||
public $configuration = [
|
||||
'content' => null,
|
||||
'extensions' => [],
|
||||
];
|
||||
|
||||
public function __construct(array $configuration = [])
|
||||
{
|
||||
if (! isset($configuration['extensions'])) {
|
||||
$configuration['extensions'] = [
|
||||
new StarterKit,
|
||||
];
|
||||
}
|
||||
|
||||
$this->configuration = array_merge_recursive($this->configuration, $configuration);
|
||||
$this->schema = new Schema($this->configuration['extensions']);
|
||||
|
||||
if (isset($configuration['content'])) {
|
||||
$this->setContent($configuration['content']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public function setContent($value): self
|
||||
{
|
||||
if ($this->getContentType($value) === 'HTML') {
|
||||
$this->document = (new DOMParser($this->schema))->process($value);
|
||||
} elseif ($this->getContentType($value) === 'Array') {
|
||||
$this->document = json_decode(json_encode($value), true);
|
||||
} elseif ($this->getContentType($value) === 'JSON') {
|
||||
$this->document = json_decode($value, true);
|
||||
}
|
||||
|
||||
$this->document = $this->schema->apply($this->document);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDocument()
|
||||
{
|
||||
return $this->document;
|
||||
}
|
||||
|
||||
public function getJSON(): string
|
||||
{
|
||||
return (new JSONSerializer)->process($this->document);
|
||||
}
|
||||
|
||||
public function getHTML(): string
|
||||
{
|
||||
return (new DOMSerializer($this->schema))->process($this->document);
|
||||
}
|
||||
|
||||
public function getText($configuration = []): string
|
||||
{
|
||||
return (new TextSerializer($this->schema, $configuration))->process($this->document);
|
||||
}
|
||||
|
||||
public function sanitize($value)
|
||||
{
|
||||
if ($this->getContentType($value) === 'HTML') {
|
||||
return $this->setContent($value)->getHTML();
|
||||
} elseif ($this->getContentType($value) === 'Array') {
|
||||
return $this->setContent($value)->getDocument();
|
||||
} elseif ($this->getContentType($value) === 'JSON') {
|
||||
return $this->setContent($value)->getJSON();
|
||||
}
|
||||
}
|
||||
|
||||
public function getContentType($value): string
|
||||
{
|
||||
if (is_string($value)) {
|
||||
try {
|
||||
/**
|
||||
* @psalm-suppress UnusedFunctionCall
|
||||
*/
|
||||
json_decode($value, true, 512, JSON_THROW_ON_ERROR);
|
||||
|
||||
return 'JSON';
|
||||
} catch (Exception $exception) {
|
||||
return 'HTML';
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
return 'Array';
|
||||
}
|
||||
|
||||
throw new Exception('Unknown format passed to setContent(). Try passing HTML, JSON or an Array.');
|
||||
}
|
||||
|
||||
public function descendants($closure): Editor
|
||||
{
|
||||
// Transform the document to an object
|
||||
$node = json_decode(json_encode($this->document));
|
||||
|
||||
$this->walkThroughNodes($node, $closure);
|
||||
|
||||
// Store the updated document.
|
||||
$this->setContent(json_decode(json_encode($node), true));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function walkThroughNodes(&$node, $closure)
|
||||
{
|
||||
// Skip, if it’s just text.
|
||||
if ($node->type === 'text') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Call the closure.
|
||||
$closure($node);
|
||||
|
||||
// Skip, if there are no children.
|
||||
if (! isset($node->content)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure content is an Array.
|
||||
$content = is_array($node->content) ? $node->content : [];
|
||||
|
||||
// Loop through all children.
|
||||
foreach ($content as $child) {
|
||||
$this->walkThroughNodes($child, $closure);
|
||||
}
|
||||
}
|
||||
}
|
||||
50
vendor/ueberdosis/tiptap-php/src/Extensions/Color.php
vendored
Normal file
50
vendor/ueberdosis/tiptap-php/src/Extensions/Color.php
vendored
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Extensions;
|
||||
|
||||
use Tiptap\Core\Extension;
|
||||
use Tiptap\Utils\InlineStyle;
|
||||
|
||||
class Color extends Extension
|
||||
{
|
||||
public static $name = 'color';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'types' => ['textStyle'],
|
||||
];
|
||||
}
|
||||
|
||||
public function addGlobalAttributes()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'types' => $this->options['types'],
|
||||
'attributes' => [
|
||||
'color' => [
|
||||
'default' => null,
|
||||
'parseHTML' => function ($DOMNode) {
|
||||
$attribute = InlineStyle::getAttribute($DOMNode, 'color');
|
||||
|
||||
if ($attribute === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return preg_replace('/[\'"]+/', '', $attribute);
|
||||
},
|
||||
'renderHTML' => function ($attributes) {
|
||||
$color = $attributes?->color ?? null;
|
||||
|
||||
if ($color === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ['style' => "color: {$color}"];
|
||||
},
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
50
vendor/ueberdosis/tiptap-php/src/Extensions/FontFamily.php
vendored
Normal file
50
vendor/ueberdosis/tiptap-php/src/Extensions/FontFamily.php
vendored
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Extensions;
|
||||
|
||||
use Tiptap\Core\Extension;
|
||||
use Tiptap\Utils\InlineStyle;
|
||||
|
||||
class FontFamily extends Extension
|
||||
{
|
||||
public static $name = 'fontFamily';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'types' => ['textStyle'],
|
||||
];
|
||||
}
|
||||
|
||||
public function addGlobalAttributes()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'types' => $this->options['types'],
|
||||
'attributes' => [
|
||||
'fontFamily' => [
|
||||
'default' => null,
|
||||
'parseHTML' => function ($DOMNode) {
|
||||
$attribute = InlineStyle::getAttribute($DOMNode, 'font-family');
|
||||
|
||||
if ($attribute === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $attribute;
|
||||
},
|
||||
'renderHTML' => function ($attributes) {
|
||||
$fontFamily = $attributes?->fontFamily ?? null;
|
||||
|
||||
if ($fontFamily === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ['style' => "font-family: {$fontFamily}"];
|
||||
},
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
82
vendor/ueberdosis/tiptap-php/src/Extensions/StarterKit.php
vendored
Normal file
82
vendor/ueberdosis/tiptap-php/src/Extensions/StarterKit.php
vendored
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Extensions;
|
||||
|
||||
use Tiptap\Core\Extension;
|
||||
|
||||
class StarterKit extends Extension
|
||||
{
|
||||
public static $name = 'starterKit';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'document' => [],
|
||||
'blockquote' => [],
|
||||
'bulletList' => [],
|
||||
'codeBlock' => [],
|
||||
'hardBreak' => [],
|
||||
'heading' => [],
|
||||
'horizontalRule' => [],
|
||||
'listItem' => [],
|
||||
'orderedList' => [],
|
||||
'paragraph' => [],
|
||||
'text' => [],
|
||||
'bold' => [],
|
||||
'code' => [],
|
||||
'italic' => [],
|
||||
'strike' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function addExtensions()
|
||||
{
|
||||
return array_filter([
|
||||
$this->options['document'] !== false
|
||||
? new \Tiptap\Nodes\Document($this->options['document'])
|
||||
: null,
|
||||
$this->options['blockquote'] !== false
|
||||
? new \Tiptap\Nodes\Blockquote($this->options['blockquote'])
|
||||
: null,
|
||||
$this->options['bulletList'] !== false
|
||||
? new \Tiptap\Nodes\BulletList($this->options['bulletList'])
|
||||
: null,
|
||||
$this->options['codeBlock'] !== false
|
||||
? new \Tiptap\Nodes\CodeBlock($this->options['codeBlock'])
|
||||
: null,
|
||||
$this->options['hardBreak'] !== false
|
||||
? new \Tiptap\Nodes\HardBreak($this->options['hardBreak'])
|
||||
: null,
|
||||
$this->options['heading'] !== false
|
||||
? new \Tiptap\Nodes\Heading($this->options['heading'])
|
||||
: null,
|
||||
$this->options['horizontalRule'] !== false
|
||||
? new \Tiptap\Nodes\HorizontalRule($this->options['horizontalRule'])
|
||||
: null,
|
||||
$this->options['listItem'] !== false
|
||||
? new \Tiptap\Nodes\ListItem($this->options['listItem'])
|
||||
: null,
|
||||
$this->options['orderedList'] !== false
|
||||
? new \Tiptap\Nodes\OrderedList($this->options['orderedList'])
|
||||
: null,
|
||||
$this->options['paragraph'] !== false
|
||||
? new \Tiptap\Nodes\Paragraph($this->options['paragraph'])
|
||||
: null,
|
||||
$this->options['text'] !== false
|
||||
? new \Tiptap\Nodes\Text($this->options['text'])
|
||||
: null,
|
||||
$this->options['bold'] !== false
|
||||
? new \Tiptap\Marks\Bold($this->options['bold'])
|
||||
: null,
|
||||
$this->options['code'] !== false
|
||||
? new \Tiptap\Marks\Code($this->options['code'])
|
||||
: null,
|
||||
$this->options['italic'] !== false
|
||||
? new \Tiptap\Marks\Italic($this->options['italic'])
|
||||
: null,
|
||||
$this->options['strike'] !== false
|
||||
? new \Tiptap\Marks\Strike($this->options['strike'])
|
||||
: null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
43
vendor/ueberdosis/tiptap-php/src/Extensions/TextAlign.php
vendored
Normal file
43
vendor/ueberdosis/tiptap-php/src/Extensions/TextAlign.php
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Extensions;
|
||||
|
||||
use Tiptap\Core\Extension;
|
||||
use Tiptap\Utils\InlineStyle;
|
||||
|
||||
class TextAlign extends Extension
|
||||
{
|
||||
public static $name = 'textAlign';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'types' => [],
|
||||
'alignments' => ['left', 'center', 'right', 'justify'],
|
||||
'defaultAlignment' => 'left',
|
||||
];
|
||||
}
|
||||
|
||||
public function addGlobalAttributes()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'types' => $this->options['types'],
|
||||
'attributes' => [
|
||||
'textAlign' => [
|
||||
'default' => $this->options['defaultAlignment'],
|
||||
'parseHTML' => fn ($DOMNode) =>
|
||||
InlineStyle::getAttribute($DOMNode, 'text-align') ?? $this->options['defaultAlignment'],
|
||||
'renderHTML' => function ($attributes) {
|
||||
if ($attributes->textAlign === $this->options['defaultAlignment']) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ['style' => "text-align: {$attributes->textAlign}"];
|
||||
},
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
51
vendor/ueberdosis/tiptap-php/src/Marks/Bold.php
vendored
Normal file
51
vendor/ueberdosis/tiptap-php/src/Marks/Bold.php
vendored
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Marks;
|
||||
|
||||
use Tiptap\Core\Mark;
|
||||
use Tiptap\Utils\HTML;
|
||||
use Tiptap\Utils\InlineStyle;
|
||||
|
||||
class Bold extends Mark
|
||||
{
|
||||
public static $name = 'bold';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'strong',
|
||||
],
|
||||
[
|
||||
'tag' => 'b',
|
||||
'getAttrs' => function ($DOMNode) {
|
||||
return ! InlineStyle::hasAttribute($DOMNode, [
|
||||
'font-weight' => 'normal',
|
||||
]) ? null : false;
|
||||
},
|
||||
],
|
||||
[
|
||||
'style' => 'font-weight',
|
||||
'getAttrs' => function ($value) {
|
||||
return (bool) preg_match('/^(bold(er)?|[5-9]\d{2,})$/', $value) ? null : false;
|
||||
},
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($mark, $HTMLAttributes = [])
|
||||
{
|
||||
return [
|
||||
'strong',
|
||||
HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes),
|
||||
0,
|
||||
];
|
||||
}
|
||||
}
|
||||
32
vendor/ueberdosis/tiptap-php/src/Marks/Code.php
vendored
Normal file
32
vendor/ueberdosis/tiptap-php/src/Marks/Code.php
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Marks;
|
||||
|
||||
use Tiptap\Core\Mark;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class Code extends Mark
|
||||
{
|
||||
public static $name = 'code';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'code',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($mark, $HTMLAttributes = [])
|
||||
{
|
||||
return ['code', HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes), 0];
|
||||
}
|
||||
}
|
||||
67
vendor/ueberdosis/tiptap-php/src/Marks/Highlight.php
vendored
Normal file
67
vendor/ueberdosis/tiptap-php/src/Marks/Highlight.php
vendored
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Marks;
|
||||
|
||||
use Tiptap\Core\Mark;
|
||||
use Tiptap\Utils\HTML;
|
||||
use Tiptap\Utils\InlineStyle;
|
||||
|
||||
class Highlight extends Mark
|
||||
{
|
||||
public static $name = 'highlight';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'multicolor' => false,
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'mark',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function addAttributes()
|
||||
{
|
||||
if (! $this->options['multicolor']) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'color' => [
|
||||
'parseHTML' => function ($DOMNode) {
|
||||
if ($color = $DOMNode->getAttribute('data-color')) {
|
||||
return $color;
|
||||
}
|
||||
|
||||
return InlineStyle::getAttribute($DOMNode, 'background-color') ?: null;
|
||||
},
|
||||
'renderHTML' => function ($attributes) {
|
||||
if (! $attributes->color) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'data-color' => $attributes->color,
|
||||
'style' => "background-color: {$attributes->color}",
|
||||
];
|
||||
},
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($mark, $HTMLAttributes = [])
|
||||
{
|
||||
return [
|
||||
'mark',
|
||||
HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes),
|
||||
0,
|
||||
];
|
||||
}
|
||||
}
|
||||
44
vendor/ueberdosis/tiptap-php/src/Marks/Italic.php
vendored
Normal file
44
vendor/ueberdosis/tiptap-php/src/Marks/Italic.php
vendored
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Marks;
|
||||
|
||||
use Tiptap\Core\Mark;
|
||||
use Tiptap\Utils\HTML;
|
||||
use Tiptap\Utils\InlineStyle;
|
||||
|
||||
class Italic extends Mark
|
||||
{
|
||||
public static $name = 'italic';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'em',
|
||||
],
|
||||
[
|
||||
'tag' => 'i',
|
||||
'getAttrs' => function ($DOMNode) {
|
||||
return ! InlineStyle::hasAttribute($DOMNode, [
|
||||
'font-style' => 'normal',
|
||||
]) ? null : false;
|
||||
},
|
||||
],
|
||||
[
|
||||
'style' => 'font-style=italic',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($mark, $HTMLAttributes = [])
|
||||
{
|
||||
return ['em', HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes), 0];
|
||||
}
|
||||
}
|
||||
103
vendor/ueberdosis/tiptap-php/src/Marks/Link.php
vendored
Normal file
103
vendor/ueberdosis/tiptap-php/src/Marks/Link.php
vendored
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Marks;
|
||||
|
||||
use Tiptap\Core\Mark;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class Link extends Mark
|
||||
{
|
||||
public static $name = 'link';
|
||||
|
||||
// Port of the DOMPurify helper used by Tiptap’s Link extension
|
||||
// https://github.com/ueberdosis/tiptap/blob/next/packages/extension-link/src/link.ts#L161
|
||||
const ATTR_WHITESPACE = '/[\x00-\x20\x{00A0}\x{1680}\x{180E}\x{2000}-\x{2029}\x{205F}\x{3000}]/u';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [
|
||||
'target' => '_blank',
|
||||
'rel' => 'noopener noreferrer nofollow',
|
||||
],
|
||||
'allowedProtocols' => [
|
||||
'http', 'https', 'ftp', 'ftps', 'mailto', 'tel', 'callto', 'sms', 'cid', 'xmpp',
|
||||
],
|
||||
'isAllowedUri' => fn ($uri) => $this->isAllowedUri($uri),
|
||||
];
|
||||
}
|
||||
|
||||
public function isAllowedUri($uri)
|
||||
{
|
||||
if ($uri === null || $uri === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (! is_string($uri)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$sanitised = preg_replace(self::ATTR_WHITESPACE, '', $uri);
|
||||
|
||||
$pattern = '/^(?:(?:' . implode('|', array_map('preg_quote', $this->options['allowedProtocols']))
|
||||
. '):|[^a-z]|[a-z0-9+.\-]+(?:[^a-z+.\-:]|$))/i';
|
||||
|
||||
return (bool) preg_match($pattern, $sanitised);
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'a[href]',
|
||||
'getAttrs' => function ($DOMNode) {
|
||||
$href = $DOMNode->getAttribute('href');
|
||||
|
||||
if (
|
||||
$href === '' ||
|
||||
! $this->options['isAllowedUri']($href)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function addAttributes()
|
||||
{
|
||||
return [
|
||||
'href' => [],
|
||||
'target' => [],
|
||||
'rel' => [],
|
||||
'class' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($mark, $HTMLAttributes = [])
|
||||
{
|
||||
$isAllowed = $this->options['isAllowedUri']($HTMLAttributes['href'] ?? '');
|
||||
|
||||
if (! $isAllowed) {
|
||||
$HTMLAttributes['href'] = '';
|
||||
}
|
||||
|
||||
$attributes = HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes);
|
||||
|
||||
if (isset($mark->attrs)) {
|
||||
foreach ((array) $mark->attrs as $key => $value) {
|
||||
if ($value === null) {
|
||||
unset($attributes[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'a',
|
||||
$attributes,
|
||||
0,
|
||||
];
|
||||
}
|
||||
}
|
||||
41
vendor/ueberdosis/tiptap-php/src/Marks/Strike.php
vendored
Normal file
41
vendor/ueberdosis/tiptap-php/src/Marks/Strike.php
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Marks;
|
||||
|
||||
use Tiptap\Core\Mark;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class Strike extends Mark
|
||||
{
|
||||
public static $name = 'strike';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 's',
|
||||
],
|
||||
[
|
||||
'tag' => 'del',
|
||||
],
|
||||
[
|
||||
'tag' => 'strike',
|
||||
],
|
||||
[
|
||||
'style' => 'text-decoration=line-through',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($mark, $HTMLAttributes = [])
|
||||
{
|
||||
return ['s', HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes), 0];
|
||||
}
|
||||
}
|
||||
35
vendor/ueberdosis/tiptap-php/src/Marks/Subscript.php
vendored
Normal file
35
vendor/ueberdosis/tiptap-php/src/Marks/Subscript.php
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Marks;
|
||||
|
||||
use Tiptap\Core\Mark;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class Subscript extends Mark
|
||||
{
|
||||
public static $name = 'subscript';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'sub',
|
||||
],
|
||||
[
|
||||
'style' => 'vertical-align=sub',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($mark, $HTMLAttributes = [])
|
||||
{
|
||||
return ['sub', HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes), 0];
|
||||
}
|
||||
}
|
||||
35
vendor/ueberdosis/tiptap-php/src/Marks/Superscript.php
vendored
Normal file
35
vendor/ueberdosis/tiptap-php/src/Marks/Superscript.php
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Marks;
|
||||
|
||||
use Tiptap\Core\Mark;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class Superscript extends Mark
|
||||
{
|
||||
public static $name = 'superscript';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'sup',
|
||||
],
|
||||
[
|
||||
'style' => 'vertical-align=super',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($mark, $HTMLAttributes = [])
|
||||
{
|
||||
return ['sup', HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes), 0];
|
||||
}
|
||||
}
|
||||
35
vendor/ueberdosis/tiptap-php/src/Marks/TextStyle.php
vendored
Normal file
35
vendor/ueberdosis/tiptap-php/src/Marks/TextStyle.php
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Marks;
|
||||
|
||||
use Tiptap\Core\Mark;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class TextStyle extends Mark
|
||||
{
|
||||
public static $name = 'textStyle';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'span',
|
||||
'getAttrs' => function ($DOMNode) {
|
||||
return $DOMNode->hasAttribute('style') ? null : false;
|
||||
},
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($mark, $HTMLAttributes = [])
|
||||
{
|
||||
return ['span', HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes), 0];
|
||||
}
|
||||
}
|
||||
35
vendor/ueberdosis/tiptap-php/src/Marks/Underline.php
vendored
Normal file
35
vendor/ueberdosis/tiptap-php/src/Marks/Underline.php
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Marks;
|
||||
|
||||
use Tiptap\Core\Mark;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class Underline extends Mark
|
||||
{
|
||||
public static $name = 'underline';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'u',
|
||||
],
|
||||
[
|
||||
'style' => 'text-decoration=underline',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($mark, $HTMLAttributes = [])
|
||||
{
|
||||
return ['u', HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes), 0];
|
||||
}
|
||||
}
|
||||
32
vendor/ueberdosis/tiptap-php/src/Nodes/Blockquote.php
vendored
Normal file
32
vendor/ueberdosis/tiptap-php/src/Nodes/Blockquote.php
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Core\Node;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class Blockquote extends Node
|
||||
{
|
||||
public static $name = 'blockquote';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'blockquote',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = [])
|
||||
{
|
||||
return ['blockquote', HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes), 0];
|
||||
}
|
||||
}
|
||||
32
vendor/ueberdosis/tiptap-php/src/Nodes/BulletList.php
vendored
Normal file
32
vendor/ueberdosis/tiptap-php/src/Nodes/BulletList.php
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Core\Node;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class BulletList extends Node
|
||||
{
|
||||
public static $name = 'bulletList';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'ul',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = [])
|
||||
{
|
||||
return ['ul', HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes), 0];
|
||||
}
|
||||
}
|
||||
67
vendor/ueberdosis/tiptap-php/src/Nodes/CodeBlock.php
vendored
Normal file
67
vendor/ueberdosis/tiptap-php/src/Nodes/CodeBlock.php
vendored
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Core\Node;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class CodeBlock extends Node
|
||||
{
|
||||
public static $name = 'codeBlock';
|
||||
|
||||
public static $marks = '';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'languageClassPrefix' => 'language-',
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'pre',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function addAttributes()
|
||||
{
|
||||
return [
|
||||
'language' => [
|
||||
'parseHTML' => function ($DOMNode) {
|
||||
if (! ($DOMNode->childNodes[0] instanceof \DOMElement)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return preg_replace(
|
||||
"/^" . $this->options['languageClassPrefix']. "/",
|
||||
"",
|
||||
$DOMNode->childNodes[0]->getAttribute('class')
|
||||
) ?: null;
|
||||
},
|
||||
'rendered' => false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = [])
|
||||
{
|
||||
return [
|
||||
'pre',
|
||||
HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes),
|
||||
[
|
||||
'code',
|
||||
[
|
||||
'class' => $node->attrs->language ?? null
|
||||
? $this->options['languageClassPrefix'] . $node->attrs->language
|
||||
: null,
|
||||
],
|
||||
0,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
62
vendor/ueberdosis/tiptap-php/src/Nodes/CodeBlockHighlight.php
vendored
Normal file
62
vendor/ueberdosis/tiptap-php/src/Nodes/CodeBlockHighlight.php
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use DomainException;
|
||||
use Highlight\Highlighter;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class CodeBlockHighlight extends CodeBlock
|
||||
{
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'languageClassPrefix' => 'hljs ',
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = [])
|
||||
{
|
||||
$code = $node->content[0]->text ?? '';
|
||||
|
||||
try {
|
||||
$highlighter = new Highlighter();
|
||||
|
||||
if ($node->attrs->language ?? null) {
|
||||
$result = $highlighter->highlight($node->attrs->language, $code);
|
||||
} else {
|
||||
$result = $highlighter->highlightAuto($code);
|
||||
}
|
||||
|
||||
$mergedAttributes = HTML::mergeAttributes(
|
||||
[
|
||||
'class' => $this->options['languageClassPrefix'] . $result->language,
|
||||
],
|
||||
$this->options['HTMLAttributes'],
|
||||
$HTMLAttributes,
|
||||
);
|
||||
|
||||
$renderedAttributes = HTML::renderAttributes($mergedAttributes);
|
||||
|
||||
$content = "<pre><code" . $renderedAttributes . ">";
|
||||
$content .= $result->value;
|
||||
$content .= "</code></pre>";
|
||||
} catch (DomainException $exception) {
|
||||
$mergedAttributes = HTML::mergeAttributes(
|
||||
$this->options['HTMLAttributes'],
|
||||
$HTMLAttributes,
|
||||
);
|
||||
|
||||
$renderedAttributes = HTML::renderAttributes($mergedAttributes);
|
||||
|
||||
$content = "<pre><code" . $renderedAttributes . ">";
|
||||
$content .= htmlentities($code);
|
||||
$content .= "</code></pre>";
|
||||
}
|
||||
|
||||
return [
|
||||
'content' => $content,
|
||||
];
|
||||
}
|
||||
}
|
||||
67
vendor/ueberdosis/tiptap-php/src/Nodes/CodeBlockShiki.php
vendored
Normal file
67
vendor/ueberdosis/tiptap-php/src/Nodes/CodeBlockShiki.php
vendored
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use DomainException;
|
||||
use Exception;
|
||||
use Highlight\Highlighter;
|
||||
use Spatie\ShikiPhp\Shiki;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class CodeBlockShiki extends CodeBlock
|
||||
{
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'languageClassPrefix' => 'language-',
|
||||
'HTMLAttributes' => [],
|
||||
'defaultLanguage' => 'html',
|
||||
'theme' => 'nord',
|
||||
'guessLanguage' => true,
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = [])
|
||||
{
|
||||
$code = $node->content[0]->text ?? '';
|
||||
|
||||
// Language is set
|
||||
if ($node->attrs->language === null) {
|
||||
$language = $node->attrs->language;
|
||||
}
|
||||
// Auto-detect the language
|
||||
elseif ($this->options['guessLanguage']) {
|
||||
try {
|
||||
$highlighter = new Highlighter();
|
||||
$result = $highlighter->highlightAuto($code);
|
||||
$language = $result->language;
|
||||
} catch (Exception $exception) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
// Use the default language
|
||||
if (! isset($language)) {
|
||||
$language = $this->options['defaultLanguage'];
|
||||
}
|
||||
|
||||
try {
|
||||
$content = Shiki::highlight($code, $language, 'nord');
|
||||
} catch (DomainException $exception) {
|
||||
$mergedAttributes = HTML::mergeAttributes(
|
||||
$this->options['HTMLAttributes'],
|
||||
$HTMLAttributes,
|
||||
);
|
||||
|
||||
$renderedAttributes = HTML::renderAttributes($mergedAttributes);
|
||||
|
||||
$content = "<pre><code" . $renderedAttributes . ">";
|
||||
$content .= htmlentities($code);
|
||||
$content .= "</code></pre>";
|
||||
}
|
||||
|
||||
return [
|
||||
'content' => $content,
|
||||
];
|
||||
}
|
||||
}
|
||||
53
vendor/ueberdosis/tiptap-php/src/Nodes/Details.php
vendored
Normal file
53
vendor/ueberdosis/tiptap-php/src/Nodes/Details.php
vendored
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Core\Node;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class Details extends Node
|
||||
{
|
||||
public static $name = 'details';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'persist' => false,
|
||||
'openClassName' => 'is-open',
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'details',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function addAttributes()
|
||||
{
|
||||
if (! $this->options['persist']) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'open' => [
|
||||
'default' => false,
|
||||
'parseHTML' => fn ($DOMNode) => $DOMNode->hasAttribute('open'),
|
||||
'renderHTML' => fn ($attributes) => $attributes->open ? ['open' => 'open'] : [],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = [])
|
||||
{
|
||||
return [
|
||||
'details',
|
||||
HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes),
|
||||
0,
|
||||
];
|
||||
}
|
||||
}
|
||||
37
vendor/ueberdosis/tiptap-php/src/Nodes/DetailsContent.php
vendored
Normal file
37
vendor/ueberdosis/tiptap-php/src/Nodes/DetailsContent.php
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Core\Node;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class DetailsContent extends Node
|
||||
{
|
||||
public static $name = 'detailsContent';
|
||||
|
||||
public function addOptions(): array
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'div[data-type]',
|
||||
'getAttrs' => fn ($value): bool => (bool) $value == 'detailsContent',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = []): array
|
||||
{
|
||||
return [
|
||||
'div',
|
||||
HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes, ['data-type' => 'detailsContent']),
|
||||
0,
|
||||
];
|
||||
}
|
||||
}
|
||||
36
vendor/ueberdosis/tiptap-php/src/Nodes/DetailsSummary.php
vendored
Normal file
36
vendor/ueberdosis/tiptap-php/src/Nodes/DetailsSummary.php
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Core\Node;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class DetailsSummary extends Node
|
||||
{
|
||||
public static $name = 'detailsSummary';
|
||||
|
||||
public function addOptions(): array
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'summary',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = []): array
|
||||
{
|
||||
return [
|
||||
'summary',
|
||||
HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes),
|
||||
0,
|
||||
];
|
||||
}
|
||||
}
|
||||
12
vendor/ueberdosis/tiptap-php/src/Nodes/Document.php
vendored
Normal file
12
vendor/ueberdosis/tiptap-php/src/Nodes/Document.php
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Core\Node;
|
||||
|
||||
class Document extends Node
|
||||
{
|
||||
public static $name = 'doc';
|
||||
|
||||
public static $topNode = true;
|
||||
}
|
||||
32
vendor/ueberdosis/tiptap-php/src/Nodes/HardBreak.php
vendored
Normal file
32
vendor/ueberdosis/tiptap-php/src/Nodes/HardBreak.php
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Core\Node;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class HardBreak extends Node
|
||||
{
|
||||
public static $name = 'hardBreak';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'br',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = [])
|
||||
{
|
||||
return ['br', HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes)];
|
||||
}
|
||||
}
|
||||
46
vendor/ueberdosis/tiptap-php/src/Nodes/Heading.php
vendored
Normal file
46
vendor/ueberdosis/tiptap-php/src/Nodes/Heading.php
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Core\Node;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class Heading extends Node
|
||||
{
|
||||
public static $name = 'heading';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'levels' => [1, 2, 3, 4, 5, 6],
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return array_map(function ($level) {
|
||||
return [
|
||||
'tag' => "h{$level}",
|
||||
'attrs' => [
|
||||
'level' => $level,
|
||||
],
|
||||
];
|
||||
}, $this->options['levels']);
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = [])
|
||||
{
|
||||
$hasLevel = in_array($node->attrs->level, $this->options['levels']);
|
||||
|
||||
$level = $hasLevel ?
|
||||
$node->attrs->level :
|
||||
$this->options['levels'][0];
|
||||
|
||||
return [
|
||||
"h{$level}",
|
||||
HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes),
|
||||
0,
|
||||
];
|
||||
}
|
||||
}
|
||||
32
vendor/ueberdosis/tiptap-php/src/Nodes/HorizontalRule.php
vendored
Normal file
32
vendor/ueberdosis/tiptap-php/src/Nodes/HorizontalRule.php
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Core\Node;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class HorizontalRule extends Node
|
||||
{
|
||||
public static $name = 'horizontalRule';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'hr',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = [])
|
||||
{
|
||||
return ['hr', HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes)];
|
||||
}
|
||||
}
|
||||
43
vendor/ueberdosis/tiptap-php/src/Nodes/Image.php
vendored
Normal file
43
vendor/ueberdosis/tiptap-php/src/Nodes/Image.php
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Core\Node;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class Image extends Node
|
||||
{
|
||||
public static $name = 'image';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'img[src]',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function addAttributes()
|
||||
{
|
||||
return [
|
||||
'src' => [],
|
||||
'alt' => [],
|
||||
'title' => [],
|
||||
'width' => [],
|
||||
'height' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = [])
|
||||
{
|
||||
return ['img', HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes), 0];
|
||||
}
|
||||
}
|
||||
32
vendor/ueberdosis/tiptap-php/src/Nodes/ListItem.php
vendored
Normal file
32
vendor/ueberdosis/tiptap-php/src/Nodes/ListItem.php
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Core\Node;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class ListItem extends Node
|
||||
{
|
||||
public static $name = 'listItem';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'li',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = [])
|
||||
{
|
||||
return ['li', HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes), 0];
|
||||
}
|
||||
}
|
||||
56
vendor/ueberdosis/tiptap-php/src/Nodes/Mention.php
vendored
Normal file
56
vendor/ueberdosis/tiptap-php/src/Nodes/Mention.php
vendored
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Core\Node;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class Mention extends Node
|
||||
{
|
||||
public static $name = 'mention';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
'renderLabel' => fn () => null,
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'span[data-type="' . self::$name . '"]',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function addAttributes()
|
||||
{
|
||||
return [
|
||||
'id' => [
|
||||
'parseHTML' => fn ($DOMNode) => $DOMNode->getAttribute('data-id') ?: null,
|
||||
'renderHTML' => fn ($attributes) => ['data-id' => $attributes->id ?? null],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderText($node)
|
||||
{
|
||||
return $this->options['renderLabel']($node);
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = [])
|
||||
{
|
||||
return [
|
||||
'span',
|
||||
HTML::mergeAttributes(
|
||||
['data-type' => self::$name],
|
||||
$this->options['HTMLAttributes'],
|
||||
$HTMLAttributes,
|
||||
),
|
||||
0,
|
||||
];
|
||||
}
|
||||
}
|
||||
42
vendor/ueberdosis/tiptap-php/src/Nodes/OrderedList.php
vendored
Normal file
42
vendor/ueberdosis/tiptap-php/src/Nodes/OrderedList.php
vendored
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Core\Node;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class OrderedList extends Node
|
||||
{
|
||||
public static $name = 'orderedList';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'ol',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function addAttributes()
|
||||
{
|
||||
return [
|
||||
'start' => [
|
||||
'parseHTML' => fn ($DOMNode) => (int) $DOMNode->getAttribute('start') ?: null,
|
||||
'renderHTML' => fn ($attributes) => ($attributes->start ?? null) ? ['start' => $attributes->start] : null,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = [])
|
||||
{
|
||||
return ['ol', HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes), 0];
|
||||
}
|
||||
}
|
||||
34
vendor/ueberdosis/tiptap-php/src/Nodes/Paragraph.php
vendored
Normal file
34
vendor/ueberdosis/tiptap-php/src/Nodes/Paragraph.php
vendored
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Core\Node;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class Paragraph extends Node
|
||||
{
|
||||
public static $name = 'paragraph';
|
||||
|
||||
public static $priority = 1000;
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'p',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = [])
|
||||
{
|
||||
return ['p', HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes), 0];
|
||||
}
|
||||
}
|
||||
36
vendor/ueberdosis/tiptap-php/src/Nodes/Table.php
vendored
Normal file
36
vendor/ueberdosis/tiptap-php/src/Nodes/Table.php
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Core\Node;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class Table extends Node
|
||||
{
|
||||
public static $name = 'table';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'table',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = [])
|
||||
{
|
||||
return [
|
||||
'table',
|
||||
HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes),
|
||||
['tbody', 0],
|
||||
];
|
||||
}
|
||||
}
|
||||
75
vendor/ueberdosis/tiptap-php/src/Nodes/TableCell.php
vendored
Normal file
75
vendor/ueberdosis/tiptap-php/src/Nodes/TableCell.php
vendored
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Core\Node;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class TableCell extends Node
|
||||
{
|
||||
public static $name = 'tableCell';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'td',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function addAttributes()
|
||||
{
|
||||
return [
|
||||
'rowspan' => [
|
||||
'parseHTML' => fn ($DOMNode) => intval($DOMNode->getAttribute('rowspan')) ?: null,
|
||||
],
|
||||
'colspan' => [
|
||||
'parseHTML' => fn ($DOMNode) => intval($DOMNode->getAttribute('colspan')) ?: null,
|
||||
],
|
||||
'colwidth' => [
|
||||
'parseHTML' => function ($DOMNode) {
|
||||
$colwidth = $DOMNode->getAttribute('data-colwidth');
|
||||
|
||||
if (! $colwidth) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$widths = array_map(function ($w) {
|
||||
return intval($w);
|
||||
}, explode(',', $colwidth));
|
||||
|
||||
return $widths;
|
||||
},
|
||||
'renderHTML' => function ($attributes) {
|
||||
if (! isset($attributes->colwidth)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'data-colwidth' => join(',', $attributes->colwidth),
|
||||
];
|
||||
},
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = [])
|
||||
{
|
||||
return [
|
||||
'td',
|
||||
HTML::mergeAttributes(
|
||||
$this->options['HTMLAttributes'],
|
||||
$HTMLAttributes,
|
||||
),
|
||||
0,
|
||||
];
|
||||
}
|
||||
}
|
||||
38
vendor/ueberdosis/tiptap-php/src/Nodes/TableHeader.php
vendored
Normal file
38
vendor/ueberdosis/tiptap-php/src/Nodes/TableHeader.php
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class TableHeader extends TableCell
|
||||
{
|
||||
public static $name = 'tableHeader';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'th',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = [])
|
||||
{
|
||||
return [
|
||||
'th',
|
||||
HTML::mergeAttributes(
|
||||
$this->options['HTMLAttributes'],
|
||||
$HTMLAttributes,
|
||||
),
|
||||
0,
|
||||
];
|
||||
}
|
||||
}
|
||||
32
vendor/ueberdosis/tiptap-php/src/Nodes/TableRow.php
vendored
Normal file
32
vendor/ueberdosis/tiptap-php/src/Nodes/TableRow.php
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Core\Node;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class TableRow extends Node
|
||||
{
|
||||
public static $name = 'tableRow';
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'tr',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = [])
|
||||
{
|
||||
return ['tr', HTML::mergeAttributes($this->options['HTMLAttributes'], $HTMLAttributes), 0];
|
||||
}
|
||||
}
|
||||
70
vendor/ueberdosis/tiptap-php/src/Nodes/TaskItem.php
vendored
Normal file
70
vendor/ueberdosis/tiptap-php/src/Nodes/TaskItem.php
vendored
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Core\Node;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class TaskItem extends Node
|
||||
{
|
||||
public static $name = 'taskItem';
|
||||
|
||||
public static $priority = 1000;
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function addAttributes()
|
||||
{
|
||||
return [
|
||||
'checked' => [
|
||||
'default' => false,
|
||||
'renderHTML' => fn ($attributes) => [
|
||||
'data-checked' => $attributes->checked ?? null,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'li[data-type="' . self::$name . '"]',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = [])
|
||||
{
|
||||
return [
|
||||
'li',
|
||||
HTML::mergeAttributes(
|
||||
$this->options['HTMLAttributes'],
|
||||
$HTMLAttributes,
|
||||
['data-type' => self::$name],
|
||||
),
|
||||
[
|
||||
'label',
|
||||
[
|
||||
'input',
|
||||
[
|
||||
'type' => 'checkbox',
|
||||
'checked' => $node->attrs->checked ?? null
|
||||
? 'checked'
|
||||
: null,
|
||||
],
|
||||
],
|
||||
['span'],
|
||||
],
|
||||
[
|
||||
'div',
|
||||
0,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
38
vendor/ueberdosis/tiptap-php/src/Nodes/TaskList.php
vendored
Normal file
38
vendor/ueberdosis/tiptap-php/src/Nodes/TaskList.php
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Core\Node;
|
||||
use Tiptap\Utils\HTML;
|
||||
|
||||
class TaskList extends Node
|
||||
{
|
||||
public static $name = 'taskList';
|
||||
|
||||
public static $priority = 1000;
|
||||
|
||||
public function addOptions()
|
||||
{
|
||||
return [
|
||||
'HTMLAttributes' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => 'ul[data-type="' . self::$name . '"]',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHTML($node, $HTMLAttributes = [])
|
||||
{
|
||||
return ['ul', HTML::mergeAttributes(
|
||||
$this->options['HTMLAttributes'],
|
||||
$HTMLAttributes,
|
||||
['data-type' => self::$name],
|
||||
), 0];
|
||||
}
|
||||
}
|
||||
19
vendor/ueberdosis/tiptap-php/src/Nodes/Text.php
vendored
Normal file
19
vendor/ueberdosis/tiptap-php/src/Nodes/Text.php
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Nodes;
|
||||
|
||||
use Tiptap\Core\Node;
|
||||
|
||||
class Text extends Node
|
||||
{
|
||||
public static $name = 'text';
|
||||
|
||||
public function parseHTML()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'tag' => '#text',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
90
vendor/ueberdosis/tiptap-php/src/Utils/HTML.php
vendored
Normal file
90
vendor/ueberdosis/tiptap-php/src/Utils/HTML.php
vendored
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Utils;
|
||||
|
||||
class HTML
|
||||
{
|
||||
/**
|
||||
* Merge an associative array of attributes,
|
||||
* and make sure to merge classes and inline styles.
|
||||
*/
|
||||
public static function mergeAttributes(...$args): array
|
||||
{
|
||||
$attributes = [];
|
||||
|
||||
foreach ($args as $moreAttributes) {
|
||||
if (! is_array($moreAttributes) && ! is_object($moreAttributes)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($moreAttributes as $key => $value) {
|
||||
// class="foo bar"
|
||||
if ($key === 'class') {
|
||||
if (! self::isStringable($value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$attributes['class'] = trim(($attributes['class'] ?? '') . ' ' . $value);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// style="color: red;"
|
||||
if ($key === 'style') {
|
||||
if (! self::isStringable($value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$style = rtrim($attributes['style'] ?? '', '; ') . '; ' . rtrim($value, ';') . '; ';
|
||||
$attributes['style'] = ltrim(trim($style), '; ');
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$attributes[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an associative array of attributes
|
||||
* as a HTML string.
|
||||
*/
|
||||
public static function renderAttributes(array $attrs): string
|
||||
{
|
||||
$attributes = [];
|
||||
|
||||
// class="custom"
|
||||
foreach ($attrs as $name => $value) {
|
||||
if (! self::isStringable($value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_bool($value)) {
|
||||
$value = $value ? 'true' : 'false';
|
||||
}
|
||||
|
||||
$value = (string) $value;
|
||||
|
||||
if ($value === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$escapedValue = htmlentities($value);
|
||||
|
||||
$attributes[] = " {$name}=\"{$escapedValue}\"";
|
||||
}
|
||||
|
||||
return join($attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a value can be rendered into an attribute. Excludes null.
|
||||
*/
|
||||
private static function isStringable($value): bool
|
||||
{
|
||||
return is_scalar($value) || $value instanceof \Stringable;
|
||||
}
|
||||
}
|
||||
57
vendor/ueberdosis/tiptap-php/src/Utils/InlineStyle.php
vendored
Normal file
57
vendor/ueberdosis/tiptap-php/src/Utils/InlineStyle.php
vendored
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Utils;
|
||||
|
||||
use Exception;
|
||||
|
||||
class InlineStyle
|
||||
{
|
||||
/**
|
||||
* @return string[]
|
||||
*
|
||||
* @psalm-return array<string, string>
|
||||
*/
|
||||
public static function get($DOMNode): array
|
||||
{
|
||||
$results = [];
|
||||
|
||||
if (! method_exists($DOMNode, 'getAttribute')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$style = $DOMNode->getAttribute('style');
|
||||
|
||||
preg_match_all(
|
||||
"/([\w-]+)\s*:\s*([^;]+)\s*;?/",
|
||||
$style,
|
||||
$matches,
|
||||
PREG_SET_ORDER
|
||||
);
|
||||
|
||||
foreach ($matches as $match) {
|
||||
$results[$match[1]] = $match[2];
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public static function hasAttribute($DOMNode, $value): bool
|
||||
{
|
||||
$styles = self::get($DOMNode);
|
||||
|
||||
if (is_string($value)) {
|
||||
return in_array($value, array_keys($styles));
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
return array_diff($value, $styles) == [];
|
||||
}
|
||||
|
||||
throw new Exception('Can’t compare inline styles to ' . json_encode($value));
|
||||
}
|
||||
|
||||
public static function getAttribute($DOMNode, $attribute): ?string
|
||||
{
|
||||
return self::get($DOMNode)[$attribute] ?? null;
|
||||
}
|
||||
}
|
||||
53
vendor/ueberdosis/tiptap-php/src/Utils/Minify.php
vendored
Normal file
53
vendor/ueberdosis/tiptap-php/src/Utils/Minify.php
vendored
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace Tiptap\Utils;
|
||||
|
||||
class Minify
|
||||
{
|
||||
protected $_replacementHash;
|
||||
protected $_placeholders = [];
|
||||
protected $_html;
|
||||
|
||||
public function process($html): string
|
||||
{
|
||||
$this->_html = str_replace("\r\n", "\n", trim($html));
|
||||
|
||||
$hash = isset($_SERVER['REQUEST_TIME']) ? (string) $_SERVER['REQUEST_TIME'] : (string) time();
|
||||
$this->_replacementHash = 'MINIFYHTML' . md5($hash);
|
||||
|
||||
// replace PREs with placeholders
|
||||
$this->_html = preg_replace_callback('/\\s*<pre(\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/iu', [$this, '_removePreCB'], $this->_html);
|
||||
|
||||
// trim each line.
|
||||
$this->_html = preg_replace('/^\\s+|\\s+$/mu', '', $this->_html);
|
||||
|
||||
// remove ws around block/undisplayed elements
|
||||
$this->_html = preg_replace('/\\s+(<\\/?(?:area|article|aside|base(?:font)?|blockquote|body'
|
||||
. '|canvas|caption|center|col(?:group)?|dd|dir|div|dl|dt|fieldset|figcaption|figure|footer|form'
|
||||
. '|frame(?:set)?|h[1-6]|head|header|hgroup|hr|html|legend|li|link|main|map|menu|meta|nav'
|
||||
. '|ol|opt(?:group|ion)|output|p|param|section|t(?:able|body|head|d|h||r|foot|itle)'
|
||||
. '|ul|video)\\b[^>]*>)/iu', '$1', $this->_html);
|
||||
|
||||
// fill placeholders
|
||||
$this->_html = str_replace(
|
||||
array_keys($this->_placeholders),
|
||||
array_values($this->_placeholders),
|
||||
$this->_html
|
||||
);
|
||||
|
||||
return $this->_html;
|
||||
}
|
||||
|
||||
protected function _removePreCB($m): string
|
||||
{
|
||||
return $this->_reservePlace("<pre{$m[1]}");
|
||||
}
|
||||
|
||||
protected function _reservePlace($content): string
|
||||
{
|
||||
$placeholder = '%' . $this->_replacementHash . count($this->_placeholders) . '%';
|
||||
$this->_placeholders[$placeholder] = $content;
|
||||
|
||||
return $placeholder;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue