Merge pull request #9110 from dotCooCoo/feat/plugin-api-importers-place

Plug-ins: importers whose manifest sets place also read files for File › Place
This commit is contained in:
BFlat authored and GitHub committed 2026-11-26 08:49:00 +07:00
commit fc34e27d99
41 files changed
+1008 -108

No files matched your search

+39 -8
View File
@@ -52,8 +52,32 @@ by its extension, and the importer lists the file's extension; when several do,
also one a built-in format reads (an importer that lists `svg` opens an `.svg` only this way). A damaged file of a
built-in format reports that format's error, and the file is not handed to an importer. The importer's objects become a
new document whose artboard is their bounds (at least 1 pt wide and high, and within ±4,000,000 pt); the document keeps
no path, so Save asks for a name. File › Place reads only the built-in formats, and a file only an importer reads opens
as a new document when it is dropped on the canvas. These rules are VectorCraft's own.
no path, so Save asks for a name. A file only an importer reads opens as a new document when it is dropped on the
canvas, unless an importer that places its files reads it (below). These rules are VectorCraft's own.
An importer whose manifest has `"place": true` also places its files. `document.formats` and `plugin.list` mark it with
`place: true`. `file.place`, `file.place.info` and `file.place.queue` read a file with it by the rules above, among the
importers that set `place`: when no built-in format reads the file, the first such importer by id that lists its
extension reads it, and `"importer": "plugin.<id>"` names one, which must set `place` and list the file's extension,
also one a built-in format reads. `"params"?: {…}` holds its parameters, which take their defaults when left out. The
importer is given at most 128 MiB of the file and `_context.mode` `"place"`, and returns its objects as it does for
File › Open. They are placed in the open document as
one group named after the file, in the order the importer returned them, at the place, size or object `at`, `rect`,
`replace` and `template` give, as one undo step; guides are left out, and the group's box is the bounds of what the
other objects draw. The file is embedded whatever `link`
says, as a format that can't be linked is, and the reply's `linked` is `false`. A decline, invalid output, a trap or
Cancel places nothing and leaves the document and its undo steps as they were. An importer without `place` is not used
by File › Place, and naming it is an error. A larger file is refused from its size. With `importer`, a `path` is refused
before any of it is read and `dataBase64` before any of it is decoded. Without `importer`, the first 64 KiB of the file
are read or decoded first to look for a built-in format. The web's File › Place reads the picked file in the browser
before the 128 MiB limit applies. In the app, File › Place lists a placing importer's extensions under "All placeable
files" and a filter of its own, named after the importer. Extensions that a built-in format reads are left out of both,
and an importer that lists only such extensions gets no filter. On the web, a dropped file that no built-in format
reads, by its extension or its content, is placed on the canvas by the first placing importer by id that lists its
extension (the desktop opens a dropped document, as it does an SVG); a dropped file that a built-in format reads goes
to that format. The importer then runs with its parameters' defaults. A file placed with `importer` goes to that
importer without the import options File › Place shows for a text file, a DXF drawing, a PDF or a PSD file. These rules
are VectorCraft's own.
In the app, installed filters appear under **Object › Plug-ins**, next to **Install Plug-in…** and **Reload
Plug-ins**; live effects under **Effect › Plug-ins** and in the Appearance panel's effect menu. A plug-in with
@@ -652,6 +676,11 @@ the module's start function, in a run that isn't a filter's run on a document, o
without the dot (`["plt"]`); the first is the one Export As gives the file. A built-in format keeps an extension both
list (`svg`): `document.export` then writes the exporter's format only when asked for by its format id, and
`document.open` reads a file with the importer only when `importer` names it.
- `place` (importers only): `true` lets File › Place read the importer's files too ([using plug-ins](#using-plug-ins));
`false`, the default, keeps it to File › Open. A value that isn't `true` or `false`, or the key on another kind, is
refused when the plug-in is installed. It asks for no permission beyond `import.read`: the importer is given the file
and its parameters alone, and the host places what it returns. Hosts from before the key ignore it, so there the
importer opens its files and places none.
- `commands` (filters and live effects; not heavy filters): up to 32 commands of the plug-in's own
([Commands](#commands)), each `{"id": "grow", "label": "Grow", "params"?: {…}, "menu"?: {…}}`. An `id` is 1–32
characters from `a-z 0-9 _` that starts with a letter, and appears once. A `label` is 1–64 printable characters;
@@ -870,7 +899,7 @@ counts toward the half of the memory cap that the input and the parameters share
"_context": {"mode": "filter", "bounds": [10, 0, 75, 60], "artboard": [0, 0, 612, 792], "documentData": {"pens": 4}}}
```
`mode` is `"filter"`, `"effect"`, `"export"`, `"import"` or `"command"` (a [command](#commands) run, whose
`mode` is `"filter"`, `"effect"`, `"export"`, `"import"`, `"place"` or `"command"` (a [command](#commands) run, whose
`command` is the command's id); `bounds` the selection's geometric bounds (a live effect: the reference box of the
effect, the object's bounds or those of the previous effect's result); `artboard` (filters) the artboard under the
selection's centre, else the first; `documentData` (filters) what the plug-in last kept with the document (`null` until
@@ -881,7 +910,8 @@ information](#document-information) asked for. A live effect's `item` says where
the extension of the file being written (one the exporter lists) and its name without the extension (the document's name
when the export is not given a path), which some formats keep in their header. An import's `_context` is `{"mode":
"import", "extension": "plt", "name": "Poster"}`: the extension of the file being opened and its name without the
extension.
extension. A place's `_context` is the same with `"mode": "place"`; the importer is given nothing of the document the
file is placed in.
### Output
@@ -1016,7 +1046,9 @@ with the export's own). A decline (`{"error": …}`), a missing `dataBase64` or
An **importer** returns `{"objects": [...], "warnings"?: ["…"]}`: new paths and compound paths (no `id`) in the
filters' object form, checked as a filter's new objects are, with warnings capped as an exporter's are and shown with
the open's own. An output with no objects, with keys other than `objects`, `warnings` and `error`, or with an object
that fails the checks opens nothing, and neither does a decline (`{"error": …}`).
that fails the checks opens nothing, and neither does a decline (`{"error": …}`). An importer that places its files
returns the same output when `_context.mode` is `"place"`; an output that fails, or whose objects other than guides draw
nothing of any width or height, places nothing.
## Writing a plug-in in Rust
@@ -1052,9 +1084,8 @@ per change of their input, parameters or paints (results are cached), not per fr
## Not in v1
- Tool plug-ins (pointer events on the canvas, a guide line or rectangle, geometry back), panel plug-ins, and
importers that place files (File › Place reads only the built-in formats) or make type, images, layers or
artboards.
- Tool plug-ins (pointer events on the canvas, a guide line or rectangle, geometry back), panel plug-ins, importers
that make type, images, layers or artboards, and placed importer files that stay linked to their file.
- Live effects that change opacity, blending or effects (at `api` 2 one may [paint](#painted-live-effects) the pieces
it returns), and filters that change type, images or symbol instances (a filter at `api` 2 reads them, see
[`inputs`](#reading-type-images-and-symbols)).