sandstorm/lazydatasource

Neos 包,实现了一个用于 UI 的懒加载数据源;元素将按需懒加载。

安装量: 17,620

依赖者: 3

建议者: 0

安全: 0

星级: 9

关注者: 9

分支: 2

公开问题: 0

语言:JavaScript

类型:neos-package

2.0.1 2024-01-23 13:50 UTC

This package is auto-updated.

Last update: 2024-09-23 15:25:44 UTC


README

在 Neos 中的 检查器数据源 通常都是 急切的,这意味着 UI 向后端发送一个请求来加载所有选项,然后在客户端进行过滤。

此包实现了额外的检查器编辑器,其行为类似于具有数据源的标准 SelectBoxEditor,但 将过滤和搜索委托给服务器端

这对于具有大集合(100 多个元素)的数据源大大提高了 Neos UI 的性能。

入门

  1. 通过以下方式使用 composer 进行默认安装

    composer require sandstorm/lazydatasource
  2. 用于单选

    在你的 NodeTypes.yaml 中,通过使用 Sandstorm.LazyDataSource/Inspector/Editors/DataSourceSelectEditor 替换 Neos.Neos/Inspector/Editors/SelectBoxEditor 来激活自定义编辑器。**基于数据源的选型配置选项 都按常规应用。

    此外,我们还支持以下额外的 editorOptions

    • dataSourceMakeNodeIndependent:如果设置为 TRUE,则当前选定的节点不会发送到后端的数据源,这将在客户端增加缓存寿命(例如,系统可以重用其他节点中的元素)

    示例

    'Neos.Demo:Document.Page':
      properties:
        test:
          ui:
            inspector:
              group: 'document'
    
              ##### THIS IS THE RELEVANT CONFIG:
              editor: 'Sandstorm.LazyDataSource/Inspector/Editors/DataSourceSelectEditor'
              
              ##### all Select options (e.g. dataSourceAdditionalData) work as usual. 
              editorOptions:
                placeholder: Choose
                dataSourceIdentifier: lazy-editor-test
  3. 用于多选

    在你的 NodeTypes.yaml 中,通过使用 Sandstorm.LazyDataSource/Inspector/Editors/DataSourceSelectEditor 替换 Neos.Neos/Inspector/Editors/SelectBoxEditor 来激活自定义编辑器。**基于数据源的选型配置选项 都按常规应用。

    此外,我们还支持以下额外的 editorOptions

    • dataSourceMakeNodeIndependent:如果设置为 TRUE,则当前选定的节点不会发送到后端的数据源,这将在客户端增加缓存寿命(例如,系统可以重用其他节点中的元素)

    示例

    'Neos.Demo:Document.Page':
      properties:
        test2:
    
          ##### Do not forget to set the property type to array<string>
          type: array<string>
          ui:
            inspector:
              group: 'document'
    
              ##### THIS IS THE RELEVANT CONFIG:
              editor: 'Sandstorm.LazyDataSource/Inspector/Editors/DataSourceSelectEditor'
              
              ##### all Select options (e.g. dataSourceAdditionalData) work as usual. 
              editorOptions:
                allowEmpty: true
                multiple: true
                placeholder: Choose
                dataSourceIdentifier: lazy-editor-test

    别忘了将属性类型设置为 array<string>

  4. 在你的服务器上的 DataSource 实现中,使用 LazyDataSourceTrait 并实现两个方法 getDataForIdentifiers()searchData()。不要实现 getData()(因为这是由 trait 提供的)。

    • getDataForIdentifiers() 在初始调用期间被调用,此时客户端需要为某些标识符解析条目。
    • searchData() 在用户输入搜索词时被调用,并需要执行搜索。

    这两个方法的返回值都需要与正常数据源相同。

    示例

     use Neos\Neos\Service\DataSource\AbstractDataSource;
     use Neos\ContentRepository\Domain\Model\NodeInterface;
     
     class MyLazyDataSource extends AbstractDataSource
     {
     
         use LazyDataSourceTrait;
     
         static protected $identifier = 'lazy-editor-test';
     
         protected function getDataForIdentifiers(array $identifiers, NodeInterface $node = null, array $arguments = [])
         {
             $options = [];
             foreach ($identifiers as $id) {
                 $options[$id] = ['label' => 'My Label for ' . $id];
             }
             return $options;
         }
     
         protected function searchData(string $searchTerm, NodeInterface $node = null, array $arguments = [])
         {
             $options = [];
             $options['key'] = ['label' => 'My Label ' . $searchTerm];
             return $options;
         }
     }

开发

此项目与 yarn 兼容。Neos 开发者提供的构建过程配置性不高,只能通过 package.json 调整构建过程的目标目录。

nvm install

如果你还没有安装 yarn

brew install yarn

构建应用程序

./dev.sh setup
./dev.sh build

贡献

我们非常欢迎您通过合并请求、添加问题等方式进行贡献。