Import and export documents
Export
Section titled “Export”Export JSON downloads the document and its design sidecar as a pair, named
after the micro-app — Team lunch RSVP becomes team-lunch-rsvp.json and
team-lunch-rsvp.mica-design.json. The document file is the versioned
envelope described in the document format,
with nothing from the editor session in it: no selection, no open page, no
preview state, no field catalog or host-action catalogue, and no fixtures
or graph. Those live only in the sidecar.
In code, the document is serializeDocument(document). The sidecar is never
copied into that JSON.
Import
Section titled “Import”Import opens a dialog pre-filled with the current document and, when one
is loaded, its sidecar. Paste a document (and optionally the sidecar) and
press Replace document, or Open files to choose {stem}.json and
{stem}.mica-design.json together. A missing sidecar is fine. If the
document is refused, the dialog shows why and nothing changes; if it is
accepted, it replaces the open document in one undoable step and the editor
switches to the document’s pack. A stale sidecar (fingerprint mismatch, or
aliases and page keys that no longer exist) drops the unknown entries and
shows a notice; it never fails the import.
In code, parseDocument(json) does exactly the same checks and returns
{ ok: true, spec, pack } or { ok: false, error }. Both stop at the first
problem; listDocumentIssues(json) returns all of them at once, each with the
element it is about and where it sits in the document, so several can be fixed
in one pass. See using the functions.
parseDocument never reads the sidecar.
The sidecar
Section titled “The sidecar”{stem}.mica-design.json holds designer extras the envelope must not grow:
graph layout for the designer’s data and page maps, and mock fixtures the preview
plays. It declares sidecarVersion: 1 and a documentFingerprint (SHA-256 of
the document in canonical serializeDocument form, so a designer-built file
and a re-imported export of it share a digest). Fixtures are two maps:
fixtures.objects.{alias}.{op} and fixtures.hostActions.{name} — an object
alias and a host action may share a name without colliding. graph.objects,
graph.pages, graph.hostActions and graph.state store node x/y (and
collapsed except on pages); hiddenGroups lists host-type prefixes the map
hides. Unknown keys are
refused at every level on sidecar load, the same honesty as documents. Theme,
field catalogues and host-action catalogues are not stored here. How the
designer uses that graph — search, grouping, click-to-bind, Show on
canvas — is in
Explore the data and page maps.
What import checks
Section titled “What import checks”Import rebuilds the document from scratch and refuses anything it does not fully understand, naming the offending field rather than dropping it:
- Envelope —
envelopeVersionmust be1; unknown top-level,ui,metaormeta.packfields are refused. A pre-envelope document (withroot,elements,stateandmetaat the top level) is still accepted and comes back out as an envelope. - Pack —
meta.packmust name a curated pack and its exact version. A document with nometais treated as a Signal document. - Structure — the root is a
PageStackwhose children are allPages, with at least one page; every child exists, belongs to one parent, and is reachable from the root; there are no cycles. - Placement — every parent-child pair is one the designer could build:
children only on components that accept them, a
Pageonly directly in the rootPageStack, and no otherPageStack. - Components — every
typebelongs to the pack, and every prop passes that component’s own schema. An unknown prop is refused by name, and so is an expression a prop does not take, such as$template. - Element fields — only
type,props,children,on,visibleand, on a Stack or Grid,repeat.watchandslotsare refused as not enabled in this version of Mica; anything else as unsupported. - Interactions — actions, state paths, conditions, business-object declarations, host-action declarations and every read and write against them, as described in the reference.
Messages you may see
Section titled “Messages you may see”Each of these is what parseDocument returns for a small change to the
first micro-app document:
| Change | Message |
|---|---|
meta.pack.version set to 2.0.0 |
Document requires Signal 2.0.0; this editor provides 1.0.0. |
A colour prop added to a Text |
Unknown prop “colour” on Text “rsvp-intro”. |
A watch field added to an element |
Element “rsvp-intro” uses “watch”, which is not enabled in this version of Mica. Remove it and re-import. |
A repeat field added to a Text |
Element “rsvp-intro” (repeat): repeat is available on Stack and Grid only; put the repeated content in one. |
A button’s goToPage aimed at page-9 |
Element “thanks-back” (on.press[0]): goToPage targets unknown page “page-9”. |
A button’s on.press renamed to on.commit |
Element “thanks-back” (on.commit): “Button” does not declare the event “commit”. |
An Input given an on.press |
Element “rsvp-name” (on.press): “Input” does not declare the event “press”. |
| An element no page contains | Element “card” is not reachable from the PageStack root. |
An Input bound to /guest while another reads /guest/name |
Element “rsvp-diet” (props.value): $bindState “/guest” would overwrite “/guest/name”, which element “rsvp-name” (value) uses; bind a field inside it instead. |
An Input value of {"$state": …} |
Invalid Input props on “rsvp-name”: props.value uses unsupported expression “$state”; value must be text, a {"$bindState": "/path"} binding, or inside a list template a {"$bindItem": "field"} binding; use $bindState, not $state, for editable fields. |
A Text content of json-render’s {"$template": …} |
Invalid Text props on “thanks-name”: props.content uses unsupported expression “$template”; content takes a literal value or a “$state”, “$item”, “$index”, “$format”, “$calc”, “$expr” or “$label” expression. |
| The back button moved inside the intro Text | Element “rsvp-intro” (Text) cannot hold “thanks-back” (Button); Text takes no children. |
| The thanks page moved inside the RSVP Section | Element “rsvp-card” (Section) cannot hold “page-thanks” (Page); a Page belongs directly in the root PageStack. |
A fixtures member added at the top level |
Document carries unsupported field “fixtures”. |
A graph member added at the top level |
Document carries unsupported field “graph”. |
Eleven more come from small changes to the order history example, which has lists:
| Change | Message |
|---|---|
An Input bound to the repeated /deliverySteps |
Element “note” (props.value): $bindState “/deliverySteps” would write the list “/deliverySteps”, which element “steps” (repeat) repeats over; edit a row's field with $bindItem inside the template. |
A heading outside the list reading $item |
Element “heading” (props.content): props.content reads $item, which is only available inside the template of a repeated Stack or Grid. |
| A row read of a field the collection does not declare | Element “order-reference” (props.content): Object “orders” declares no field “warehouse”. |
The row Button’s setState value set to {"$item": "reference"} |
Element “order-track” (on.press[0]): setState params.value is a row read, which json-render resolves to the row's position path, not its value; put the row field inside a setState record, an object input or an object action's row. |
An Input in an order card with {"$bindItem": "reference"} |
Element “order-note” (props.value): Rows of object “orders” belong to the host and are never edited in place; copy the row into a draft from a button in the row, and save it with update. |
The row Button’s delete without its row |
Element “order-remove” (on.press[0]): delete “orders” needs row: { “id”: … }, the identity of the row to delete. |
The row Button’s delete naming its row by {"$item": "reference"} |
Element “order-remove” (on.press[0]): delete “orders” row “id” reads “reference”; a row of “orders” is named by its identity, { "$item": "id" }. |
An Input in a delivery step with {"$bindItem": "code"} |
Element “step-code” (props.value): $bindItem “code” would edit “code”, the key that tells rows apart; editing it rebuilds the row on every keystroke and hides rows whose keys collide. |
The row Button’s setState renamed to pushState |
Element “order-track” (on.press[0]): pushState is json-render's built-in list action, which removes by position and cannot be bounded; use addRow or removeRow. |
The row Button’s action replaced by an addRow of /deliverySteps that sets code |
Element “order-track” (on.press[0]): addRow “/deliverySteps” sets “code”, the key; Mica gives every added row a key of its own. |
The row Button’s setState aimed at /deliverySteps/0/label |
Element “order-track” (on.press[0]): setState “/deliverySteps/0/label” writes inside the list “/deliverySteps”; change its rows with addRow, removeRow or $bindItem. |