@aglyn/besigner
v1.0.0-beta.172
Published
The logic of Besigner, Aglyn's visual editor, with no UI in it: editor app and interface state, selection and hover, drag-and-drop rules, the element and style clipboards, and node moves. Install it if you are building your own editor UI over Aglyn's node
Downloads
1,074
Readme
@aglyn/besigner
The logic of Besigner, Aglyn's visual editor, with no UI in it: editor app and
interface state, selection and hover, drag-and-drop rules, the element and
style clipboards, and node moves. Install it if you are building your own
editor UI over Aglyn's node model. If you want the editor as it ships, take
@aglyn/besigner-ui, which is built on this package.
Beta. Published from the Aglyn monorepo under the
betadist-tag; APIs can change between beta releases.
Install
npm install @aglyn/besigner@betaPeer dependencies:
react(used for ref types only; the package renders nothing)
This is the "logic only" consumer story: @aglyn/besigner together with
@aglyn/aglyn installs with react as the only peer. It needs no next, no
Firebase SDK, no MUI and no @aglyn/besigner-ui. The framework peers of
@aglyn/aglyn are all optional.
What's in it
Editor app and interface state:
initializeBesignerApp,getBesignerApp,doesBesignerAppExistanddeleteBesignerAppmanage named editor app instances (BesignerAppController). With no name, the default app is used.BesignerInterfaceControllerholds the editor's flags and panel state.setBesignerFlag,setBesignerFlags,setBesignerPanelandsetBesignerPanelsupdate it for a given app.- Constants and types for that state:
InteractionModeFlag,BesignerDeviceFlag,BesignerPanelViewFlag,BesignerPanelTabFlag,BesignerContextand the flag and panel key types.
Managers, which act on the canvas of @aglyn/aglyn:
focusis the selection, hover and tree-expansion state:setSelectedNode,getSelected,rangeSelectNode,clearSelection,setHoveredNode,expandNode,collapseNodeand others.dndis aDndManagerinstance tracking the current drag, drop target and drop region. Beside it areconfirmValidLinealRelationship, which checks whether an item may sit under a given parent (the lineal rules), and the drop-region geometry helpers such asdetermineDropRegion.clipboardcopies and pastes elements (copyNodes,pasteInto,hasContent,clear), andstyleClipboarddoes the same for styles. The clipboard mirrors itself intolocalStorage.moveNodeIn,moveNodeOut,canMoveNodeIn,canMoveNodeOut,resolveMoveInandresolveMoveOutmove a node one level into or out of its neighbors.pickis the "pick an element on the canvas" mode:startPick,cancelPick,isPicking,handlePickClick.refsmaps node ids to their rendered DOM refs, for a UI to fill.isTextEntryElementandisTextEntryFocusedtell a shortcut handler when the user is typing.devicePreviewWidthandisRootElementIdare small helpers.
Every file under src/lib is also reachable by subpath, for example
@aglyn/besigner/focus-manager/focus-manager.
Usage
import { canvas } from '@aglyn/aglyn'
import {
canMoveNodeOut,
clipboard,
focus,
initializeBesignerApp,
moveNodeOut,
} from '@aglyn/besigner'
const app = initializeBesignerApp()
// `nodes` is a NodesMap loaded from a stored screen version
canvas.setNodes(nodes)
const [first] = canvas.rootNode.children
focus.setSelectedNode(first)
clipboard.copyNodes(focus.getSelected())
const pasted = clipboard.pasteInto(canvas.rootNode)
if (pasted.error) console.warn(pasted.error)
if (canMoveNodeOut(first)) moveNodeOut(first)How it fits
This is the besigner scope of the package map: the designer's logic,
publishable without its UI. It imports the core (@aglyn/aglyn) and the
generic @aglyn/shared-* packages only. It never imports the designer UI, the
renderer or a plugin. @aglyn/besigner-ui is the React surface over it, and a
plugin may import it too.
License
Apache-2.0. Source: https://github.com/aglyn/aglyn/tree/main/libs/besigner/core
