Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
klembot committed Oct 20, 2016
2 parents 6625a21 + 52fbd02 commit 44d4c28
Show file tree
Hide file tree
Showing 18 changed files with 160 additions and 52 deletions.
3 changes: 1 addition & 2 deletions grunt/nw.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ module.exports = function(grunt) {
var options = {
buildDir: 'build/nwjs/',
cacheDir: 'nwbuilder-cache/',
version: '0.16.0',
'chromium-args': '--enable-threaded-compositing',
version: '0.17.4',
macIcns: 'src/common/img/logo.icns',
winIco: 'src/common/img/logo.ico'
}
Expand Down
9 changes: 5 additions & 4 deletions src/common/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ TwineRouter.map({
const story = state.story.stories.find(
story => story.id === this.$route.params.id
);
const formatName = story.format || state.pref.defaultFormat;

const formatName = story.storyFormat || state.pref.defaultFormat;
const format = state.storyFormat.formats.find(
format => format.name === formatName
);
Expand Down Expand Up @@ -112,7 +113,7 @@ TwineRouter.map({
const story = state.story.stories.find(
story => story.id === this.$route.params.id
);
const formatName = story.format || state.pref.defaultFormat;
const formatName = story.storyFormat || state.pref.defaultFormat;
const format = state.storyFormat.formats.find(
format => format.name === formatName
);
Expand All @@ -134,9 +135,9 @@ TwineRouter.map({
ready() {
const state = this.$store.state;
const story = state.story.stories.find(
story => story.id === this.$route.params.id
story => story.id === this.$route.params.storyId
);
const formatName = story.format || state.pref.defaultFormat;
const formatName = story.storyFormat || state.pref.defaultFormat;
const format = state.storyFormat.formats.find(
format => format.name === formatName
);
Expand Down
2 changes: 1 addition & 1 deletion src/data/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function domToObject(storyEl, forceLastUpdate) {
: 100,
height:
passageEl.attributes.height ?
parseInt(passageEl.attributes.width.value)
parseInt(passageEl.attributes.height.value)
: 100,
tags:
passageEl.attributes.tags.value === '' ?
Expand Down
26 changes: 26 additions & 0 deletions src/data/story.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ const storyStore = module.exports = {
props
);

/*
Force the top and left properties to be at least zero, to keep
passages onscreen.
*/

if (newPassage.left < 0) {
newPassage.left = 0;
}

if (newPassage.top < 0) {
newPassage.top = 0;
}

newPassage.story = story.id;
story.passages.push(newPassage);

Expand All @@ -145,6 +158,19 @@ const storyStore = module.exports = {
UPDATE_PASSAGE_IN_STORY(state, storyId, passageId, props) {
let story = getStoryById(state, storyId);

/*
Force the top and left properties to be at least zero, to keep
passages onscreen.
*/

if (props.left && props.left < 0) {
props.left = 0;
}

if (props.top && props.top < 0) {
props.top = 0;
}

Object.assign(getPassageInStory(story, passageId), props);
story.lastUpdate = new Date();
},
Expand Down
4 changes: 2 additions & 2 deletions src/dialogs/formats/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
{{'Story formats control the appearance and behavior of stories during play.' | say}}
</p>

<format-item v-for="format in storyFormats" :format="format"></format-item>
<format-item v-for="format in storyFormats" :format="format" transition="fade-in-out"></format-item>
</tab-item>

<tab-item name="Proofing Formats">
<p>
{{'Proofing formats create a versions of stories tailored for editing and proofreading.' | say}}
</p>

<format-item v-for="format in proofingFormats" :format="format"></format-item>
<format-item v-for="format in proofingFormats" :format="format" transition="fade-in-out"></format-item>
</tab-item>

<tab-item name="Add a New Format">
Expand Down
52 changes: 42 additions & 10 deletions src/dialogs/formats/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ module.exports = Vue.extend({
template: require('./index.html'),

data: () => ({
// Used to create the <format-item>s using v-for.
storyFormats: [],
proofingFormats: [],
// Detail about each format.
loadedFormats: [],

// Determines whether to show the error <span>, and with what text.
error: '',
Expand All @@ -24,20 +23,53 @@ module.exports = Vue.extend({
newFormatUrl: ''
}),

/*
These are linked to the Vuex formatNames, so that when a format is deleted
it will disappear from these properties.
*/

computed: {
proofingFormats() {
let result = [];

this.formatNames.forEach(name => {
const format = this.loadedFormats.find(
format => format.name === name
);

if (format && format.properties.proofing) {
result.push(format);
}
});

return result;
},

storyFormats() {
let result = [];

this.formatNames.forEach(name => {
const format = this.loadedFormats.find(
format => format.name === name
);

if (format && !format.properties.proofing) {
result.push(format);
}
});

return result;
}
},

methods: {
// Loads the next pending format.

loadNext() {
if (this.loadIndex < this.formatNames.length) {
this.loadFormat(this.formatNames[this.loadIndex])
.then(format => {
if (format.properties.proofing) {
this.proofingFormats.push(format);
}
else {
this.storyFormats.push(format);
}

this.loadedFormats.push(format);
this.loadIndex++;
this.loadNext();
})
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/formats/item.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
const Vue = require('vue');
const locale = require('../../locale');
const { confirm } = require('../../ui');
const { confirm } = require('../confirm');
const { deleteFormat, setPref } = require('../../data/actions');

module.exports = Vue.extend({
Expand Down
2 changes: 1 addition & 1 deletion src/editors/stylesheet/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
</p>

<div class="expand">
<code-mirror :options="cmOptions" :text="story.stylesheet" @cm-change="save" v-ref:codemirror></code-mirror>
<code-mirror :options="cmOptions" :text="source" @cm-change="save" v-ref:codemirror></code-mirror>
</div>
</modal-dialog>
4 changes: 4 additions & 0 deletions src/editors/stylesheet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ module.exports = Vue.extend({
vuex: {
actions: {
updateStory
},

getters: {
allStories: state => state.story.stories
}
}
});
2 changes: 2 additions & 0 deletions src/nw/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module.exports = {
return;
}

require('core-js');

const startupErrorTemplate = require('./startup-error.ejs');
let startupTask = 'beginning startup tasks';

Expand Down
10 changes: 10 additions & 0 deletions src/story-edit-view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ module.exports = Vue.extend({
}
},

watch: {
'story.name': {
handler(value) {
document.title = value;
},

immediate: true
}
},

ready() {
this.resize();
this.on(window, 'resize', this.resize);
Expand Down
2 changes: 1 addition & 1 deletion src/story-edit-view/passage-item/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
</p>
</div> <!-- .frame -->

<passage-menu v-if="needsMenu" :passage="passage"></passage-menu>
<passage-menu v-if="needsMenu" :passage="passage" :parent-story="parentStory"></passage-menu>
</div>
20 changes: 18 additions & 2 deletions src/story-edit-view/passage-item/passage-menu/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// A contextual menu that appears when the user points at a passage.

const Vue = require('vue');
const { updateStory } = require('../../../data/actions');

module.exports = Vue.extend({
template: require('./index.html'),
Expand All @@ -9,6 +10,11 @@ module.exports = Vue.extend({
passage: {
type: Object,
required: true
},

parentStory: {
type: Object,
required: true
}
},

Expand All @@ -22,15 +28,25 @@ module.exports = Vue.extend({
},

test() {
this.$dispatch('story-test', this.passage.id);
window.open(
'#stories/' + this.parentStory.id + '/test/' + this.passage.id,
'twinestory_test_' + this.parentStory.id
);
},

setAsStart() {
this.$dispatch('story-set-start', this.passage.id);
this.updateStory(
this.parentStory.id,
{ startPassage: this.passage.id }
);
}
},

components: {
'drop-down': require('../../../ui/drop-down')
},

vuex: {
actions: { updateStory }
}
});
2 changes: 1 addition & 1 deletion src/story-edit-view/story-toolbar/story-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = Vue.extend({
),
buttonLabel:
'<i class="fa fa-ok"></i> ' + locale.say('Rename'),
defaultText:
response:
this.story.name,
blankTextError:
locale.say('Please enter a name.')
Expand Down
7 changes: 7 additions & 0 deletions src/ui/file-drag-n-drop/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div :class="'drag-n-drop ' + (receiving ? 'receiving' : '')" @drop.prevent="fileReceived">
<div class="label">
<slot></slot>
</div>

<div class="inner-border"></div>
</div>
59 changes: 35 additions & 24 deletions src/ui/file-drag-n-drop/index.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,51 @@
/*
Manages a drag-and-drop-target on a component. When a file is dragged onto it,
this component dispatches a `file-drag-n-drop` event to its parent.
*/

const Vue = require('vue');
const { default: { on, off } } = require('oui-dom-events');
const domEvents = require('../../vue/mixins/dom-events');

module.exports = Vue.extend({
template:
`<div :class="'drag-n-drop ' + (dragover ? 'dragover' : '')">
<div class='label'>
<slot></slot>
</div>
<div class='inner-border'></div>
</div>`,
template: require('./index.html'),

data: () => ({
dragover: false,
/* Whether the user has a file dragged onto this component. */

receiving: false
}),

ready() {
const {$el, $parent:{$el:parentEl}} = this;
const parentEl = this.$parent.$el;

on(parentEl, 'dragenter.file-drag-n-drop', () => {
this.dragover = true;
});
/*
Make ourselves visible when the user drags a file onto us.
*/

on(parentEl, 'dragexit.file-drag-n-drop', () => {
this.dragover = false;
this.on(parentEl, 'dragenter', () => {
this.receiving = true;
});
// The below is necessary to prevent the browser from
// opening the file directly, on drop.
on(parentEl, 'dragover.file-drag-n-drop', e => {
e.preventDefault();

this.on(parentEl, 'dragexit', () => {
this.receiving = false;
});
on($el, 'drop', e => {

/*
The below is necessary to prevent the browser from opening the file
directly after the user drops a file on us.
*/

this.on(parentEl, 'dragover', e => {
e.preventDefault();
this.$dispatch('file-drag-n-drop', e.dataTransfer.files);
this.dragover = false;
});
},

beforeDestroy() {
off(this.$parent.$el, '.file-drag-n-drop');
methods: {
fileReceived(e) {
this.$dispatch('file-drag-n-drop', e.dataTransfer.files);
this.receiving = false;
}
},

mixins: [domEvents]
});
4 changes: 2 additions & 2 deletions src/ui/file-drag-n-drop/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

// Display a dotted rectangle overlay when dragging

&.dragover {
&.receiving {
z-index: 100; // In front of the UI.
background: fadeout(@color-darken, 20%);
color: @color-paper;
Expand All @@ -43,4 +43,4 @@
box-sizing: border-box;
}
}
}
}
Loading

0 comments on commit 44d4c28

Please sign in to comment.