docs: document scriptUrl, the offline options, and the exported types - #54
docs: document scriptUrl, the offline options, and the exported types#54sidgaikwad wants to merge 2 commits into
Conversation
`scriptUrl` is fully implemented and tested but was absent from the props table, so the only supported way to pin an embed environment was undiscoverable outside the .d.ts. Add it, along with the doc comment's caveat about one embed winning per page. Also close the gaps around it: - `offline`, `licenseUrl` and `env` were named in the options row but never explained anywhere. Give them a section with a worked example. - Add a TypeScript usage example — every other example was JSX — and a table of the exported types. The TypeScript example is verified to compile against the real source types via the demo's tsconfig.
|
@sidgaikwad is attempting to deploy a commit to the Unlayer Team on Vercel. A member of the Team first needs to authorize it. |
|
@sidgaikwad One issue to fix: the new example combines Please separate URL-hosted assets from true offline usage, and document the asset-map and local-script setup required for offline operation. |
The offline example combined offline: true with IMAGE_EDITOR_BASE_URL, but
offline turns off URL-based asset loading, so that configuration silently
produces an editor with no stickers, no frames and fallback text fonts.
In image-editor 2.4.0 the asset resolver is
assetMap?.[path] ?? bundled[path] ?? (!offline && base ? `${base}/assets/${path}` : '')
with `bundled` empty in the CDN build, so with offline set and no injected
map every asset resolves to ''. Confirmed in the browser: offline plus a
valid IMAGE_EDITOR_BASE_URL gives 590 sticker <img> elements with 590 empty
src attributes; dropping offline alone takes that to 0.
Split the section in two:
- Self-hosting the editor assets — IMAGE_EDITOR_BASE_URL and scriptUrl,
online, assets still resolved by URL.
- Offline mode — what it disables, plus the three things a working setup
needs: locally served scripts, an asset map via setAssetsMap on the
image-editor-ready event, and self-hosted UI fonts, since the Google
Fonts stylesheet is not injected when offline.
|
You are right, and the example was worse than merely misleading — it produces an editor with no stickers or frames at all. Fixed in I traced it in the 2.4.0 bundle rather than guessing. The asset resolver is: let assetMap = null; // set by setAssetsMap()
const bundled = {}; // empty in the CDN build
// offline and base assigned at mount from options.offline / env.IMAGE_EDITOR_BASE_URL
resolve(path) =
assetMap?.[path] ?? bundled[path]
?? (!offline && base ? `${base}/assets/${path}` : "");
Confirmed in the browser, with
In the control the srcs resolve to What changedSplit into two sections that are no longer confusable: Self-hosting the editor assets — Offline mode — leads with a callout that
I also noted that a missing key resolves to One thing to confirmI documented the map injection as README TypeScript example still compiles; Prettier and lint clean. |
Fixes #36.
scriptUrl(the actual bug)scriptUrlis a fully implemented, fully tested prop —loadScript(scriptUrl), part of the remount effect's deps, covered by "forwards a custom scriptUrl to loadScript" and "remounts when scriptUrl changes". But it was absent from the props table, so the only supported way to pin an embed environment was undiscoverable short of reading the.d.ts.Added, along with the caveat already written in its doc comment — the kind of thing people otherwise discover by breaking it:
The related gaps from the issue
Offline / self-hosted assets.
offline,licenseUrlandenvwere named in theoptionsrow and explained nowhere — that's the entire offline and self-hosted-assets story. New section with a table and a worked example, plus a note thatenvis remount-tier.TypeScript. Every example was JSX. Added a
.tsxexample and a table of the five exported types (ImageEditorProps,ImageEditorOptions,ImageEditorRef,ImageEditorInstance,ImageEditorSaveResult).Verification
The TypeScript example isn't hand-waved — I extracted it from the README and compiled it against the real source types through the demo's tsconfig:
Prettier clean.