Browse Source

cutomstyle générique + possibilité de styles imbriqués

master
choj 4 years ago
parent
commit
295c90508a
5 changed files with 116 additions and 120 deletions
  1. +13
    -15
      src/assets/dedediteur.css
  2. +34
    -27
      src/components/Dedediteur.vue
  3. +0
    -64
      src/components/extensions/CustomStyle.js
  4. +14
    -14
      src/environments/Environement.js
  5. +55
    -0
      src/extensions/CustomStyle.js

+ 13
- 15
src/assets/dedediteur.css View File

@@ -31,66 +31,66 @@ h1{


/* MOTS */ /* MOTS */
/*// — Mot - Accronyme*/ /*// — Mot - Accronyme*/
.acronym{
span[data-type=acronym]{
color: pink; color: pink;
} }
/*// — Mot - Etranger*/ /*// — Mot - Etranger*/
.foreign{
span[data-type=foreign]{
color: red; color: red;
} }


/* NOMS */ /* NOMS */
/*// — Nom - Auteur - Citation*/ /*// — Nom - Auteur - Citation*/
.author-quotation{
span[data-type=author-quotation]{
color : yellow; color : yellow;


} }
/*// — Nom - Auteur - Œuvre*/ /*// — Nom - Auteur - Œuvre*/
.author-work{
span[data-type=author-work]{
color: orange; color: orange;
} }
/*// — Nom - Marque*/ /*// — Nom - Marque*/
.brand{
span[data-type=brand]{
color: coral; color: coral;
} }


.work{
span[data-type=work]{
color: brown; color: brown;
} }
/*// — Nom - Propre*/ /*// — Nom - Propre*/


.proper-noun{
span[data-type=proper-noun]{
color: darkorange; color: darkorange;
} }


/* NOMBRES */ /* NOMBRES */
/*// — Numeral - Chapitre*/ /*// — Numeral - Chapitre*/
.chapter{
span[data-type=chapter]{
color: blue; color: blue;
} }
/*// — Numeral - Date*/ /*// — Numeral - Date*/
.date{
span[data-type=date]{
color: aqua; color: aqua;
} }
/*// — Numeral - Siecle*/ /*// — Numeral - Siecle*/
.century{
span[data-type=century]{
color: cornflowerblue; color: cornflowerblue;
} }


/*TYPO */ /*TYPO */
/*// — Typo - Exposant*/ /*// — Typo - Exposant*/
.superscript{
span[data-type=superscript]{
color: green; color: green;
font-variant-position: super; font-variant-position: super;
} }
/*// — Typo - Indice*/ /*// — Typo - Indice*/
.subscript{
span[data-type=subscript]{
color:chartreuse; color:chartreuse;
font-variant-position: sub; font-variant-position: sub;


} }


.emphasis{
span[data-type=emphasis]{
font-style: italic; font-style: italic;
} }


@@ -105,5 +105,3 @@ h1{
} }


} }



+ 34
- 27
src/components/Dedediteur.vue View File

@@ -67,8 +67,8 @@
<a v-for="style in opt.styles" v-bind:key="style.label"> <a v-for="style in opt.styles" v-bind:key="style.label">
<button <button
class="menubar__button" class="menubar__button"
:class="{ 'is-active': isActive.customstyle({ type: style.class }) }"
@click="commands.customstyle({ type: style.class })">
:class="{ 'is-active': isActive[style.type]() }"
@click="commands[style.type]({ type: style.type })">
{{style.label | capitalize}} {{style.label | capitalize}}
</button> </button>
</a> </a>
@@ -188,7 +188,7 @@
import AboutPane from './AboutPane'; import AboutPane from './AboutPane';


import Environment from "../environments/Environement" import Environment from "../environments/Environement"
import CustomStyle from "./extensions/CustomStyle"
import CustomStyle from "../extensions/CustomStyle"




