lexxy 0.1.8.beta → 0.1.10.beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +78 -3
- data/app/assets/javascript/lexxy.js +320 -142
- data/app/assets/javascript/lexxy.js.br +0 -0
- data/app/assets/javascript/lexxy.js.gz +0 -0
- data/app/assets/javascript/lexxy.min.js +2 -2
- data/app/assets/javascript/lexxy.min.js.br +0 -0
- data/app/assets/javascript/lexxy.min.js.gz +0 -0
- data/lib/lexxy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fffdc9d43469a6366a3d6fa16b6e5b8284c5a19bdcfa3cbffeb79a96cf16970
|
4
|
+
data.tar.gz: b1e76d677c2c7e9c55ff713eba32c89f04cc0e267153f4e4def7cf48238dc733
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c7752a992efceb4f40f411bb154037a21b7ffeb83db7dc28bf882f68ed2ff57f21ebe4c1d61dc420d6b344fd45fb8d819595a753e33d90134a8e3536d6fd0ba
|
7
|
+
data.tar.gz: 761ce9eee667c72a4cab67a5572cad3013f468c9248f415477c144b640a26852400c07afcdbe287afe492f858d54a798281ac96c89814fd69683f3ecd4488d77
|
data/README.md
CHANGED
@@ -341,9 +341,84 @@ The sandbox app is available at http://localhost:3000. There is also a CRUD exam
|
|
341
341
|
|
342
342
|
## Events
|
343
343
|
|
344
|
-
|
345
|
-
|
346
|
-
|
344
|
+
Lexxy fires a handful of custom events that you can hook into.
|
345
|
+
Each event is dispatched on the `<lexxy-editor>` element.
|
346
|
+
|
347
|
+
### `lexxy:initialize`
|
348
|
+
|
349
|
+
Fired when the `<lexxy-editor>` element is attached to the DOM and ready for use.
|
350
|
+
This is useful for one-time setup.
|
351
|
+
|
352
|
+
### `lexxy:change`
|
353
|
+
|
354
|
+
Fired whenever the editor content changes.
|
355
|
+
You can use this to sync the editor state with your application.
|
356
|
+
|
357
|
+
### `lexxy:file-accept`
|
358
|
+
|
359
|
+
Fired when a file is dropped or inserted into the editor.
|
360
|
+
|
361
|
+
- Access the file via `event.detail.file`.
|
362
|
+
- Call `event.preventDefault()` to cancel the upload and prevent attaching the file.
|
363
|
+
|
364
|
+
### `lexxy:insert-link`
|
365
|
+
|
366
|
+
Fired when a plain text link is pasted into the editor.
|
367
|
+
Access the link’s URL via `event.detail.url`.
|
368
|
+
|
369
|
+
You also get a handful of callback helpers on `event.detail`:
|
370
|
+
|
371
|
+
- **`replaceLinkWith(html, options)`** – replace the pasted link with your own HTML.
|
372
|
+
- **`insertBelowLink(html, options)`** – insert custom HTML below the link.
|
373
|
+
- **Attachment rendering** – pass `{ attachment: true }` in `options` to render as non-editable content,
|
374
|
+
or `{ attachment: { sgid: "your-sgid-here" } }` to provide a custom SGID.
|
375
|
+
|
376
|
+
#### Example: Link Unfurling with Stimulus
|
377
|
+
|
378
|
+
When a user pastes a link, you may want to turn it into a preview or embed.
|
379
|
+
Here’s a Stimulus controller that sends the URL to your app, retrieves metadata,
|
380
|
+
and replaces the plain text link with a richer version:
|
381
|
+
|
382
|
+
```javascript
|
383
|
+
// app/javascript/controllers/link_unfurl_controller.js
|
384
|
+
import { Controller } from "@hotwired/stimulus"
|
385
|
+
import { post } from "@rails/request.js"
|
386
|
+
|
387
|
+
export default class extends Controller {
|
388
|
+
static values = {
|
389
|
+
url: String, // endpoint that handles unfurling
|
390
|
+
}
|
391
|
+
|
392
|
+
unfurl(event) {
|
393
|
+
this.#unfurlLink(event.detail.url, event.detail)
|
394
|
+
}
|
395
|
+
|
396
|
+
async #unfurlLink(url, callbacks) {
|
397
|
+
const { response } = await post(this.urlValue, {
|
398
|
+
body: JSON.stringify({ url }),
|
399
|
+
headers: {
|
400
|
+
"Content-Type": "application/json",
|
401
|
+
"Accept": "application/json"
|
402
|
+
}
|
403
|
+
})
|
404
|
+
|
405
|
+
const metadata = await response.json()
|
406
|
+
this.#insertUnfurledLink(metadata, callbacks)
|
407
|
+
}
|
408
|
+
|
409
|
+
#insertUnfurledLink(metadata, callbacks) {
|
410
|
+
// Replace the pasted link with your custom HTML
|
411
|
+
callbacks.replaceLinkWith(this.#renderUnfurledLinkHTML(metadata))
|
412
|
+
|
413
|
+
// Or, insert below the link as an attachment:
|
414
|
+
// callbacks.insertBelowLink(this.#renderUnfurledLinkHTML(metadata), { attachment: true })
|
415
|
+
}
|
416
|
+
|
417
|
+
#renderUnfurledLinkHTML(link) {
|
418
|
+
return `<a href="${link.canonical_url}">${link.title}</a>`
|
419
|
+
}
|
420
|
+
}
|
421
|
+
```
|
347
422
|
|
348
423
|
## Contributing
|
349
424
|
|