Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnumbered chapters #234

Merged
merged 7 commits into from
Oct 10, 2024
Merged
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,744 changes: 836 additions & 908 deletions examples/Frankenstein.mawe

Large diffs are not rendered by default.

80 changes: 80 additions & 0 deletions examples/Unnumbered.mawe
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<story uuid="4881b810-89e9-4b9e-aa14-c178309f7c1a" format="mawe" version="3" name="Unnumbered">
<!--/
===============================================================================

STORY: Unnumbered

===============================================================================
/-->
<head/>
<export type="short" chapterelem="chapter" chaptertype="named"/>
<!--/
===============================================================================
/-->
<body>
<chapter name="Prologue" unnumbered="true">
<scene name="Scene">
<p>Test unnumbered chapters.</p>
</scene>
<scene name="Scene">
<br/>
</scene>
</chapter>
<chapter name="Chapter 1">
<scene name="Scene">
<p>This is numbered.</p>
</scene>
<scene name="Scene">
<br/>
</scene>
</chapter>
<chapter name="Act II" unnumbered="true">
<scene name="Scene">
<p>Act II</p>
</scene>
</chapter>
<chapter name="Chapter 2">
<scene name="Scene">
<br/>
</scene>
<scene name="Scene">
<br/>
</scene>
</chapter>
<chapter name="Epilogue" unnumbered="true">
<scene name="Epilogue">
<p>Epilogue</p>
<br/>
</scene>
</chapter>
</body>
<!--/
===============================================================================

NOTES

===============================================================================
/-->
<notes>
<chapter name="">
<scene name="">
<br/>
</scene>
</chapter>
</notes>
<!--/
===============================================================================
/-->
<ui>
<view/>
<arc elements="scenes" template="plotpoints" mode="topCCW"/>
<editor>
<body words="numbers" indexed="chapter,scene,synopsis"/>
</editor>
</ui>
<history>
<words date="2024-10-08" text="0" missing="0" chars="0"/>
<words date="2024-10-09" text="9" missing="0" chars="56"/>
<words date="2024-10-10" text="9" missing="0" chars="56"/>
</history>
</story>
2 changes: 1 addition & 1 deletion examples/migration/Story1.v2.mawe
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
</scene>
</part>
</body>
<export chapterelem="part"/>
<export type="long" chapterelem="part" chaptertype="numbered" scenes="separated"/>
<ui><chart elements="parts"/></ui>
15 changes: 11 additions & 4 deletions src/document/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,27 @@ export function elemAsText(elem) {
)
}

export function elemName(elem) {
export function elemHeading(elem) {
if(elem.type === "chapter") {
if(elem.children.length && elem.children[0].type === "hchapter") {
return elemAsText(elem.children[0]);
return elem.children[0];
}
return undefined
}
if(elem.type === "scene") {
if(elem.children.length && elem.children[0].type === "hscene") {
return elemAsText(elem.children[0]);
return elem.children[0];
}
return undefined
}
return undefined
}

export function elemName(elem) {
return elemAsText(elemHeading(elem))
}

export function elemUnnumbered(elem) {
return elemHeading(elem)?.unnumbered
}

//-----------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions src/document/xmljs/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,11 @@ function parseSection(section) {
}

