Repository navigation
feat(typescript): @diaryx/twig, TypeScript bindings over twig compiled to WebAssembly - #17
Merged
Merged
Conversation
Embed::set_body takes a body edited outside fig's Rust editor (fig's TypeScript one, say) and render splices it in. Embed::open_or_init_with opens a new block on a given body rather than empty, which a JSON block needs: an empty body is not a JSON document, so open_or_init could never write a new JSON block.
twig_document_metadata locates a document's front or end metadata block (or an HTML page's <script> data island), twig_document_metadata_json reads its body as JSON through fig, and twig_editor_set_metadata replaces the body, or writes a new front block, as one splice and one undo step. twig_alloc and twig_free let a caller outside the library's memory, the WebAssembly build driven from JavaScript, place its input. All additive, so TWIG_ABI_VERSION stays 6. The workspace gains a size-first `wasm` profile for the module @diaryx/twig inlines, and twig-capi asserts the wasm32 struct layouts that package reads.
…Script and JavaScript bindings/typescript is a new npm package, built as fig's @diaryx/fig is: twig-capi compiled for wasm32-unknown-unknown with every language twig ships, inlined as base64, and loaded lazily (or with init() on a browser main thread). It wraps parsing, rendering, conversion and its diagnostics, queries, the flat tree and hit tests, the lossless editor with undo, and a document's metadata: located, read as data, and replaced, with @diaryx/fig for edits that keep comments. The package takes the workspace's version: ship's post_bump writes it in with scripts/version-sync.mjs, and the new `version` job checks it. A `typescript` job builds and tests the package, in ship ci and in CI, and release-npm.yml publishes it on a v* tag. The guide is docs/typescript.md.
…() was pending init() replaced the module's exports when its compile resolved, even if a synchronous call had already made an instance. Handles made before then live in the first instance's memory, so the next call on one ran against the second and trapped. The first instance now stays, and a test in a process of its own covers the mix.
…at does not parse twig::meta::replace_body replaces a block's whole body without parsing the old one, so it repairs a block whose body does not parse, and reparses the host to check the block reads the new body back. A body that parses as its language but holds the block's closing fence (TOML's +++ inside a multi-line string) would have ended the block early and left the rest as document text; it is Error::BodyEscapesBlock now, and nothing changes. Embed::open_with opens a block on a new body. twig_editor_set_metadata goes through replace_body and reports the new refusal as TWIG_STATUS_UNSAFE_METADATA.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
@diaryx/twig, TypeScript bindings for twig, built the way fig builds@diaryx/fig.What changes
bindings/typescript(new npm package). twig-capi is compiled forwasm32-unknown-unknownwith every language twig ships and inlined as base64 (1.3 MiB module, 1.8 MiB as base64). It loads lazily, or withawait init()on a browser main thread, and imports nothing. The API:Document: parse (format by code or name, Markdown flags),renderHtml,serialize(convert),diagnostics,ast,query,nodes(flat tree),children,nodeAt/nodesAt.Editor: locator edits (replace,insertBefore/After/Child,delete,unwrap,moveBefore/After,filter),editRange,undo/redo,revision, and a livedocument()view.metadata(at)(lang, spans, body),metadataValue(at)(the body as data),Editor#setMetadata(body, { at, lang }). Front and end blocks and HTML<script type="application/…">islands (feat(meta): read and edit a document's HTML <script> data island #16). To keep comments, edit the body with@diaryx/fig. A test does this round trip with the published fig 7 packages.renderHtml,convert,parseAst,readMetadata,metadataValue,setMetadata.TWIG_ABI_VERSIONstays 6):twig_document_metadata,twig_document_metadata_json,twig_editor_set_metadata,twig_alloc,twig_free. twig-capi now also asserts the wasm32 struct layouts the package reads. Awasmcargo profile is added.Embed::set_bodyandEmbed::open_or_init_with.open_or_initcould not write a new JSON block, because an empty body is not valid JSON.post_bumprunsscripts/version-sync.mjs, and newversionandtypescriptship jobs check it. CI gets atypescriptjob.release-npm.ymlpublishes on av*tag.docs/typescript.md(made withprov new; it is also the npm README), plus README and RELEASING.Verified
ship ci: all 5 jobs pass (test, cli-wasi, capi with the new C header checks, version, typescript 19/19).cargo test -p twig-doc --no-default-featurespasses.dist/loads without the source condition, and thatnpm pack --dry-runhas the expected contents.Not done here
NPM_TOKENsecret is not set on this repo, and nobody has claimed@diaryx/twigon npm yet.