Skip to content

Commit 5595d31

Browse files
committed
fix: update PDFObject import for compatibility; add global-ot initialization; refine mousewheel import handling
1 parent d52c088 commit 5595d31

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

public/js/extra.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
import Prism from 'prismjs'
55
import hljs from 'highlight.js'
6-
// Fix PDFObject import to work with both dev and prod builds
7-
import * as PDFObjectModule from 'pdfobject'
6+
import * as PDFObject from 'pdfobject'
87

98
import { saveAs } from 'file-saver'
109

@@ -67,8 +66,6 @@ import { instance as vizInstance } from '@viz-js/viz'
6766
let viz = null
6867
vizInstance().then(instance => { viz = instance })
6968

70-
const PDFObject = PDFObjectModule.default || PDFObjectModule
71-
7269
const ui = getUIElements()
7370

7471
// auto update last change

public/js/global-ot.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if (typeof window.ot === 'undefined') {
2+
window.ot = {};
3+
}

public/js/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ import '@vendor/inlineAttachment/codemirror.inline-attachment'
9595
import Visibility from 'visibilityjs'
9696
// Import the original vendor file
9797

98+
import './global-ot'
9899
import '@hackmd/ot'
99100
import '@hackmd/ot/lib/socketio-adapter'
100101
import '@hackmd/ot/lib/codemirror-adapter'
101102
import '@hackmd/ot/lib/undo-manager'
102-
// import '@hackmd/ot/lib/client'
103+
import '@hackmd/ot/lib/client'
103104
import '@hackmd/ot/lib/editor-client'
104105

105106
import * as mousewheel from 'jquery-mousewheel'
@@ -226,8 +227,7 @@ import '@css/extra.css'
226227
import '@css/site.css'
227228
import 'spin.js/spin.css'
228229

229-
const mw = mousewheel.default || mousewheel // Fix for mousewheel import
230-
mw($)
230+
mousewheel?.default?.($)
231231

232232
// ot.Client = Client
233233
// ot.EditorClient = EditorClient

vite.config.mjs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ export default defineConfig({
125125
emptyOutDir: true, // Clean the output directory before building
126126
manifest: true, // Generate manifest.json
127127
rollupOptions: {
128+
moduleContext: (id) => {
129+
const modules = ['pdfobject', 'jquery-mousewheel']
130+
131+
if (modules.some(module => id.includes(module))) {
132+
return 'window' // Set context for specific modules
133+
}
134+
return undefined
135+
},
128136
input: {
129137
// Define JS entry points
130138
index: path.resolve(__dirname, 'public/js/index.js'),
@@ -140,7 +148,7 @@ export default defineConfig({
140148
// Example: 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
141149
__dirname: '""', // Define __dirname as empty string for browser compatibility
142150
global: 'globalThis', // Explicitly define global for Vite
143-
ot: {} // Define ot as empty object for browser compatibility
151+
// ot: {} // Define ot as empty object for browser compatibility
144152
},
145153
root: __dirname,
146154
base: '/.vite/', // Updated to match our custom base path in app.js

0 commit comments

Comments
 (0)