function parseChapter(chapter, index) {
const {name, folded} = chapter.attributes ?? {};
const {name, folded, unnumbered} = chapter.attributes ?? {};
const header = (!index && !name) ? [] : [{
type: "hchapter",
id: nanoid(),
unnumbered: unnumbered ? true : undefined,
children: [{text: name ?? ""}],
words: {}
}]
Expand All @@ -187,7 +188,7 @@ function parseChapter(chapter, index) {
type: "chapter",
id: nanoid(),
//name,
folded: (folded === "true") ? true : undefined,
folded: folded ? true : undefined,
children: [
...header,
...children,
Expand Down
50 changes: 25 additions & 25 deletions src/document/xmljs/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function migrate(root) {
v1_to_v2,
v2_fixes,
v2_to_v3,
v3_fix,
v3_fixes,
].reduce((story, func) => func(story), story)
}

Expand Down Expand Up @@ -151,6 +151,27 @@ function v2_to_v3(story) {
//
//*****************************************************************************

function v3_fixes(story) {

const {version} = story.attributes ?? {}

if(version !== "3") return story

const uiElem = elemFind(story, "ui")
const exportElem = elemFind(story, "export")

return {
...story,
elements: [
...story.elements
.filter(elem => elem.name !== "ui")
.filter(elem => elem.name !== "export"),
v3_fix_chart(uiElem),
v3_fix_exports(exportElem),
]
}
}

function v3_fix_chart(uiElem) {

if(!uiElem) return {type: "element", name: "ui", attributes: {}, elements: []}
Expand Down Expand Up @@ -183,34 +204,13 @@ function v3_fix_exports(exportElem) {
if(!exportElem) return {type: "element", name: "export", attributes: {}, elements: []}

const {attributes} = exportElem
const {chapterelem} = attributes
const {chaptertype, chapters, ...rest} = attributes

return {
...exportElem,
attributes: {
...attributes,
chapterelem: chapterelem === "part" ? "chapter" : chapterelem
...rest,
chapters: chapters ?? chaptertype,
}
}
}

function v3_fix(story) {

const {version} = story.attributes ?? {}

if(version !== "3") return story

const uiElem = elemFind(story, "ui")
const exportElem = elemFind(story, "export")

return {
...story,
elements: [
...story.elements
.filter(elem => elem.name !== "ui")
.filter(elem => elem.name !== "export"),
v3_fix_chart(uiElem),
v3_fix_exports(exportElem),
]
}
}
4 changes: 3 additions & 1 deletion src/document/xmljs/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { saveViewSettings } from "../../gui/app/views";
import { saveChartSettings } from "../../gui/arc/arc";
import { saveEditorSettings } from "../../gui/editor/editor";
import {saveExportSettings} from "../../gui/export/export";
import {uuid as getUUID, buf2file, elemName, filterCtrlElems} from "../util";
import {uuid as getUUID, buf2file, elemName, filterCtrlElems, elemUnnumbered} from "../util";

//----------------------------------------------------------------------------

Expand Down Expand Up @@ -131,13 +131,15 @@ function toNotes(notes) {
function toChapter(chapter) {
const {folded} = chapter;
const name = elemName(chapter)
const unnumbered = elemUnnumbered(chapter)

return xmlLines(
{
type: "chapter",
attributes: {
name: name,
folded: folded ? true : undefined,
unnumbered: unnumbered ? true : undefined,
},
},
...filterCtrlElems(chapter.children).map(toScene),
Expand Down
4 changes: 0 additions & 4 deletions src/gui/common/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ export function updateDocSubtitle(updateDoc, value) { updateDoc(doc => {doc.head
export function updateDocAuthor(updateDoc, value) { updateDoc(doc => {doc.head.author = value})}
export function updateDocPseudonym(updateDoc, value) { updateDoc(doc => {doc.head.pseudonym = value})}

export function updateDocStoryType(updateDoc, value) { updateDoc(doc => {doc.exports.type = value})}
export function updateDocChapterElem(updateDoc, value) { updateDoc(doc => {doc.exports.chapterelem = value})}
export function updateDocChapterType(updateDoc, value) { updateDoc(doc => {doc.exports.chaptertype = value})}

export class EditHead extends React.PureComponent {
render() {
const {head, updateDoc, expanded} = this.props
Expand Down
11 changes: 7 additions & 4 deletions src/gui/common/docIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {

import {FormatWords} from "./components";
import {elemAsText, elemName, filterCtrlElems} from "../../document";
import {wcCumulative} from "../../document/util";
import {elemUnnumbered, wcCumulative} from "../../document/util";

//-----------------------------------------------------------------------------

Expand Down Expand Up @@ -179,9 +179,9 @@ class ChapterItem extends React.PureComponent {
Draggable(provided, snapshot) {
const {elem, include, wcFormat, onActivate, unfold, current, refCurrent} = this.props
const {innerRef, draggableProps, dragHandleProps} = provided
const unnumbered=elemUnnumbered(elem)

return <div
className="Chapter"
ref={innerRef}
{...draggableProps}
>
Expand All @@ -191,6 +191,7 @@ class ChapterItem extends React.PureComponent {
name={elemName(elem)}
words={elem.words}
folded={!unfold && elem.folded}
unnumbered={elemUnnumbered(elem)}
wcFormat={wcFormat}
onActivate={onActivate}
current={current}
Expand Down Expand Up @@ -303,7 +304,7 @@ class SceneItem extends React.PureComponent {

class IndexItem extends React.PureComponent {
render() {
const {className, refCurrent, id, type, name, folded, words, wcFormat, onActivate, current, ...rest} = this.props
const {className, refCurrent, id, type, name, folded, unnumbered, words, wcFormat, onActivate, current, ...rest} = this.props

//console.log("Render IndexItem:", type, id, name)

Expand All @@ -312,14 +313,16 @@ class IndexItem extends React.PureComponent {
(type === "section") ? "SectionName" :
"BookmarkName"

const numClass = (type === "chapter" || type === "scene") ? (unnumbered ? "" : "Numbered") : ""

const foldClass = (folded) ? "Folded" : ""

function onClick(ev) {
return onActivate && onActivate(id)
}

return <ScrollRef current={current} id={id} refCurrent={refCurrent}>
<HBox className={addClass(className, typeClass, foldClass, "Entry")} onClick={onClick} {...rest}>
<HBox className={addClass(className, typeClass, numClass, foldClass, "Entry")} onClick={onClick} {...rest}>
<ItemIcon type={type}/>
<ItemLabel name={name ? name : "<Unnamed>"}/>
<Filler/>
Expand Down
11 changes: 5 additions & 6 deletions src/gui/common/styles/TOC.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,21 @@
/* ---------------------------------------------------------------------------- */

.TOC .ChapterName {
font-weight: bold;
/*
padding-top: 4pt !important;
padding-bottom: 4pt !important;
*/
}

.TOC .ChapterName .Name::before {
.TOC .ChapterName.Numbered .Name::before {
counter-increment: chapter;
content: counter(chapter) ". ";
/*
content: counter(chapter, upper-roman) "\00a0-\00a0";
*/
}

.TOC .ChapterName {
font-weight: bold;
}

.TOC div.SceneDropZone {
min-height: 16pt
}
Expand Down Expand Up @@ -117,10 +114,12 @@
*/
}

.TOC .SceneName .Name::before {
.TOC .SceneName.Numbered .Name::before {
/* width: 1cm; */
counter-increment: scene;
/*
content: counter(scene) ". ";
*/
}

.TOC .BookmarkName {
Expand Down
Loading