lynkow 3.4.0 → 3.4.1

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.
Files changed (2) hide show
  1. package/README.md +96 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -88,6 +88,7 @@ The SDK is isomorphic and works on both browser and server environments. Some fe
88
88
  | Analytics tracking | ✅ | ❌ (no-op) |
89
89
  | Consent banner | ✅ | ❌ (no-op) |
90
90
  | Branding badge | ✅ | ❌ (no-op) |
91
+ | Content enhancements | ✅ | ❌ (no-op) |
91
92
  | Locale detection | ✅ | ✅ (returns default) |
92
93
  | Cache | localStorage | In-memory |
93
94
 
@@ -400,6 +401,96 @@ lynkow.branding.remove()
400
401
  lynkow.branding.isVisible() // true/false
401
402
  ```
402
403
 
404
+ ## Content Enhancements (Browser-only)
405
+
406
+ The SDK automatically enhances HTML content from the API with interactive features.
407
+
408
+ ### Features
409
+
410
+ - **Code blocks**: Copy button with visual feedback
411
+ - **Text alignment**: CSS rules to ensure `text-align` styles are respected
412
+
413
+ ```typescript
414
+ // Enhancements are initialized automatically when the client is created
415
+ const lynkow = createClient({ siteId: 'your-site-id' })
416
+
417
+ // Manually re-initialize after loading dynamic content
418
+ lynkow.enhancements.init()
419
+
420
+ // Check if initialized
421
+ lynkow.enhancements.isInitialized()
422
+
423
+ // Clean up
424
+ lynkow.enhancements.destroy()
425
+ ```
426
+
427
+ ### Rendering HTML Content
428
+
429
+ The API returns HTML content in the `bodyHtml` field. To render it properly:
430
+
431
+ #### Option 1: dangerouslySetInnerHTML (Simple)
432
+
433
+ ```jsx
434
+ function Article({ content }) {
435
+ return (
436
+ <article dangerouslySetInnerHTML={{ __html: content.bodyHtml }} />
437
+ )
438
+ }
439
+ ```
440
+
441
+ #### Option 2: html-react-parser (Recommended)
442
+
443
+ If you use `html-react-parser` to convert HTML to React components, **you must preserve the `style` attribute** for text alignment to work:
444
+
445
+ ```jsx
446
+ import parse, { domToReact, attributesToProps } from 'html-react-parser'
447
+
448
+ const options = {
449
+ replace: (domNode) => {
450
+ if (domNode.type !== 'tag') return
451
+
452
+ // Convert HTML attributes to React props (including style)
453
+ const props = attributesToProps(domNode.attribs)
454
+ const children = domToReact(domNode.children, options)
455
+
456
+ switch (domNode.name) {
457
+ case 'h2':
458
+ return <h2 {...props}>{children}</h2>
459
+ case 'h3':
460
+ return <h3 {...props}>{children}</h3>
461
+ case 'p':
462
+ return <p {...props}>{children}</p>
463
+ // Add other tags as needed
464
+ }
465
+ }
466
+ }
467
+
468
+ function Article({ content }) {
469
+ return <article>{parse(content.bodyHtml, options)}</article>
470
+ }
471
+ ```
472
+
473
+ > ⚠️ **Important**: The `attributesToProps` function automatically converts `style="text-align: center"` to `{ style: { textAlign: 'center' } }`. Without this, inline styles will be lost and text alignment won't work.
474
+
475
+ ### Code Block HTML Structure
476
+
477
+ The API returns code blocks with this structure:
478
+
479
+ ```html
480
+ <div class="code-block" data-language="javascript">
481
+ <div class="code-block-header">
482
+ <span class="code-block-language">JavaScript</span>
483
+ <button class="code-block-copy" data-copy-code>...</button>
484
+ </div>
485
+ <pre><code class="language-javascript">const x = 1;</code></pre>
486
+ </div>
487
+ ```
488
+
489
+ The SDK automatically:
490
+ - Injects CSS styles for the code block UI
491
+ - Binds click handlers to copy buttons
492
+ - Shows visual feedback when code is copied
493
+
403
494
  ## Events
404
495
 
405
496
  Subscribe to SDK events for reactive updates.
@@ -556,6 +647,11 @@ import type {
556
647
  - Built-in caching (localStorage in browser, memory on server)
557
648
  - Debug logging option
558
649
 
650
+ ### New in v3.4
651
+
652
+ - **Content enhancements**: Code block copy buttons, text alignment CSS fixes
653
+ - Automatic binding with MutationObserver for dynamic content
654
+
559
655
  ### Upgrade Steps
560
656
 
561
657
  ```typescript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lynkow",
3
- "version": "3.4.0",
3
+ "version": "3.4.1",
4
4
  "description": "Official SDK for Lynkow Headless",
5
5
  "author": "Lynkow",
6
6
  "license": "SEE LICENSE IN LICENSE",