Simple text editor based on tiptap. HTML format.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

165 lines
4.4 KiB

  1. const defaultEnvName = "typobasic";
  2. export default class Environment {
  3. constructor(options = {}) {
  4. this.name = options.name ? options.name : defaultEnvName;
  5. this.defaultOptions = {
  6. paragraphs: {
  7. T1: true,
  8. T2: true,
  9. T3: true,
  10. T4: true,
  11. quote: true,
  12. ul: true,
  13. ol: true
  14. },
  15. characters: [
  16. {
  17. label: "Mot",
  18. styles: [
  19. {
  20. "label": "étranger",
  21. "type": "foreign"
  22. },
  23. {
  24. "label": "accronyme",
  25. "type": "acronym"
  26. }
  27. ]
  28. },
  29. //
  30. {
  31. label: "nom",
  32. styles: [
  33. {
  34. "label": "Auteur - Citation",
  35. "type": "author-quotation"
  36. },
  37. {
  38. "label": "Auteur - Œuvre",
  39. "type": "author-work"
  40. },
  41. {
  42. "label": "Marque",
  43. "type": "brand"
  44. },
  45. {
  46. "label": "Nom œuvre",
  47. "type": "work"
  48. },
  49. {
  50. "label": "Nom propre",
  51. "type": "proper-noun"
  52. }
  53. ]
  54. },
  55. {
  56. label: "numéral",
  57. styles: [
  58. {
  59. "label": "siècle",
  60. "type": "century"
  61. },
  62. {
  63. "label": "date",
  64. "type": "date"
  65. },
  66. {
  67. "label": "chapitre",
  68. "type": "chapter"
  69. }
  70. ]
  71. },
  72. {
  73. label: "typo",
  74. styles: [
  75. {
  76. "label": "emphase",
  77. "type": "emphasis"
  78. },
  79. {
  80. "label": "indice",
  81. "type": "subscript"
  82. },
  83. {
  84. "label": "exposant",
  85. "type": "superscript"
  86. }
  87. ]
  88. }
  89. ],
  90. };
  91. this.setOptions({
  92. ...this.defaultOptions,
  93. ...options,
  94. })
  95. }
  96. setOptions(options) {
  97. this.options = {
  98. ...this.options,
  99. ...options,
  100. }
  101. }
  102. hasParagraphOption(optionKey) {
  103. return this.options.paragraphs[optionKey] | false;
  104. }
  105. getCharacterOptions() {
  106. return this.options.characters;
  107. }
  108. async getTemplate(){
  109. let template = await fetch('/dedediteur/env/' + this.name + '/template.html').catch(() => null);
  110. if(template){
  111. let html = await template.text();
  112. return html;
  113. }
  114. return null;
  115. }
  116. async getStyleSheetPath(){
  117. let css = await fetch('/dedediteur/env/' + this.name + '/' + this.name +'.css').catch(() => null);
  118. if(css)
  119. return '/dedediteur/env/' + this.name + '/' + this.name +'.css';
  120. return null
  121. }
  122. static async getEnvironment(envName) {
  123. if (envName === defaultEnvName)
  124. return new Environment();
  125. else
  126. return Environment.getEnvironmentFromJSONFile('/dedediteur/env/' + envName + '/'+envName+ '.json')
  127. }
  128. static async getEnvironmentFromJSONFile(filePath) {
  129. let res = await fetch(filePath);
  130. let json = await res.json().catch(() => null);
  131. return json ? Environment.getEnvironmentFromJSON(json) : null;
  132. }
  133. static getEnvironmentFromJSON(json) {
  134. return new Environment(json);
  135. }
  136. }