Skip to content

Commit 53f726d

Browse files
fix: adjust biome.json for solid, makes fixes to implementation in solid and solid start
1 parent a042cbf commit 53f726d

File tree

19 files changed

+829
-262
lines changed

19 files changed

+829
-262
lines changed

biome.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,17 @@
2121
"enabled": true,
2222
"clientKind": "git",
2323
"useIgnoreFile": true
24-
}
24+
},
25+
"overrides": [
26+
{
27+
"include": ["frameworks/solid/**", "frameworks/solidstart/**"],
28+
"linter": {
29+
"rules": {
30+
"correctness": {
31+
"useJsxKeyInIterable": "off"
32+
}
33+
}
34+
}
35+
}
36+
]
2537
}

frameworks/solid/js/biome.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
3+
"linter": {
4+
"enabled": true,
5+
"rules": {
6+
"correctness": {
7+
"useJsxKeyInIterable": "off"
8+
}
9+
}
10+
}
11+
}

frameworks/solid/js/src/nutrient/basic-viewer/implementation.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Basic Nutrient Viewer Implementation for SolidJS (JavaScript)
2+
* Basic Nutrient Viewer Implementation for React (JavaScript)
33
*
44
* This is the simplest way to load a PDF document with Nutrient Web SDK.
55
*/
@@ -21,9 +21,13 @@ export function loadBasicViewer(
2121
const config = {
2222
container,
2323
document,
24-
...(nutrientConfig.baseUrl && { baseUrl: nutrientConfig.baseUrl }),
2524
};
2625

26+
// Add baseUrl if configured (for package installations)
27+
if (nutrientConfig.baseUrl) {
28+
config.baseUrl = nutrientConfig.baseUrl;
29+
}
30+
2731
return nutrientViewer.load(config);
2832
}
2933

Lines changed: 74 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,104 @@
1-
/**
2-
* Custom Overlays Implementation for SolidJS (JavaScript)
3-
*
4-
* Demonstrates interactive overlays that appear on page clicks
5-
*/
6-
71
import { nutrientConfig } from "../nutrient-config.js";
82

93
/**
10-
* Load the viewer with custom overlay functionality
11-
* @param nutrientViewer - The NutrientViewer object
12-
* @param container - The container element
4+
* Load a PDF viewer with custom overlays functionality
5+
* @param nutrientViewer - The NutrientViewer object (from CDN or package)
6+
* @param container - The container element to mount the viewer
137
* @param document - URL to the PDF document
8+
* @returns Promise that resolves when the viewer is loaded
149
*/
1510
export async function loadCustomOverlaysViewer(
1611
nutrientViewer,
1712
container,
1813
document = nutrientConfig.documentUrl,
1914
) {
15+
if (!nutrientViewer) {
16+
throw new Error("NutrientViewer is required");
17+
}
18+
19+
// Ensure there's only one NutrientViewer instance
20+
nutrientViewer.unload(container);
21+
2022
const config = {
2123
container,
2224
document,
2325
...(nutrientConfig.baseUrl && { baseUrl: nutrientConfig.baseUrl }),
2426
};
2527

26-
const instance = await nutrientViewer.load(config);
28+
// Load the viewer with custom overlays configuration
29+
return load(nutrientViewer, config);
30+
}
2731

