Skip to content

Commit 49ab949

Browse files
refactor: adds loader module for normalization purposes
1 parent 01929c1 commit 49ab949

File tree

18 files changed

+236
-14
lines changed

18 files changed

+236
-14
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Nutrient Viewer Loader Abstraction
3+
*
4+
* This utility provides a consistent way to load NutrientViewer regardless of installation method.
5+
* For CDN installations, it retrieves from window object.
6+
* For package installations, it imports from @nutrient-sdk/viewer.
7+
*/
8+
9+
/**
10+
* Load NutrientViewer instance
11+
* @returns Promise that resolves to NutrientViewer instance
12+
* @throws Error if NutrientViewer cannot be loaded
13+
*/
14+
export async function loadNutrientViewer() {
15+
// For CDN installation: get from window object
16+
const { NutrientViewer } = window;
17+
18+
if (!NutrientViewer) {
19+
throw new Error(
20+
"NutrientViewer is not available. Make sure the Nutrient Web SDK is properly loaded via CDN.",
21+
);
22+
}
23+
24+
return NutrientViewer;
25+
}

frameworks/nextjs/JS/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"lint": "next lint"
1919
},
2020
"dependencies": {
21+
"@nutrient-sdk/viewer": "^1.7.0",
2122
"next": "^15.3.0",
2223
"react": "^19.0.0",
2324
"react-dom": "^19.0.0"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Nutrient Viewer Loader Abstraction
3+
*
4+
* This utility provides a consistent way to load NutrientViewer regardless of installation method.
5+
* For CDN installations, it retrieves from window object.
6+
* For package installations, it imports from @nutrient-sdk/viewer.
7+
*/
8+
9+
import type NutrientViewer from "@nutrient-sdk/viewer";
10+
11+
/**
12+
* Load NutrientViewer instance
13+
* @returns Promise that resolves to NutrientViewer instance
14+
* @throws Error if NutrientViewer cannot be loaded
15+
*/
16+
export async function loadNutrientViewer(): Promise<typeof NutrientViewer> {
17+
// For CDN installation: get from window object
18+
const { NutrientViewer } = window;
19+
20+
if (!NutrientViewer) {
21+
throw new Error(
22+
"NutrientViewer is not available. Make sure the Nutrient Web SDK is properly loaded via CDN.",
23+
);
24+
}
25+
26+
return NutrientViewer;
27+
}

frameworks/nextjs/TS/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
"lint": "next lint"
1919
},
2020
"dependencies": {
21+
"@nutrient-sdk/viewer": "^1.7.0",
2122
"next": "^15.3.0",
2223
"react": "^19.0.0",
2324
"react-dom": "^19.0.0"
2425
},
2526
"devDependencies": {
26-
"@nutrient-sdk/viewer": "^1.7.0",
2727
"@types/node": "^20.0.0",
2828
"@types/react": "^18.0.0",
2929
"@types/react-dom": "^18.0.0",

frameworks/nuxtjs/JS/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
"preview": "nuxt preview",
1919
"postinstall": "nuxt prepare"
2020
},
21+
"dependencies": {
22+
"@nutrient-sdk/viewer": "^1.7.0"
23+
},
2124
"devDependencies": {
2225
"@nuxt/devtools": "latest",
2326
"nuxt": "^3.17.4"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Nutrient Viewer Loader Abstraction
3+
*
4+
* This utility provides a consistent way to load NutrientViewer regardless of installation method.
5+
* For CDN installations, it retrieves from window object.
6+
* For package installations, it imports from @nutrient-sdk/viewer.
7+
*/
8+
9+
/**
10+
* Load NutrientViewer instance
11+
* @returns Promise that resolves to NutrientViewer instance
12+
* @throws Error if NutrientViewer cannot be loaded
13+
*/
14+
export async function loadNutrientViewer() {
15+
// For CDN installation: get from window object
16+
const { NutrientViewer } = window;
17+
18+
if (!NutrientViewer) {
19+
throw new Error(
20+
"NutrientViewer is not available. Make sure the Nutrient Web SDK is properly loaded via CDN.",
21+
);
22+
}
23+
24+
return NutrientViewer;
25+
}

frameworks/nuxtjs/TS/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
"preview": "nuxt preview",
1919
"postinstall": "nuxt prepare"
2020
},
21+
"dependencies": {
22+
"@nutrient-sdk/viewer": "^1.7.0"
23+
},
2124
"devDependencies": {
22-
"@nutrient-sdk/viewer": "^1.7.0",
2325
"@nuxt/devtools": "latest",
2426
"nuxt": "^3.17.4",
2527
"vue-tsc": "^2.0.0"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Nutrient Viewer Loader Abstraction
3+
*
4+
* This utility provides a consistent way to load NutrientViewer regardless of installation method.
5+
* For CDN installations, it retrieves from window object.
6+
* For package installations, it imports from @nutrient-sdk/viewer.
7+
*/
8+
9+
import type NutrientViewer from "@nutrient-sdk/viewer";
10+
11+
/**
12+
* Load NutrientViewer instance
13+
* @returns Promise that resolves to NutrientViewer instance
14+
* @throws Error if NutrientViewer cannot be loaded
15+
*/
16+
export async function loadNutrientViewer(): Promise<typeof NutrientViewer> {
17+
// For CDN installation: get from window object
18+
const { NutrientViewer } = window;
19+
20+
if (!NutrientViewer) {
21+
throw new Error(
22+
"NutrientViewer is not available. Make sure the Nutrient Web SDK is properly loaded via CDN.",
23+
);
24+
}
25+
26+
return NutrientViewer;
27+
}

frameworks/react/JS/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"preview": "vite preview"
2020
},
2121
"dependencies": {
22+
"@nutrient-sdk/viewer": "^1.7.0",
2223
"react": "^18.0.0",
2324
"react-dom": "^18.0.0",
2425
"react-router-dom": "^6.0.0"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Nutrient Viewer Loader Abstraction
3+
*
4+
* This utility provides a consistent way to load NutrientViewer regardless of installation method.
5+
* For CDN installations, it retrieves from window object.
6+
* For package installations, it imports from @nutrient-sdk/viewer.
7+
*/
8+
9+
/**
10+
* Load NutrientViewer instance
11+
* @returns Promise that resolves to NutrientViewer instance
12+
* @throws Error if NutrientViewer cannot be loaded
13+
*/
14+
export async function loadNutrientViewer() {
15+
// For CDN installation: get from window object
16+
const { NutrientViewer } = window;
17+
18+
if (!NutrientViewer) {
19+
throw new Error(
20+
"NutrientViewer is not available. Make sure the Nutrient Web SDK is properly loaded via CDN.",
21+
);
22+
}
23+
24+
return NutrientViewer;
25+
}

0 commit comments

Comments
 (0)