PHP implementation of the Slate Rich Text Editor data model
The PHP model implementation basically follows the Slate data model structure as close as possible.
composer require prezly/slate-php
Brought to you with ❤️ by Prezly.
Slate model implementation in PHP
License: MIT License
The PHP model implementation basically follows the Slate data model structure as close as possible.
composer require prezly/slate-php
Brought to you with ❤️ by Prezly.
As Slate v0.50 is a complete overhaul, we need to rework this library to make it work with the new Slate model.
See Slate Changelog for v0.50.0:
https://github.com/ianstormtaylor/slate/blob/master/Changelog.md#0500--november-27-2019
A complete overhaul. The Slate codebase has had a complete overhaul and many pieces of its core architecture have been reconsidered from the ground up. There are lots of changes. We recommend re-reading the Walkthroughs and Concepts documentation and the Examples to get a sense for everything that has changed. As well as the Migration writeup for what the major changes are.
Hey, just tried out your package - looks really nice, and does exactly what i need.
Would you mind publishing it to https://packagist.org/ for ease of installation via composer?
Migrating content from one version to another is always a painful task. Especially when there are structural changes.
It would be great if this library did provide version-aware Value serialization.
A good example is Slate v0.46
update that merges Leaf and Text nodes data into Text node.
Before v0.46
:
{
"object": "text",
"leaves": [
{
"object": "leaf",
"text": "Hello",
"marks": []
}
]
}
After v0.46
:
{
"object": "text",
"text": "Hello",
"marks": []
}
A discussion started in #16
I think the library will benefit a lot from adoption the immutable model approach. So there is no way to modify an existing model instance, only create a new one with updated fields.
For example, PSR-7 HttpMessageInterface is following this practice: https://www.php-fig.org/psr/psr-7/
withXxx
methods to the model to create a new instance with modified propertiesBefore:
$leaf = new Leaf('foo', [new Mark('type')]);
// Modify text
$leaf->setText(
str_replace($leaf->getText(), 'o', 'a')
);
// Modify children
$leaf->setMarks(
array_map(
$leaf->getMarks(),
function(Mark $mark): Mark {
// modify mark
// return modified mark
}
)
);
// $leaf is the instance, but mutated
After:
$leaf = new Leaf('foo', [new Mark('type')]);
// Modify text
$leaf = $leaf->withText(
str_replace($leaf->getText(), 'o', 'a')
);
// Modify children
$leaf = $leaf->withMarks(
array_map(
$leaf->getMarks(),
function(Mark $mark): Mark {
// modify mark
// return modified mark
}
)
);
// $leaf is a competely new instance of Leaf
A problem revealed by @spawnia in #16
See #16 (comment)
There is a method to get and add marks, but not set.
Leaf::setMarks()
methods.Leaf::setMarks()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.