editor-js / editor-js/attaches

Add openFile hook to AttachesTool to support custom file opening logic

Open
#81 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
74
Forks
68
PR merge metrics
No merged PRs in 30d

Description

This update introduces a new openFile hook to the AttachesTool config.
It allows custom file-opening logic beyond the default browser behavior.

This is especially useful for:
- WebView environments (Android/iOS apps)
- Desktop applications that embed Editor.js
- Custom file viewers / sandboxed environments

When the hook is present, openFile(fileData) is executed instead of opening file.url in a new tab.
If the hook is missing or throws an error — the fallback browser action is triggered.

📌 Why this is useful
✔ Works in Android WebView

Browser links (target=_blank) do not work in WebView — but you can call the Android method.

🧩 Short PR Example Description
Added a new config option `openFile` to AttachesTool.
If provided, it overrides the default action when the user clicks the file icon.
Useful for WebView apps (Android/iOS), desktop clients, and custom environments where
opening external URLs is restricted. Falls back to the standard browser behavior
when not defined.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the AttachesTool configuration and the current file-icon action that opens file.url in a new tab. Trace how fileData reaches that action, then verify that an openFile hook takes precedence and that missing or throwing hooks use the existing browser fallback.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.