Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/getting-started/vanilla/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<header>
<h1>SuperDoc Example</h1>
<button id="loadButton">Load Document</button>
<span id="pageCount" style="margin-left: 20px; font-weight: bold;"></span>
<input
type="file"
id="fileInput"
Expand Down
2 changes: 1 addition & 1 deletion examples/getting-started/vanilla/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dev": "vite"
},
"dependencies": {
"superdoc": "0.20.0-next.13"
"superdoc": "1.2.1"
},
"devDependencies": {
"vite": "^4.4.6"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update devDeps as well

npx npm-check-updates -u

Expand Down
19 changes: 19 additions & 0 deletions examples/getting-started/vanilla/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let editor = null;
function initializeEditor(file = null) {
// Cleanup previous instance if it exists
if (editor) {
editor.destroy();
editor = null;
}

Expand All @@ -23,6 +24,24 @@ function initializeEditor(file = null) {
},
onEditorCreate: (event) => {
console.log('Editor is created', event);

// Get page count after editor is created
setTimeout(() => {
const documents = editor.superdocStore.documents;
const presentationEditor = documents[0]?.getPresentationEditor();

if (presentationEditor) {
Comment on lines +29 to +33

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid computing page count before documents finish loading

The onEditorCreate callback runs as soon as the editor instance is created, but document initialization in superdocStore.init is async (it awaits file/URL loading). With the fixed setTimeout(100) here, editor.superdocStore.documents can still be empty for larger files or remote URLs, so presentationEditor stays undefined and the page count is never displayed. This shows up when users load a real document via the file picker: the UI stays blank even though the document eventually renders. Consider waiting for a document-ready signal (e.g., a store-ready flag/event) or recomputing when pages become available rather than using a hard-coded delay.

Useful? React with 👍 / 👎.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please assess if this is relevant or not

const pages = presentationEditor.getPages();
const pageCount = pages.length;
console.log(`Document has ${pageCount} page(s)`);

// Display page count in UI
const pageCountDisplay = document.getElementById('pageCount');
if (pageCountDisplay) {
pageCountDisplay.textContent = `Pages: ${pageCount}`;
}
}
}, 100); // Small delay to ensure layout is complete
},
});
}
Expand Down
21 changes: 21 additions & 0 deletions examples/getting-started/vanilla/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name = "superdoc-page-count"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why cloudflare pages? :)

I thought we agreed on Github pages instead

compatibility_date = "2023-12-01"

[env.production]
account_id = ""
zone_id = ""

# Pages configuration
pages_build_output_dir = "dist"

# Build configuration
[build]
command = "npm run build"
cwd = ""

# Environment variables (if needed)
[vars]

# Custom domains (optional)
[env.production.routes]
# Add custom domains here if needed
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ catalog:
eslint: ^9.39.1
eslint-config-prettier: ^9.1.0
eslint-import-resolver-typescript: ^4.4.4
eslint-plugin-import-x: ^4.16.1
eslint-plugin-import-x: 4.16.1
eslint-plugin-jsdoc: ^54.1.0
eventemitter3: ^5.0.1
he: ^1.2.0
Expand Down
Loading