@aglyn/aglyn
v1.0.0-beta.180
Published
The core of Aglyn: the platform's data model (hosts, screens, layouts, node trees), the runtime managers that hold components, plugins and the canvas, and the framework-independent utilities the rest of the `@aglyn` packages are built on. Install it if yo
Readme
@aglyn/aglyn
The core of Aglyn: the platform's data model (hosts, screens, layouts, node
trees), the runtime managers that hold components, plugins and the canvas, and
the framework-independent utilities the rest of the @aglyn packages are built
on. Install it if you are building on Aglyn's model: a renderer, an editor, a
plugin, or a tool that reads and writes Aglyn documents.
Beta. Published from the Aglyn monorepo under the
betadist-tag; APIs can change between beta releases.
Install
npm install @aglyn/aglyn@betaPeer dependencies:
reactis required.next,firebase,@mui/materialand@mui/systemare declared optional (peerDependenciesMeta). The package installs and bundles with onlyreact. Bring the optional ones only for the modules that use them:@mui/materialfor the consent UI modules (@aglyn/aglyn/app-utils/consent-banner-ui,@aglyn/aglyn/app-utils/consent-preferences-dialog);@mui/materialand@mui/systemalso supply types that some node and component type definitions refer to.nextfor@aglyn/aglyn/app-utils/advertising-tag-mounts, which usesnext/script.firebaseis declared for apps that pair the model with Firebase, as Aglyn's own apps do. No module in this package needs it to load.
This is the "logic only" consumer story: @aglyn/aglyn together with
@aglyn/besigner installs with react as the only peer, and needs no UI
library, no next, and no Firebase SDK.
What's in it
Entry points:
@aglyn/aglynis the full barrel, for client code.@aglyn/aglyn/serveris the server-safe barrel. It re-exports the same model, managers and pure utilities without the client React contexts, so it can be imported from React Server Components. It also carries the modules that use Node built-ins or a JavaScript parser and are therefore kept out of the client barrel: the Web-to-(req, res)API adapter, API idempotency, the person key, the plugin bundle checks, and the server side of realm plugins.@aglyn/aglyn/*maps to a file undersrc/lib, for example@aglyn/aglyn/aglynor@aglyn/aglyn/app-utils/markdown-lite. A subpath names a file, not a folder. Importing by subpath keeps a bundle to what it uses.
Main areas under src/lib:
aglynis the runtime singleton. It exportsaglynand its parts:emitter,plugins,components,canvasandlogger. The instance is keyed onglobalThis, so duplicate module copies in one JavaScript realm share one runtime.typesholds the node and screen model:NodeSchema,NodesMap,ComponentSchema,PresetSchema,ScreenSchema, routing and AST types.foundationholds the platform document types (AglynHost,AglynScreen,AglynLayout,AglynHostTheme, organization and billing shapes, and their id types) and shared constants.emit-managerisEmitManager(aneventemitter2emitter) and theAglynEventenum of lifecycle and action events.components-managerisComponentManager, the registry of component factories, their schemas, and presets.plugin-managerisPluginManager(plugin registration and dependency status) plus the plugin seams: the plugin loader (createPluginLoader), contributions, configuration, permissions, entitlements, events, services and jobs. Aglyn's feature plugins attach to the platform through these.canvas-managerisCanvasManager, the observable node tree: set, create, delete, duplicate, reparent and reorder nodes, with undo and redo history.app-utilsis a large set of pure helpers over the model: node composition and sanitizing, binding tokens and variables, datasets and collections, SEO and sitemap helpers, the markdown-lite dialect, permissions and roles, consent, analytics keys, media references, and more. Its React contexts (site context, media picker, enabled plugins and others) are exported from the client barrel only.utilshas the feature-flag predicates such asisFeatureEnabled.
Usage
import { AglynEvent, canvas, components, emitter } from '@aglyn/aglyn'
emitter.on(AglynEvent.COMPONENT_REGISTERED, ({ $id }) => {
console.log('registered', $id)
})
components.registerComponent(MyBox, {
$id: 'my-box',
pluginId: 'my-plugin',
displayName: 'My box',
})
components.getSchema('my-box')
// `nodes` is a NodesMap: node id -> NodeSchema
canvas.setNodes(nodes)
const root = canvas.rootNodeFrom a Server Component or other server code:
import type { AglynScreen, NodeSchema } from '@aglyn/aglyn/server'How it fits
@aglyn/aglyn is the core scope of the package map. It imports only itself
and the generic @aglyn/shared-* packages. It holds no rendering, no designer,
no tenancy and no plugin: the core never imports a plugin, and a plugin's
domain lives in that plugin. Everything else stands on it:
@aglyn/aglyn-node-renderer turns its node trees into React,
@aglyn/besigner and @aglyn/besigner-ui edit them, the @aglyn/tenant-*
packages serve them, and every @aglyn/plugins-* package registers into its
managers.
License
Apache-2.0. Source: https://github.com/aglyn/aglyn/tree/main/libs/aglyn
