@document-explorer/core
v0.1.1
Published
Framework-agnostic engine for the Document Explorer: data mapping, normalization, tree, search, sort, selection and store.
Maintainers
Readme
@document-explorer/core
The engine behind Document Explorer — framework-free,
with zero runtime dependencies and no DOM access. Every renderer
(@document-explorer/react, @document-explorer/angular) is a thin subscriber
to what lives here.
Useful on its own if you want the behaviour without the UI.
npm install @document-explorer/coreThe store
import { createExplorerStore } from '@document-explorer/core';
const store = createExplorerStore({
data: apiRows,
mapper,
selection: { enabled: true, mode: 'multiple' },
search: { scope: 'global', searchableFields: ['metadata.owner'] },
events: { onDocumentOpen: (item) => open(item.viewUrl) },
});
store.subscribe(() => render(store.getSnapshot()));
store.actions.openFolder('engineering');getSnapshot() returns a memoized, render-ready view — filtered and sorted
rows, breadcrumbs, selected items, normalizer warnings — and is referentially
stable until something actually changes, so it drops straight into
useSyncExternalStore or an Angular signal.
Modules
| Module | Purpose |
| --- | --- |
| mapper | resolveMapper() — turn any row shape into the canonical DocumentItem. Fields accept a key, a dot path, or a function. |
| normalize | Build the DocumentIndex. Accepts flat rows and nested children; repairs duplicate ids, missing parents, cycles and files-used-as-folders, collecting each as a warning rather than throwing. |
| tree | getChildren, getDescendants, getAncestors, getBreadcrumbs, isWithin. |
| search | Case- and diacritic-insensitive matching over the name plus any configured dot paths. |
| sort | Type-aware comparators with an Intl.Collator, so file9 precedes file10 and ISO dates sort chronologically. Missing values sort last in both directions. |
| selection | Single/multiple, files/folders togglable, optional max, range select against the visible order. Keyed by id, so it survives navigation and filtering. |
| keyboard | createKeyboardNavigator() — the key-to-intent contract, shared by every renderer so shortcuts cannot drift between frameworks. |
| fileTypes | An extensible registry rather than if (ext === 'pdf'). Resolves mimeType → extension → name suffix → fallback. |
| format | formatBytes and formatDate, both Intl-based and locale-aware. |
| path | getValueAtPath() — the single dot-path accessor reused by the mapper, columns, search and sort. |
Extending file types
import { registerFileType } from '@document-explorer/core';
registerFileType({ extensions: ['rs'], label: 'Rust', iconKey: 'rust' });iconKey is a string, never a component — that is what keeps this package
free of any renderer dependency. Each UI package maps the key to its own icon.
License
MIT
