Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/plotdb/datadom
dom serializer / deserializer.
https://github.com/plotdb/datadom
dom dom-tree json
Last synced: 29 days ago
JSON representation
dom serializer / deserializer.
- Host: GitHub
- URL: https://github.com/plotdb/datadom
- Owner: plotdb
- Created: 2020-11-27T02:20:59.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-06-15T08:57:46.000Z (over 1 year ago)
- Last Synced: 2024-12-11T13:12:42.783Z (about 2 months ago)
- Topics: dom, dom-tree, json
- Language: LiveScript
- Homepage:
- Size: 5.5 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# datadom
DOM serializer / deserializer with scriptable plugins.
WIP, please consider this as an unstable library.
# Usage
install via npm:
npm install --save @plotdb/datadom
Add `datadom.js` in your HTML:
serialize/deserialize a DOM tree:
json = datadom.serialize(document.querySelector("your-selector"), [])
datadom.deserialize(json,[])
.then({node, promise}) ->
node # node is the deserialized DOM tree root.
promise # promise for asynchronous content
.then ({node, promise}) -> # all content prepared.datadom is also a constructor:
dd = new datadom({ ... })
dd.init().then(function() { ... });# API
constructor options:
- `plugin`: function, of Array of functions as default plugin(s).
- plugin function accepts 1 parameters: subtree root ( for serialize ) / subdoc root ( for deserialize )
- `data`: datadom json
- `node`: root of DOM tree. ignored if `data` is provided.
- `window`: optional `window` object if run in NodeJS.datadom object methods:
- `init()`: initialize data and node ( from provided counterpart ). Return promise.
- `update(ops)`: apply ops ( operation transformations ) to internal data and DOM tree.
- `getData()`: return datadom json.
- `getNode()`: return root of the corresponding DOM tree.datadom class methods:
- `serialize(node, plugin)`: convert DOM tree (with root `node`) into json.
- `node`: root node of DOM tree to serialize
- `plugin(d)`: optional handler for custom node types.
- `deserialize(data, plugin)`: convert datadom json into DOM tree
- `data`: a datadom json.
- `plugin(d)`: optional handler for custom node types.## Node.js
to run in nodeJS, use `jsdom` and pass `window` as an argument:
datadom.deserialize(data, [], (new JSDOM()).window);
similarly, pass `window` in constructor when using `new datadom( ... )`:
new datadom({ ..., window: (new JSDOM()).window)});
## Plugins
(TBD) check `doc/plugin.md` for more information.
# License
MIT