28-
// Add click event listener for custom overlays
29-
instance.addEventListener("page.click", (event) => {
30-
const { pageIndex, point } = event;
32+
/**
33+
* Internal load function with custom overlays configuration
34+
* @param nutrientViewer - The NutrientViewer object
35+
* @param defaultConfiguration - Base configuration object
36+
*/
37+
function load(nutrientViewer, defaultConfiguration) {
38+
return nutrientViewer.load(defaultConfiguration).then((instance) => {
39+
console.log("Nutrient Web SDK successfully loaded!!", instance);
3140

32-
// Create overlay content
33-
const overlayElement = document.createElement("div");
34-
overlayElement.innerHTML = `
35-
<div style="background: white; padding: 15px; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,0.2);">
36-
<h3 style="margin: 0 0 10px 0;">Page ${pageIndex + 1}</h3>
37-
<p style="margin: 0;">Clicked at: (${Math.round(point.x)}, ${Math.round(point.y)})</p>
38-
<button id="close-overlay" style="margin-top: 10px; padding: 5px 10px;">Close</button>
39-
</div>
40-
`;
41+
// Every time a user clicks on the page, we show a custom overlay item on
42+
// this page.
43+
instance.addEventListener("page.press", (event) => {
44+
if (event.pageIndex === 0) {
45+
instance.setCustomOverlayItem(getOverlayItemForPage1(nutrientViewer));
46+
}
4147

42-
// Add overlay to the instance
43-
const overlay = new nutrientViewer.Overlay({
44-
element: overlayElement,
45-
pageIndex,
46-
position: point,
47-
onDisappear: () => overlay.remove(),
48+
if (event.pageIndex === 1) {
49+
instance.setCustomOverlayItem(getOverlayItemForPage2(nutrientViewer));
50+
}
4851
});
4952

50-
// Close button handler
51-
overlayElement
52-
.querySelector("#close-overlay")
53-
.addEventListener("click", () => {
54-
overlay.remove();
55-
});
53+
return instance;
54+
});
55+
}
56+
57+
function getOverlayItemForPage1(nutrientViewer) {
58+
// We create a div element with an emoji and a short text.
59+
const overlayElement = document.createElement("div");
60+
61+
overlayElement.style.cssText =
62+
"width: 300px;background: #FFF; border: 1px #333 solid; font-family: sans-serif; font-size: 14px; padding: 20px;";
63+
overlayElement.innerHTML =
64+
"<p>👋 This is an overlay item that appears when clicking on the first page. Find out what happens when you click on the second page.";
5665

57-
instance.setCustomOverlayItem(overlay);
66+
// Then we return a NutrientViewer.CustomOverlayItem which uses the overlayElement
67+
// that we created above as a node, the pageIndex we get from our onPress
68+
// event and define the position on the page.
69+
return new nutrientViewer.CustomOverlayItem({
70+
id: "overlay-item-first-page",
71+
node: overlayElement,
72+
pageIndex: 0,
73+
position: new nutrientViewer.Geometry.Point({ x: 300, y: 50 }),
5874
});
75+
}
5976

60-
return instance;
77+
function getOverlayItemForPage2(nutrientViewer) {
78+
const overlayElement = document.createElement("div");
79+
80+
// In this case we embed a video to the page
81+
overlayElement.innerHTML =
82+
'<iframe src="https://player.vimeo.com/video/227250697" width="500" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
83+
84+
// Then we return a NutrientViewer.CustomOverlayItem which uses the overlayElement
85+
// that we created above as a node, the pageIndex we get from our onPress
86+
// event and define the position on the page.
87+
return new nutrientViewer.CustomOverlayItem({
88+
id: "overlay-item-second-page",
89+
node: overlayElement,
90+
pageIndex: 1,
91+
position: new nutrientViewer.Geometry.Point({ x: 55, y: 220 }),
92+
});
6193
}
6294

6395
/**
64-
* Unload the viewer from a container
65-
* @param nutrientViewer - The NutrientViewer object
96+
* Unload the custom overlays viewer from a container
97+
* @param nutrientViewer - The NutrientViewer object (from CDN)
6698
* @param container - The container element
6799
*/
68-
export function unloadCustomOverlaysViewer(nutrientViewer, container) {
69-
nutrientViewer.unload(container);
100+
export async function unloadCustomOverlaysViewer(nutrientViewer, container) {
101+
if (nutrientViewer) {
102+
nutrientViewer.unload(container);
103+
}
70104
}

0 commit comments

Comments
 (0)