formatd/componentloader

为 Fusion 组件自动加载 JavaScript

安装: 909

依赖: 1

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

语言:TypeScript

类型:neos-package

v1.0.3 2024-04-11 14:33 UTC

This package is auto-updated.

Last update: 2024-09-11 15:24:06 UTC


README

为融合组件加载 JavaScript 的简单方法

兼容性

版本控制方案

 1.0.0 
 | | |
 | | Bugfix Releases (non breaking)
 | Neos Compatibility Releases (non breaking)
 Feature Releases (breaking)

版本和兼容性

使用方法

FormatD.ComponentLoader:WindowComponentRegistry 会自动放置在 Neos.Neos:Page 的头部。

@packages 创建一个 typescript-include-alias,它指向 composer 包夹。

在你的组件中使用原型

prototype(Vendor.Website:MyComponent) < prototype(FormatD.ComponentLoader:Component) {
     ...
}

创建一个组件管理器

import { AbstractComponentManager } from "@packages/Application/FormatD.ComponentLoader/Resources/Private/TypeScript/AbstractComponentManager"

export default class MyComponentManager extends AbstractComponentManager {
	initialize(domSection: HTMLElement) {
		console.log("Hello World")
	}
}

包含相应的文件

import {componentLoader} from "@packages/Application/FormatD.ComponentLoader/Resources/Private/TypeScript/ComponentLoader";

componentLoader.addDefaultImport('Vendor.Website:MyComponent', () => import('../private/Fusion/MyComponent'));
//...
componentLoader.initialize()

可选的回调可以用来自初始化由组件管理器不管理的自定义 JavaScript

componentLoader.initialize(async (domSection, reason) => {
	if (domSection.querySelector('myElement')) {
		// add stuff here
	}
});