oberon/quill-delta

组合quill编辑器历史操作数组的deltas。npm库quill-delta的移植版本

1.0.2 2018-09-05 15:28 UTC

This package is auto-updated.

Last update: 2024-09-22 10:24:51 UTC


README

这是npm库quill-delta的PHP移植版本。目前它仅移植了组合函数,用于将包括所有保留和删除在内的完整历史组合到一个只包含必要插入的最终版本。

安装

使用composer

composer require oberon/quill-delta

使用

use Oberon\Quill\Delta\Composer;
    
$fullOps = [
    [
        "ops" => [
            ["insert" => "hello"],
        ],
    ],
    [
        "ops" => [
            ["retain" => 5],
            ["insert" => " world"],
        ],
    ],
];

$quilComposer = new Composer();
echo $quilComposer->compose($fullOps);

// {"ops":[{"insert":"hello world"}]}

use Oberon\Quill\Delta\Delta;

$fullOps = [
    [
        "ops" => [
            ["insert" => "hello"],
        ],
    ],
    [
        "ops" => [
            ["retain" => 5],
            ["insert" => " world"],
        ],
    ],
];

$output = array_reduce($fullOps, function(Delta $delta, $ops){
    $comp = $delta->compose(new Delta($ops));
    return $comp;
}, new Delta());

echo $output;

// {"ops":[{"insert":"hello world"}]}

说明

* only supports the delta compose method, diff and other utilities are not supported