squiffy-runtime 6.0.0-beta.0 → 6.0.0-beta.2
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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "squiffy-runtime",
|
|
3
|
-
"version": "6.0.0-beta.
|
|
3
|
+
"version": "6.0.0-beta.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/squiffy.runtime.js",
|
|
6
6
|
"types": "dist/squiffy.runtime.d.ts",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"css.escape": "^1.5.1",
|
|
37
37
|
"global-jsdom": "^25.0.0",
|
|
38
38
|
"jsdom": "^25.0.0",
|
|
39
|
-
"squiffy-compiler": "^6.0.0-beta.
|
|
39
|
+
"squiffy-compiler": "^6.0.0-beta.2",
|
|
40
40
|
"typescript": "^5.6.2",
|
|
41
41
|
"vite": "^7.1.3",
|
|
42
42
|
"vite-plugin-dts": "^4.5.4"
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"handlebars": "^4.7.8",
|
|
47
47
|
"marked": "^16.2.0"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "d8f215aafa4534ddff8ecee0f8eaa4dd3eb9a46a"
|
|
50
50
|
}
|
|
@@ -100,6 +100,27 @@ test('"Hello world" script should run', async () => {
|
|
|
100
100
|
expect(element.innerHTML).toMatchSnapshot();
|
|
101
101
|
});
|
|
102
102
|
|
|
103
|
+
test("squiffy.story.go() in section JS navigates without showing original section content", async () => {
|
|
104
|
+
// Regression test for https://github.com/textadventures/squiffy/issues/179
|
|
105
|
+
// Note: the 4-space indent on the next line is the squiffy JS syntax - don't trim it!
|
|
106
|
+
const script = ` squiffy.story.go('destination');
|
|
107
|
+
Default section text that should not appear.
|
|
108
|
+
|
|
109
|
+
[[destination]]:
|
|
110
|
+
Destination section text.`;
|
|
111
|
+
|
|
112
|
+
const { element } = await initScript(script);
|
|
113
|
+
|
|
114
|
+
// Only the destination section content should be visible
|
|
115
|
+
const html = element.innerHTML;
|
|
116
|
+
expect(html).toContain("Destination section text.");
|
|
117
|
+
expect(html).not.toContain("Default section text that should not appear.");
|
|
118
|
+
|
|
119
|
+
// The destination section should be the only section element (no empty default section)
|
|
120
|
+
expect(element.querySelectorAll(".squiffy-output-section").length).toBe(1);
|
|
121
|
+
expect(element.querySelector(".squiffy-output-section")?.getAttribute("data-section")).toBe("destination");
|
|
122
|
+
});
|
|
123
|
+
|
|
103
124
|
test("Click a section link", async () => {
|
|
104
125
|
const script = await fs.readFile("../examples/test/example.squiffy", "utf-8");
|
|
105
126
|
const { squiffyApi, element } = await initScript(script);
|
package/src/squiffy.runtime.ts
CHANGED
|
@@ -180,20 +180,30 @@ export const init = async (options: SquiffyInitOptions): Promise<SquiffyApi> =>
|
|
|
180
180
|
clearScreen();
|
|
181
181
|
}
|
|
182
182
|
newSection(sectionName);
|
|
183
|
+
const sectionElement = currentSectionElement;
|
|
183
184
|
if (master) {
|
|
184
185
|
await run(master, "[[]]");
|
|
186
|
+
if (get("_section") !== sectionName) {
|
|
187
|
+
// JS in the master section navigated away; clean up the empty element we created.
|
|
188
|
+
sectionElement.remove();
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
185
191
|
}
|
|
186
192
|
await run(currentSection, `[[${sectionName}]]`);
|
|
187
193
|
|
|
194
|
+
if (get("_section") !== sectionName) {
|
|
195
|
+
// JS in this section navigated away; clean up the empty element we created.
|
|
196
|
+
sectionElement.remove();
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
|
|
188
200
|
// Setup validation after transitions complete (animations may have replaced DOM elements)
|
|
189
201
|
setupInputValidation(currentSectionElement);
|
|
190
202
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
save();
|
|
196
|
-
}
|
|
203
|
+
set("_turncount", 0);
|
|
204
|
+
writeUndoLog();
|
|
205
|
+
save();
|
|
206
|
+
|
|
197
207
|
const newCanGoBack = canGoBack();
|
|
198
208
|
if (newCanGoBack != oldCanGoBack) {
|
|
199
209
|
emitter.emit("canGoBackChanged", { canGoBack: newCanGoBack });
|
|
@@ -224,7 +234,13 @@ export const init = async (options: SquiffyInitOptions): Promise<SquiffyApi> =>
|
|
|
224
234
|
await processAttributes(section.attributes);
|
|
225
235
|
}
|
|
226
236
|
if (section.jsIndex !== undefined) {
|
|
237
|
+
const sectionBefore = get("_section");
|
|
227
238
|
runJs(section.jsIndex);
|
|
239
|
+
if (get("_section") !== sectionBefore) {
|
|
240
|
+
// JS called squiffy.story.go() and navigated away; the destination
|
|
241
|
+
// section will handle rendering its own content.
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
228
244
|
}
|
|
229
245
|
|
|
230
246
|
ui.write(section.text || "", source);
|