export default { export default {
@@ -201,6 +201,8 @@
AboutPane AboutPane
}, },
data() { data() {


return { return {
nbWords: 0, nbWords: 0,
nbParagraphs: 0, nbParagraphs: 0,
@@ -213,29 +215,7 @@
isPreviewMode: false, isPreviewMode: false,
environment: new Environment(), environment: new Environment(),
keepInBounds: true, keepInBounds: true,
editor: new Editor({
extensions: [
new Blockquote(),
new BulletList(),
new Heading({levels: [1, 2, 3]}),
new ListItem(),
new OrderedList(),
new BulletList(),
new Link(),
new CustomStyle()
],
content: ``,

onInit: () => {
},
onUpdate: () => {

Countable.count(document.getElementById('dedediteur'), counter => this.updateCountInfos(counter), {stripTags: false});


}

}),
editor: null,
linkUrl: null, linkUrl: null,
linkMenuIsActive: false, linkMenuIsActive: false,
} }
@@ -249,7 +229,34 @@
fetch('/dedediteur/sample-mounier.html').then(function (response) { fetch('/dedediteur/sample-mounier.html').then(function (response) {
return response.text(); return response.text();
}).then(function (html) { }).then(function (html) {
self.editor.setContent(html);

let extensions = [
new Blockquote(),
new BulletList(),
new Heading({levels: [1, 2, 3]}),
new ListItem(),
new OrderedList(),
new BulletList(),
new Link()];

for(let i = 0; i < self.environment.getCharacterOptions().length; i++){
let styles = (self.environment.getCharacterOptions()[i]).styles
for(let j = 0; j < styles.length; j++){
extensions.push(new CustomStyle(styles[j].type));
}
}

self.editor = new Editor({
extensions: extensions,
content: html,
onInit: () => {
},
onUpdate: () => {
Countable.count(document.getElementById('dedediteur'), counter => self.updateCountInfos(counter), {stripTags: false});
}

}),

self.$nextTick().then(() => { self.$nextTick().then(() => {
Countable.count(document.getElementById('dedediteur'), counter => self.updateCountInfos(counter), {stripTags: false}) Countable.count(document.getElementById('dedediteur'), counter => self.updateCountInfos(counter), {stripTags: false})
}) })


+ 0
- 64
src/components/extensions/CustomStyle.js View File

@@ -1,64 +0,0 @@
import {Mark} from "tiptap";
import {updateMark} from "tiptap-commands";


// — Mot - Accronyme
// — Mot - Etranger

// — Nom - Auteur - Citation
// — Nom - Auteur - Œuvre
// — Nom - Marque
// — Nom - Propre

// — Numeral - Chapitre
// — Numeral - Date
// — Numeral - Siecle


// — Typo - Particulier
export default class CustomStyle extends Mark {
get name() {
return "customstyle";
}

get defaultOptions() {
return {
types: [
// "acronym",
// "foreign",
// "author-quotation",
// "author-work",
// "brand",
// "proper-noun",
// "century",
// "date",
// "chapter"
]
};
}

get schema() {
return {
attrs: {
type: {
default: ""
}
},
parseDOM: [
{
tag: "span.dede-style",
getAttrs(dom) {
return {type: dom.classList};
}
}
],
toDOM: mark => {
return ["span", {class: `dede-style ${mark.attrs.type}`}, 0];
}
};
}

commands({type}) {
return attrs => { return updateMark(type, attrs);}
}
}

+ 14
- 14
src/environments/Environement.js View File

@@ -25,37 +25,37 @@ export default class Environment {
styles: [ styles: [
{ {
"label": "étranger", "label": "étranger",
"class": "foreign"
"type": "foreign"
}, },
{ {
"label": "accronyme", "label": "accronyme",
"class": "acronym"
"type": "acronym"
} }
] ]
}, },
//
{ {
label: "nom", label: "nom",
styles: [ styles: [
{ {
"label": "Auteur - Citation", "label": "Auteur - Citation",
"class": "author-quotation"
"type": "author-quotation"
}, },
{ {
"label": "Auteur - Œuvre", "label": "Auteur - Œuvre",
"class": "author-work"
"type": "author-work"
}, },
{ {
"label": "Marque", "label": "Marque",
"class": "brand"
"type": "brand"
}, },
{ {
"label": "Nom œuvre", "label": "Nom œuvre",
"class": "work"
"type": "work"
}, },
{ {
"label": "Nom propre", "label": "Nom propre",
"class": "proper-noun"
"type": "proper-noun"
} }
] ]
}, },
@@ -65,15 +65,15 @@ export default class Environment {
styles: [ styles: [
{ {
"label": "siècle", "label": "siècle",
"class": "century"
"type": "century"
}, },
{ {
"label": "date", "label": "date",
"class": "date"
"type": "date"
}, },
{ {
"label": "chapitre", "label": "chapitre",
"class": "chapter"
"type": "chapter"
} }
] ]
}, },
@@ -82,15 +82,15 @@ export default class Environment {
styles: [ styles: [
{ {
"label": "italique", "label": "italique",
"class": "emphasis"
"type": "emphasis"
}, },
{ {
"label": "indice", "label": "indice",
"class": "subscript"
"type": "subscript"
}, },
{ {
"label": "exposant", "label": "exposant",
"class": "superscript"
"type": "superscript"
} }


] ]


+ 55
- 0
src/extensions/CustomStyle.js View File

@@ -0,0 +1,55 @@
import {Mark} from "tiptap";
import {toggleMark} from "tiptap-commands";


// — Mot - Accronyme
// — Mot - Etranger

// — Nom - Auteur - Citation
// — Nom - Auteur - Œuvre
// — Nom - Marque
// — Nom - Propre

// — Numeral - Chapitre
// — Numeral - Date
// — Numeral - Siecle


// — Typo - Particulier
export default class CustomStyle extends Mark {

constructor(type){
super();
this.customType = type;
}

get name() {
return this.customType;
}


get schema() {
return {
attrs: {
type: {
default: ""
}
},
parseDOM: [
{
tag: "span[data-type="+this.customType+"]",
getAttrs(dom) {
return {type: dom.dataset.type};
}
}
],
toDOM: () => {
return ["span", {'data-type': this.customType}, 0];
}
};
}

commands({type}) {
return attrs => { return toggleMark(type, attrs);}
}
}

Loading…
Cancel
Save