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

feat: add possibility to write the filename per editor #52

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
29 changes: 25 additions & 4 deletions components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
class="flex items-center justify-between w-full overflow-auto bg-ui-gray-700"
>
<div
class="flex items-center gap-2 m-2 rounded-lg bg-ui-gray-800 focus-within:ring-2 focus-within:ring-ui-focus"
class="flex items-center gap-2 m-2 rounded-lg bg-ui-gray-800 focus-within:ring-2 focus-within:ring-ui-focus"
>
<label
class="hidden pl-2 text-xs font-semibold leading-none tracking-wide uppercase text-ui-gray-500 xl:inline-block whitespace-nowrap"
class="hidden pl-2 text-xs font-semibold leading-none tracking-wide uppercase text-ui-gray-500 xl:inline-block whitespace-nowrap"
>
Lang
</label>
Expand All @@ -24,10 +24,10 @@

<div class="flex items-stretch gap-2">
<div
class="flex items-center gap-2 mr-2 rounded-lg bg-ui-gray-800 focus-within:ring-2 focus-within:ring-ui-focus lg:mr-0"
class="flex items-center gap-2 mr-2 rounded-lg bg-ui-gray-800 focus-within:ring-2 focus-within:ring-ui-focus lg:mr-0"
>
<label
class="hidden pl-2 text-xs font-semibold leading-none tracking-wide uppercase text-ui-gray-500 xl:inline-block whitespace-nowrap"
class="hidden pl-2 text-xs font-semibold leading-none tracking-wide uppercase text-ui-gray-500 xl:inline-block whitespace-nowrap"
>
Tab Size
</label>
Expand Down Expand Up @@ -113,6 +113,25 @@
</div>
</div>

<div v-if="allowFilename" class="flex items-center justify-between bg-ui-gray-700">
<div
class="flex items-center w-full gap-2 m-2 mt-0 rounded-lg bg-ui-gray-800 focus-within:ring-2 focus-within:ring-ui-focus"
>
<label
class="hidden pl-2 text-xs font-semibold leading-none tracking-wide uppercase text-ui-gray-500 xl:inline-block whitespace-nowrap"
>
Filename
</label>

<input
type="text"
:value="filename"
@input="(event) => $emit('update:filename', event.target.value)"
class="w-full text-xs font-medium border-0 rounded-lg cursor-pointer text-ui-gray-400 bg-ui-gray-800 hover:bg-ui-gray-900 focus:bg-ui-gray-900 focus:outline-none focus:ring-0"
/>
</div>
</div>

<div ref="container" class="w-full h-full">
<Monaco
class="w-full h-full"
Expand Down Expand Up @@ -148,6 +167,8 @@ export default {
value: String,
size: Number,
tabSize: [String, Number],
filename: String,
allowFilename: Boolean,
language: String,
options: Object,
landscape: Boolean,
Expand Down
9 changes: 9 additions & 0 deletions components/Page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
:size="sizes[0]"
:tab-size="editor.tabSize"
:language="editor.language"
:filename="editor.filename"
:allow-filename="editors.length > 1"
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of a separate prop for allow-filename, can we use a ternary condition to simply pass in null in the filename prop? For example:

<Editor
  :filename="editors.length > 1 ? editor.filename : null"
/>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I remember why. If I do not use allow-filename, I don't know when I can allow writing the filename or not. For example, inside Editor.vue in the v-if="allowFilename", we need to know how much Editors are using to allow set the filename or not. With this :filename="editors.length > 1 ? editor.filename : null", the filename always is allowed to set but, when just exists one Editor, the filename field is visible, but not visible in the render. Do you know what I mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I can do something like canSetFilename

:landscape="isLandscape"
:can-move-up="index !== 0"
:can-move-down="index !== editors.length - 1"
Expand All @@ -37,13 +39,15 @@
@update:layout="toggleLayout"
@update:tab-size="(size) => (editors[index].tabSize = size)"
@update:language="(lang) => (editors[index].language = lang)"
@update:filename="(filename) => (editors[index].filename = filename)"
/>
</div>

<Preview
dusk="preview"
ref="preview"
:tab="tab"
:filenames="filenames"
:code="code"
:languages="languages"
class="flex flex-col justify-between w-full h-full overflow-auto"
Expand Down Expand Up @@ -140,6 +144,10 @@ export default {
}));
},

filenames() {
return this.editors.map(({ filename }) => filename);
},

canRemoveEditor() {
return this.editors.length > 1;
},
Expand Down Expand Up @@ -233,6 +241,7 @@ export default {
id: uuid(),
tabSize: 4,
language: language,
filename: '',
value: language === 'php' ? '<?php\n\n' : '',
};
},
Expand Down
2 changes: 2 additions & 0 deletions components/Preview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
class="z-10"
:blocks="blocks"
:settings="settings"
:filenames="filenames"
@update:title="(title) => (settings.title = title)"
/>

Expand Down Expand Up @@ -366,6 +367,7 @@ export default {
props: {
tab: Object,
code: Array,
filenames: Array,
languages: Array,
},

Expand Down
7 changes: 6 additions & 1 deletion components/Window.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
type="text"
ref="title"
v-model="title"
class="w-full p-0 text-sm font-medium text-center truncate bg-transparent border-0 shadow-none focus:ring-0"
class="w-full p-0 text-sm font-medium text-center truncate bg-transparent border-0 shadow-none focus:ring-0"
@blur="editingTitle = false"
/>

Expand All @@ -45,6 +45,10 @@
:key="index"
:style="{ padding: `${settings.padding}px` }"
>
<div v-if="filenames.length > 1" class="mb-2 text-sm text-right text-gray-400">
{{ filenames[index] }}
</div>

<Code
class="relative"
:lines="lines"
Expand All @@ -63,6 +67,7 @@ export default {
props: {
blocks: Array,
settings: Object,
filenames: Array,
},

components: { Code, FauxMenu },
Expand Down