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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f5d2b0484ac9aad5019fd912a29090835732381b605e9738ed7d53ee92c30ae6
4
- data.tar.gz: 5f4d8f87542fa4af872eda21776c0af69e504b7ca1aa6e9139d510b5b23d214b
3
+ metadata.gz: 2fffdc9d43469a6366a3d6fa16b6e5b8284c5a19bdcfa3cbffeb79a96cf16970
4
+ data.tar.gz: b1e76d677c2c7e9c55ff713eba32c89f04cc0e267153f4e4def7cf48238dc733
5
5
  SHA512:
6
- metadata.gz: b0ed0fd1d053b8d4a88362120f2bb21ab3a79ef7f24e0a0b24fcb59f6b4e40a9b90c53329150b4b4f39370bff9556781c2b679d2c667800f7a3de2e6d7f922fc
7
- data.tar.gz: 5fbe5195dbc24bf382aad7c51d76108eb7be0903819bf10f2b59014ddd062fe18d133d36314511868526217603588774d7a0b12719529cf59acab24f3b82654f
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
- * `lexxy:initialize`: Fired whenever the `<lexxy-editor>` element is attached to the DOM and is ready for use.
345
- * `lexxy:change`: Fired whenever the editor content changes.
346
- * `lexxy:file-accept`: Fired whenever a file is dropped or inserted into the editor. You can access the `File` object through the `event.detail.file` property. Call `preventDefault` on the event to cancel upload and prevent attaching the file.
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