Closed samlown closed 2 years ago
If we assume for now that GOBLBuilder
will always work with one single code editor model (Monaco supports multiple, e.g. what's rendered as tabs in VS Code — but we likely won't need that yet), we could expose a property to set the JSON schema for the document. For example, your project would use the component like this:
<GOBLBuilder schema="https://gobl.org/draft-0/bill/invoice" />
It would then be up to the caller to decide where the schema
prop value comes from. E.g. a piece of local state in the UI, perhaps based on something contextual from the "Console Labels" we're currently drafting. WDYT @samlown?
As for enforcing/validating against the supplied schema, I'll look into the Monaco Editor API. It should be possible to hook into the validation logic.
Added a PR. Can be tested via this preview URL.
Note: For now in the "demo wrapper" (e.g. https://build.gobl.org), I've hardcoded the required schema to https://gobl.org/draft-0/bill/invoice
. A follow up issue/PR will be to lift the "Load template..." logic out of the GOBLBuilder
component; a parent/container project should do data loading and pass in data and/or required schema to GOBLBuilder
. For the demo, we can keep the template loading logic, but it would be invoked from the demo wrapper code, not from within the GOBLBuilder
component as we do right now.
Oh nice! That works quite well actually! Suggests sound good for the demo wrapper. That makes sense :+1:
https://gobl.org/draft-0/bill/invoice
in my sales section.Not sure what the best way to provide the schema would be. Perhaps as a query parameter?
It's tempting to expect the schema to be passed in a more compact form, like
bill.Invoice
orbill/invoice
, but I think it's important to include the complete schema so it can be used with any other format in the future.