@lblod/ember-rdfa-editor-lblod-plugins 0.4.1 → 1.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/addon/commands/article-structure-plugin/delete-structure.ts +85 -0
  3. package/addon/commands/article-structure-plugin/index.ts +4 -0
  4. package/addon/commands/article-structure-plugin/insert-article-structure.ts +137 -0
  5. package/addon/commands/article-structure-plugin/move-structure.ts +227 -0
  6. package/addon/commands/article-structure-plugin/recalculate-structure-numbers.ts +88 -0
  7. package/addon/commands/besluit-plugin/get-article-nodes-for-besluit.ts +30 -0
  8. package/addon/commands/besluit-plugin/index.ts +4 -0
  9. package/addon/commands/besluit-plugin/insert-article.ts +94 -0
  10. package/addon/commands/besluit-plugin/insert-title.ts +67 -0
  11. package/addon/commands/besluit-plugin/move-article.ts +69 -0
  12. package/addon/commands/besluit-plugin/recalculate-article-numbers.ts +44 -0
  13. package/addon/commands/modify-date-command.ts +48 -0
  14. package/addon/components/article-structure-plugin/article-structure-card.hbs +14 -0
  15. package/addon/components/article-structure-plugin/article-structure-card.ts +83 -0
  16. package/addon/components/article-structure-plugin/structure-card.hbs +42 -0
  17. package/addon/components/article-structure-plugin/structure-card.ts +140 -0
  18. package/addon/components/au-native-input.hbs +30 -0
  19. package/addon/components/au-native-input.ts +47 -0
  20. package/addon/components/besluit-plugin/besluit-context-card.hbs +44 -0
  21. package/addon/components/besluit-plugin/besluit-context-card.ts +144 -0
  22. package/addon/components/besluit-plugin/besluit-plugin-card.hbs +20 -0
  23. package/addon/components/besluit-plugin/besluit-plugin-card.ts +42 -0
  24. package/addon/components/besluit-type-plugin/{besluit-type-select.js → besluit-type-select.ts} +9 -4
  25. package/addon/components/besluit-type-plugin/toolbar-dropdown.hbs +2 -0
  26. package/addon/components/besluit-type-plugin/toolbar-dropdown.ts +216 -0
  27. package/addon/components/citation-plugin/citation-card.hbs +118 -0
  28. package/addon/components/citation-plugin/citation-card.ts +230 -0
  29. package/addon/components/citation-plugin/citation-insert.hbs +20 -0
  30. package/addon/components/citation-plugin/citation-insert.ts +102 -0
  31. package/addon/components/{citaten-plugin → citation-plugin}/citations/article-list.hbs +2 -2
  32. package/addon/components/{citaten-plugin → citation-plugin}/citations/article-preview.hbs +0 -0
  33. package/addon/components/{citaten-plugin → citation-plugin}/citations/decision-detail.hbs +9 -6
  34. package/addon/components/{citaten-plugin/citations/decision-detail.js → citation-plugin/citations/decision-detail.ts} +30 -31
  35. package/addon/components/{citaten-plugin → citation-plugin}/citations/decision-list.hbs +2 -2
  36. package/addon/components/{citaten-plugin → citation-plugin}/citations/decision-preview.hbs +0 -0
  37. package/addon/components/citation-plugin/citations/search-modal.hbs +254 -0
  38. package/addon/components/{citaten-plugin/citations/search-modal.js → citation-plugin/citations/search-modal.ts} +116 -89
  39. package/addon/components/{citaten-plugin → citation-plugin}/helpers/alert-load-error.hbs +0 -0
  40. package/addon/components/{citaten-plugin → citation-plugin}/helpers/alert-no-items.hbs +0 -0
  41. package/addon/components/import-snippet-plugin/card.ts +119 -0
  42. package/addon/components/insert-variable-plugin/insert-variable-card.hbs +2 -1
  43. package/addon/components/insert-variable-plugin/insert-variable-card.ts +134 -0
  44. package/addon/components/rdfa-date-plugin/{rdfa-date-plugin-card.hbs → card.hbs} +3 -1
  45. package/addon/components/rdfa-date-plugin/card.ts +72 -0
  46. package/addon/components/rdfa-date-plugin/{rdfa-date-time-picker.hbs → date-time-picker.hbs} +0 -0
  47. package/addon/components/rdfa-date-plugin/{rdfa-date-time-picker.js → date-time-picker.ts} +26 -12
  48. package/addon/components/rdfa-date-plugin/{rdfa-date-plugin-insert.hbs → insert.hbs} +0 -0
  49. package/addon/components/rdfa-date-plugin/insert.ts +44 -0
  50. package/addon/components/roadsign-regulation-plugin/expanded-measure.ts +58 -0
  51. package/addon/components/roadsign-regulation-plugin/measure-template.ts +35 -0
  52. package/addon/components/roadsign-regulation-plugin/roadsign-regulation-card.hbs +2 -2
  53. package/addon/components/roadsign-regulation-plugin/roadsign-regulation-card.ts +60 -0
  54. package/addon/components/roadsign-regulation-plugin/{roadsigns-modal.js → roadsigns-modal.ts} +101 -64
  55. package/addon/components/roadsign-regulation-plugin/{roadsigns-pagination.js → roadsigns-pagination.ts} +7 -3
  56. package/addon/components/roadsign-regulation-plugin/roadsigns-table.ts +32 -0
  57. package/addon/components/standard-template-plugin/{template-card.hbs → card.hbs} +0 -0
  58. package/addon/components/standard-template-plugin/card.ts +11 -0
  59. package/addon/components/standard-template-plugin/template-provider.hbs +3 -1
  60. package/addon/components/standard-template-plugin/template-provider.ts +75 -0
  61. package/addon/components/table-of-contents-plugin/card.hbs +12 -1
  62. package/addon/components/table-of-contents-plugin/card.ts +60 -0
  63. package/addon/components/table-of-contents-plugin/{inline-components → ember-nodes}/outline.hbs +2 -2
  64. package/addon/components/table-of-contents-plugin/ember-nodes/table-of-contents.hbs +9 -0
  65. package/addon/components/table-of-contents-plugin/ember-nodes/table-of-contents.ts +95 -0
  66. package/addon/components/template-variable-plugin/template-variable-card.hbs +2 -1
  67. package/addon/components/template-variable-plugin/template-variable-card.ts +227 -0
  68. package/addon/{constants.js → constants.ts} +15 -3
  69. package/addon/ember-nodes/table-of-contents.ts +53 -0
  70. package/addon/helpers/{limit-text.js → limit-text.ts} +2 -2
  71. package/addon/initializers/plugin-initializer.js +0 -75
  72. package/addon/models/instruction.ts +18 -0
  73. package/addon/models/measure.ts +38 -0
  74. package/addon/models/sign.ts +36 -0
  75. package/addon/models/template.ts +14 -0
  76. package/addon/plugins/article-structure-plugin.ts +55 -0
  77. package/addon/plugins/besluit-plugin.ts +27 -0
  78. package/addon/plugins/besluit-type-plugin.ts +6 -0
  79. package/addon/plugins/citation-plugin/index.ts +216 -0
  80. package/addon/plugins/citation-plugin/marks/citation.ts +27 -0
  81. package/addon/plugins/citation-plugin/utils/cited-text.ts +17 -0
  82. package/addon/plugins/citation-plugin/utils/process-match.ts +135 -0
  83. package/addon/{utils/vlaamse-codex.js → plugins/citation-plugin/utils/vlaamse-codex.ts} +161 -42
  84. package/addon/plugins/import-snippet-plugin.ts +6 -0
  85. package/addon/plugins/insert-variable-plugin.ts +11 -0
  86. package/addon/plugins/rdfa-date-plugin.ts +11 -0
  87. package/addon/plugins/roadsign-regulation-plugin.ts +6 -0
  88. package/addon/plugins/standard-template-plugin.ts +6 -0
  89. package/addon/plugins/table-of-contents-plugin.ts +14 -0
  90. package/addon/plugins/template-variable-plugin.ts +6 -0
  91. package/addon/services/{import-rdfa-snippet.js → import-rdfa-snippet.ts} +48 -36
  92. package/addon/services/roadsign-registry.ts +288 -0
  93. package/addon/services/{standard-template-plugin.js → standard-template-plugin.ts} +17 -11
  94. package/addon/utils/article-structure-plugin/constants.ts +260 -0
  95. package/addon/utils/article-structure-plugin/defaults.ts +3 -0
  96. package/addon/utils/article-structure-plugin/options-with-defaults.ts +31 -0
  97. package/addon/utils/article-structure-plugin/validate-datastore.ts +23 -0
  98. package/addon/utils/besluit-plugin/get-title-for-decision.ts +35 -0
  99. package/addon/utils/{fetchBesluitTypes.js → fetchBesluitTypes.ts} +36 -16
  100. package/addon/utils/generate-template-plugin/{default-resources.js → default-resources.ts} +0 -0
  101. package/addon/utils/{instantiate-uuids.js → instantiate-uuids.ts} +9 -6
  102. package/addon/utils/{legislation-types.js → legislation-types.ts} +17 -3
  103. package/addon/utils/{memoize.js → memoize.ts} +4 -2
  104. package/addon/utils/option.ts +58 -0
  105. package/addon/utils/roadsign-regulation-plugin/{fetchData.js → fetchData.ts} +19 -2
  106. package/addon/utils/roadsign-regulation-plugin/includeInstructions.ts +16 -0
  107. package/addon/utils/romanize.ts +47 -0
  108. package/addon/utils/variable-plugins/{default-variable-types.js → default-variable-types.ts} +18 -7
  109. package/addon/utils/variable-plugins/{fetch-data.js → fetch-data.ts} +43 -15
  110. package/app/components/article-structure-plugin/article-structure-card.js +1 -0
  111. package/app/components/article-structure-plugin/structure-card.js +1 -0
  112. package/app/components/{citaten-plugin/citaat-card.js → au-native-input.js} +1 -1
  113. package/app/components/{citaten-plugin/citations/article-list.js → besluit-plugin/besluit-context-card.js} +1 -1
  114. package/app/components/besluit-plugin/besluit-plugin-card.js +1 -0
  115. package/app/components/{citaten-plugin/citations/modal.js → citation-plugin/citation-card.js} +1 -1
  116. package/app/components/citation-plugin/citation-insert.js +1 -0
  117. package/app/components/{citaten-plugin/citations/decision-list.js → citation-plugin/citations/article-list.js} +1 -1
  118. package/app/components/{citaten-plugin → citation-plugin}/citations/article-preview.js +1 -1
  119. package/app/components/{citaten-plugin → citation-plugin}/citations/decision-detail.js +1 -1
  120. package/app/components/citation-plugin/citations/decision-list.js +1 -0
  121. package/app/components/{citaten-plugin → citation-plugin}/citations/decision-preview.js +1 -1
  122. package/app/components/citation-plugin/citations/modal.js +1 -0
  123. package/app/components/{citaten-plugin → citation-plugin}/citations/search-modal.js +1 -1
  124. package/app/components/{citaten-plugin → citation-plugin}/helpers/alert-load-error.js +1 -1
  125. package/app/components/{citaten-plugin → citation-plugin}/helpers/alert-no-items.js +1 -1
  126. package/app/components/{citaten-plugin/citaat-insert.js → rdfa-date-plugin/card.js} +1 -1
  127. package/app/components/rdfa-date-plugin/date-time-picker.js +1 -0
  128. package/app/components/rdfa-date-plugin/insert.js +1 -0
  129. package/app/components/standard-template-plugin/card.js +1 -0
  130. package/app/components/table-of-contents-plugin/ember-nodes/outline.js +1 -0
  131. package/app/components/table-of-contents-plugin/ember-nodes/table-of-contents.js +1 -0
  132. package/app/styles/citaten-plugin.scss +1 -1
  133. package/commands/article-structure-plugin/delete-structure.d.ts +4 -0
  134. package/commands/article-structure-plugin/index.d.ts +4 -0
  135. package/commands/article-structure-plugin/insert-article-structure.d.ts +6 -0
  136. package/commands/article-structure-plugin/move-structure.d.ts +5 -0
  137. package/commands/article-structure-plugin/recalculate-structure-numbers.d.ts +7 -0
  138. package/commands/besluit-plugin/get-article-nodes-for-besluit.d.ts +5 -0
  139. package/commands/besluit-plugin/index.d.ts +4 -0
  140. package/commands/besluit-plugin/insert-article.d.ts +3 -0
  141. package/commands/besluit-plugin/insert-title.d.ts +2 -0
  142. package/commands/besluit-plugin/move-article.d.ts +2 -0
  143. package/commands/besluit-plugin/recalculate-article-numbers.d.ts +2 -0
  144. package/commands/modify-date-command.d.ts +2 -0
  145. package/components/article-structure-plugin/article-structure-card.d.ts +36 -0
  146. package/components/article-structure-plugin/structure-card.d.ts +23 -0
  147. package/components/au-native-input.d.ts +20 -0
  148. package/components/besluit-plugin/besluit-context-card.d.ts +29 -0
  149. package/components/besluit-plugin/besluit-plugin-card.d.ts +14 -0
  150. package/components/besluit-type-plugin/besluit-type-select.d.ts +11 -0
  151. package/components/besluit-type-plugin/toolbar-dropdown.d.ts +46 -0
  152. package/components/citation-plugin/citation-card.d.ts +51 -0
  153. package/components/citation-plugin/citation-insert.d.ts +24 -0
  154. package/components/citation-plugin/citations/decision-detail.d.ts +26 -0
  155. package/components/citation-plugin/citations/search-modal.d.ts +67 -0
  156. package/components/import-snippet-plugin/card.d.ts +19 -0
  157. package/components/insert-variable-plugin/insert-variable-card.d.ts +31 -0
  158. package/components/rdfa-date-plugin/card.d.ts +20 -0
  159. package/components/rdfa-date-plugin/date-time-picker.d.ts +32 -0
  160. package/components/rdfa-date-plugin/insert.d.ts +12 -0
  161. package/components/roadsign-regulation-plugin/expanded-measure.d.ts +20 -0
  162. package/components/roadsign-regulation-plugin/measure-template.d.ts +14 -0
  163. package/components/roadsign-regulation-plugin/roadsign-regulation-card.d.ts +12 -0
  164. package/components/roadsign-regulation-plugin/roadsigns-modal.d.ts +57 -0
  165. package/components/roadsign-regulation-plugin/roadsigns-pagination.d.ts +19 -0
  166. package/components/roadsign-regulation-plugin/roadsigns-table.d.ts +9 -0
  167. package/components/standard-template-plugin/card.d.ts +9 -0
  168. package/components/standard-template-plugin/template-provider.d.ts +17 -0
  169. package/components/table-of-contents-plugin/card.d.ts +20 -0
  170. package/components/table-of-contents-plugin/ember-nodes/table-of-contents.d.ts +22 -0
  171. package/components/template-variable-plugin/template-variable-card.d.ts +27 -0
  172. package/constants.d.ts +11 -0
  173. package/ember-nodes/table-of-contents.d.ts +4 -0
  174. package/helpers/limit-text.d.ts +8 -0
  175. package/index.js +5 -0
  176. package/models/instruction.d.ts +8 -0
  177. package/models/measure.d.ts +14 -0
  178. package/models/sign.d.ts +12 -0
  179. package/models/template.d.ts +13 -0
  180. package/package.json +27 -8
  181. package/plugins/article-structure-plugin.d.ts +29 -0
  182. package/plugins/besluit-plugin.d.ts +9 -0
  183. package/plugins/besluit-type-plugin.d.ts +2 -0
  184. package/plugins/citation-plugin/index.d.ts +31 -0
  185. package/plugins/citation-plugin/marks/citation.d.ts +2 -0
  186. package/plugins/citation-plugin/utils/cited-text.d.ts +3 -0
  187. package/plugins/citation-plugin/utils/process-match.d.ts +23 -0
  188. package/plugins/citation-plugin/utils/vlaamse-codex.d.ts +56 -0
  189. package/plugins/import-snippet-plugin.d.ts +2 -0
  190. package/plugins/insert-variable-plugin.d.ts +2 -0
  191. package/plugins/rdfa-date-plugin.d.ts +3 -0
  192. package/plugins/roadsign-regulation-plugin.d.ts +2 -0
  193. package/plugins/standard-template-plugin.d.ts +2 -0
  194. package/plugins/table-of-contents-plugin.d.ts +3 -0
  195. package/plugins/template-variable-plugin.d.ts +2 -0
  196. package/services/import-rdfa-snippet.d.ts +99 -0
  197. package/services/roadsign-registry.d.ts +42 -0
  198. package/services/standard-template-plugin.d.ts +21 -0
  199. package/translations/en-US.yaml +47 -1
  200. package/translations/nl-BE.yaml +49 -3
  201. package/tsconfig.json +34 -9
  202. package/types/config/environment.d.ts +22 -0
  203. package/types/ember-mu-transform-helpers/transforms/string-set.d.ts +14 -0
  204. package/types/lblod/frontend-gelinkt-notuleren/models/account.d.ts +10 -0
  205. package/types/lblod/frontend-gelinkt-notuleren/models/bestuurseenheid-classificatie-code.d.ts +10 -0
  206. package/types/lblod/frontend-gelinkt-notuleren/models/bestuurseenheid.d.ts +12 -0
  207. package/types/lblod/frontend-gelinkt-notuleren/models/gebruiker-model.d.ts +18 -0
  208. package/types/lblod/frontend-gelinkt-notuleren/services/current-session.d.ts +30 -0
  209. package/types/lblod/marawa/dom-helpers.d.ts +4 -0
  210. package/types/lblod/marawa/ember-object-mock.d.ts +3 -0
  211. package/types/lblod/marawa/node-walker.d.ts +18 -0
  212. package/types/lblod/marawa/range-helpers.d.ts +10 -0
  213. package/types/lblod/marawa/rdfa-attributes.d.ts +25 -0
  214. package/types/lblod/marawa/rdfa-block.d.ts +22 -0
  215. package/types/lblod/marawa/rdfa-context-scanner.d.ts +13 -0
  216. package/types/lblod/marawa/rdfa-helpers.d.ts +22 -0
  217. package/types/lblod/marawa/rich-node.d.ts +50 -0
  218. package/types/lblod/marawa/triple.d.ts +16 -0
  219. package/utils/article-structure-plugin/constants.d.ts +2 -0
  220. package/utils/article-structure-plugin/defaults.d.ts +4 -0
  221. package/utils/article-structure-plugin/options-with-defaults.d.ts +2 -0
  222. package/utils/article-structure-plugin/validate-datastore.d.ts +3 -0
  223. package/utils/besluit-plugin/get-title-for-decision.d.ts +10 -0
  224. package/utils/fetchBesluitTypes.d.ts +12 -0
  225. package/utils/generate-template-plugin/default-resources.d.ts +2 -0
  226. package/utils/instantiate-uuids.d.ts +1 -0
  227. package/utils/legislation-types.d.ts +24 -0
  228. package/utils/memoize.d.ts +1 -0
  229. package/utils/option.d.ts +14 -0
  230. package/utils/roadsign-regulation-plugin/fetchData.d.ts +8 -0
  231. package/utils/roadsign-regulation-plugin/includeInstructions.d.ts +2 -0
  232. package/utils/romanize.d.ts +2 -0
  233. package/utils/variable-plugins/default-variable-types.d.ts +7 -0
  234. package/utils/variable-plugins/fetch-data.d.ts +14 -0
  235. package/addon/commands/generate-template-command.js +0 -35
  236. package/addon/commands/insert-and-collapse.js +0 -32
  237. package/addon/commands/modify-date-command.js +0 -42
  238. package/addon/components/besluit-type-plugin/toolbar-dropdown.js +0 -188
  239. package/addon/components/citaten-plugin/citaat-card.hbs +0 -76
  240. package/addon/components/citaten-plugin/citaat-card.js +0 -286
  241. package/addon/components/citaten-plugin/citaat-insert.hbs +0 -20
  242. package/addon/components/citaten-plugin/citaat-insert.js +0 -68
  243. package/addon/components/citaten-plugin/citations/search-modal.hbs +0 -175
  244. package/addon/components/import-snippet-plugin/card.js +0 -95
  245. package/addon/components/insert-variable-plugin/insert-variable-card.js +0 -125
  246. package/addon/components/rdfa-date-plugin/rdfa-date-plugin-card.js +0 -71
  247. package/addon/components/rdfa-date-plugin/rdfa-date-plugin-insert.js +0 -24
  248. package/addon/components/roadsign-regulation-plugin/expanded-measure.js +0 -38
  249. package/addon/components/roadsign-regulation-plugin/measure-template.js +0 -30
  250. package/addon/components/roadsign-regulation-plugin/roadsign-regulation-card.js +0 -101
  251. package/addon/components/roadsign-regulation-plugin/roadsigns-table.js +0 -24
  252. package/addon/components/standard-template-plugin/template-card.js +0 -7
  253. package/addon/components/standard-template-plugin/template-provider.js +0 -75
  254. package/addon/components/table-of-contents-plugin/card.js +0 -53
  255. package/addon/components/table-of-contents-plugin/inline-components/table-of-contents.hbs +0 -9
  256. package/addon/components/table-of-contents-plugin/inline-components/table-of-contents.js +0 -100
  257. package/addon/components/template-variable-plugin/template-variable-card.js +0 -230
  258. package/addon/inline-components/table-of-contents.js +0 -43
  259. package/addon/models/instruction.js +0 -19
  260. package/addon/models/measure.js +0 -46
  261. package/addon/models/sign.js +0 -37
  262. package/addon/models/template.js +0 -9
  263. package/addon/plugins/besluit-type-plugin.js +0 -16
  264. package/addon/plugins/citaten-plugin.js +0 -22
  265. package/addon/plugins/import-snippet-plugin.js +0 -16
  266. package/addon/plugins/insert-variable-plugin.js +0 -19
  267. package/addon/plugins/rdfa-date-plugin.js +0 -26
  268. package/addon/plugins/roadsign-regulation-plugin.js +0 -24
  269. package/addon/plugins/standard-template-plugin.js +0 -33
  270. package/addon/plugins/table-of-contents-plugin.js +0 -27
  271. package/addon/plugins/template-variable-plugin.js +0 -21
  272. package/addon/services/roadsign-registry.js +0 -240
  273. package/addon/utils/processMatch.js +0 -80
  274. package/addon/utils/roadsign-regulation-plugin/includeInstructions.js +0 -10
  275. package/app/components/rdfa-date-plugin/rdfa-date-plugin-card.js +0 -1
  276. package/app/components/rdfa-date-plugin/rdfa-date-plugin-insert.js +0 -1
  277. package/app/components/rdfa-date-plugin/rdfa-date-time-picker.js +0 -1
  278. package/app/components/standard-template-plugin/template-card.js +0 -1
  279. package/app/components/table-of-contents-plugin/inline-components/outline.js +0 -1
  280. package/app/components/table-of-contents-plugin/inline-components/table-of-contents.js +0 -1
  281. package/app/initializers/plugin-initializer.js +0 -4
  282. package/types/dummy/index.d.ts +0 -1
  283. package/types/ember-data/types/registries/model.d.ts +0 -6
@@ -0,0 +1,288 @@
1
+ import Service from '@ember/service';
2
+ import { task, timeout } from 'ember-concurrency';
3
+ import { tracked } from '@glimmer/tracking';
4
+ import { getOwner } from '@ember/application';
5
+ import { generateMeasuresQuery } from '../utils/roadsign-regulation-plugin/fetchData';
6
+ import Instruction from '../models/instruction';
7
+ import Measure from '../models/measure';
8
+ import Sign from '../models/sign';
9
+ import { IBindings } from 'fetch-sparql-endpoint';
10
+ import { optionMapOr, unwrap } from '@lblod/ember-rdfa-editor/utils/option';
11
+ import dataFactory from '@rdfjs/data-model';
12
+
13
+ const PREFIXES = `
14
+ PREFIX ex: <http://example.org#>
15
+ PREFIX lblodMobiliteit: <http://data.lblod.info/vocabularies/mobiliteit/>
16
+ PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>
17
+ PREFIX sh: <http://www.w3.org/ns/shacl#>
18
+ PREFIX oslo: <http://data.vlaanderen.be/ns#>
19
+ PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
20
+ PREFIX org: <http://www.w3.org/ns/org#>
21
+ PREFIX mobiliteit: <https://data.vlaanderen.be/ns/mobiliteit#>
22
+ `;
23
+
24
+ const DEBOUNCE_MS = 100;
25
+
26
+ export default class RoadsignRegistryService extends Service {
27
+ @tracked classifications: { value: string; label: string }[] = [];
28
+ instructions: Map<string, Instruction[]> = new Map();
29
+ endpoint: string;
30
+ imageBaseUrl: string;
31
+
32
+ constructor() {
33
+ // eslint-disable-next-line prefer-rest-params
34
+ super(...arguments);
35
+ const config = getOwner(this).resolveRegistration('config:environment') as {
36
+ roadsignRegulationPlugin: {
37
+ imageBaseUrl: string;
38
+ endpoint: string;
39
+ };
40
+ };
41
+ this.imageBaseUrl = config.roadsignRegulationPlugin.imageBaseUrl;
42
+ this.endpoint = config.roadsignRegulationPlugin.endpoint;
43
+ void this.loadClassifications.perform();
44
+ }
45
+
46
+ loadClassifications = task(async () => {
47
+ const result = await this.executeQuery.perform(`
48
+ SELECT DISTINCT ?classificationUri ?classificationLabel WHERE {
49
+ ?measure ext:relation/ext:concept ?signUri.
50
+ ?signUri org:classification ?classificationUri.
51
+ ?classificationUri a mobiliteit:Verkeersbordcategorie;
52
+ skos:prefLabel ?classificationLabel.
53
+ }
54
+ `);
55
+ const bindings = result.results.bindings;
56
+ this.classifications = bindings.map((binding) => ({
57
+ value: unwrap(binding['classificationUri']?.value),
58
+ label: unwrap(binding['classificationLabel']?.value),
59
+ }));
60
+ });
61
+
62
+ getInstructionsForMeasure = task(
63
+ async (uri: string): Promise<Instruction[]> => {
64
+ if (this.instructions.has(uri)) {
65
+ return unwrap(this.instructions.get(uri));
66
+ } else {
67
+ const instructions = await this.fetchInstructionsForMeasure.perform(
68
+ uri
69
+ );
70
+ this.instructions.set(uri, instructions);
71
+ return instructions;
72
+ }
73
+ }
74
+ );
75
+
76
+ searchCode = task(
77
+ { restartable: true },
78
+ async (
79
+ codeString?: string,
80
+ category?: string,
81
+ type?: string,
82
+ combinedSigns?: string[]
83
+ ) => {
84
+ await timeout(DEBOUNCE_MS);
85
+ if (!Array.isArray(combinedSigns)) {
86
+ if (combinedSigns) combinedSigns = [combinedSigns];
87
+ else combinedSigns = [];
88
+ }
89
+ let signFilter = '';
90
+ if (combinedSigns.length > 0) {
91
+ signFilter = combinedSigns
92
+ .map((sign) => `?measure ext:relation/ext:concept <${sign}>.`)
93
+ .join('\n');
94
+ signFilter += '\n';
95
+ const commaSeperatedSigns = combinedSigns
96
+ .map((sign) => `<${sign}>`)
97
+ .join(',');
98
+ signFilter += `FILTER (?signUri NOT IN (${commaSeperatedSigns}))`;
99
+ }
100
+
101
+ const query = `
102
+ SELECT DISTINCT ?signUri ?signCode WHERE {
103
+ ?measure ext:relation/ext:concept ?signUri.
104
+ ?signUri a ${type ? `<${type}>` : '?signType'};
105
+ skos:prefLabel ?signCode;
106
+ ext:valid "true"^^<http://mu.semte.ch/vocabularies/typed-literals/boolean>.
107
+ ${category ? `?signUri org:classification <${category}>` : ''}
108
+ ${
109
+ type
110
+ ? ''
111
+ : `
112
+ VALUES ?signType {
113
+ <https://data.vlaanderen.be/ns/mobiliteit#Verkeersbordconcept>
114
+ <https://data.vlaanderen.be/ns/mobiliteit#Wegmarkeringconcept>
115
+ <https://data.vlaanderen.be/ns/mobiliteit#Verkeerslichtconcept>
116
+ }
117
+ `
118
+ }
119
+ ${signFilter}
120
+ ${
121
+ codeString
122
+ ? `FILTER(CONTAINS(LCASE(?signCode), "${codeString.toLowerCase()}"))`
123
+ : ''
124
+ }
125
+ }
126
+ ORDER BY ASC(?signCode)
127
+ `;
128
+ const result = await this.executeQuery.perform(query);
129
+ const codes = result.results.bindings.map((binding) => ({
130
+ value: unwrap(binding['signUri']?.value),
131
+ label: unwrap(binding['signCode']?.value),
132
+ }));
133
+ return codes;
134
+ }
135
+ );
136
+
137
+ executeQuery = task(
138
+ async (
139
+ query: string
140
+ ): Promise<{
141
+ results: {
142
+ bindings: IBindings[];
143
+ };
144
+ }> => {
145
+ const encodedQuery = encodeURIComponent(`${PREFIXES}\n${query.trim()}`);
146
+ const response = await fetch(this.endpoint, {
147
+ method: 'POST',
148
+ mode: 'cors',
149
+ headers: {
150
+ Accept: 'application/sparql-results+json',
151
+ 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
152
+ },
153
+ body: `query=${encodedQuery}`,
154
+ });
155
+ if (response.ok) {
156
+ return response.json() as unknown as {
157
+ results: {
158
+ bindings: IBindings[];
159
+ };
160
+ };
161
+ } else {
162
+ throw new Error(
163
+ `Request to MOW backend was unsuccessful: [${response.status}] ${response.statusText}`
164
+ );
165
+ }
166
+ }
167
+ );
168
+
169
+ fetchInstructionsForMeasure = task(
170
+ async (uri: string): Promise<Instruction[]> => {
171
+ const query = `SELECT ?name ?template ?annotatedTemplate
172
+ WHERE {
173
+ <${uri}> ext:template/ext:mapping ?mapping.
174
+ ?mapping ext:variableType 'instruction';
175
+ ext:variable ?name;
176
+ ext:instructionVariable ?instructionVariable.
177
+ ?instructionVariable ext:annotated ?annotatedTemplate;
178
+ ext:value ?template.
179
+ }
180
+ `;
181
+ const result = await this.executeQuery.perform(query);
182
+ const instructions = result.results.bindings.map((binding) =>
183
+ Instruction.fromBinding(binding)
184
+ );
185
+ return instructions;
186
+ }
187
+ );
188
+
189
+ fetchMeasures = task(
190
+ { restartable: true },
191
+ async ({
192
+ zonality,
193
+ type,
194
+ codes,
195
+ category,
196
+ pageStart,
197
+ }: {
198
+ zonality?: string;
199
+ type?: string;
200
+ codes?: string[];
201
+ category?: string;
202
+ pageStart?: number;
203
+ } = {}) => {
204
+ const selectQuery = generateMeasuresQuery({
205
+ zonality,
206
+ type,
207
+ codes,
208
+ category,
209
+ pageStart,
210
+ });
211
+ const countQuery = generateMeasuresQuery({
212
+ zonality,
213
+ type,
214
+ codes,
215
+ category,
216
+ count: true,
217
+ });
218
+ const countResult = await this.executeQuery.perform(countQuery);
219
+
220
+ const count = optionMapOr(
221
+ 0,
222
+ parseInt,
223
+ countResult.results.bindings[0]?.['count']?.value
224
+ );
225
+ const measures = [];
226
+ const result = await this.executeQuery.perform(selectQuery);
227
+ for (const binding of result.results.bindings) {
228
+ const measure = Measure.fromBinding(binding);
229
+ measure.signs = await this.fetchSignsForMeasure.perform(measure.uri);
230
+ measure.classifications = makeClassificationSet(measure.signs);
231
+ measures.push(measure);
232
+ }
233
+ return { measures, count };
234
+ }
235
+ );
236
+
237
+ fetchSignsForMeasure = task(async (uri: string) => {
238
+ const query = `
239
+ SELECT ?uri ?code ?image ?zonality ?order (GROUP_CONCAT(?classification; SEPARATOR="|") AS ?classifications)
240
+ WHERE {
241
+ <${uri}> ext:relation ?relation.
242
+ ?relation a ext:MustUseRelation;
243
+ <http://purl.org/linked-data/cube#order> ?order;
244
+ ext:concept ?uri.
245
+ ?uri a ?type;
246
+ skos:prefLabel ?code;
247
+ ext:zonality ?zonality;
248
+ mobiliteit:grafischeWeergave ?image.
249
+ OPTIONAL {
250
+ ?uri org:classification/skos:prefLabel ?classification.
251
+ }
252
+ } ORDER BY ASC(?order)
253
+ `;
254
+ const result = await this.executeQuery.perform(query);
255
+ const signs = [];
256
+ for (const binding of result.results.bindings) {
257
+ const sign = Sign.fromBinding({
258
+ ...binding,
259
+ imageBaseUrl: dataFactory.namedNode(this.imageBaseUrl),
260
+ });
261
+ signs.push(sign);
262
+ }
263
+ return signs;
264
+ });
265
+ }
266
+
267
+ function makeClassificationSet(signs: Iterable<Sign>) {
268
+ const classifications = new Set();
269
+ for (const sign of signs) {
270
+ for (const c of sign.classifications) {
271
+ classifications.add(c);
272
+ }
273
+ }
274
+ sortSet(classifications);
275
+ return classifications;
276
+ }
277
+
278
+ function sortSet<T>(set: Set<T>) {
279
+ const entries = [];
280
+ for (const member of set) {
281
+ entries.push(member);
282
+ }
283
+ set.clear();
284
+ for (const entry of entries.sort()) {
285
+ set.add(entry);
286
+ }
287
+ return set;
288
+ }
@@ -1,21 +1,27 @@
1
+ import Store from '@ember-data/store';
2
+ // eslint-disable-next-line ember/use-ember-data-rfc-395-imports
3
+ import { DS } from 'ember-data';
1
4
  import Service, { inject as service } from '@ember/service';
2
- import { task, waitForProperty } from 'ember-concurrency';
5
+ import { task, waitForProperty, Task } from 'ember-concurrency';
3
6
  import { tracked } from '@glimmer/tracking';
7
+ import TemplateModel from '../models/template';
4
8
 
5
- export default class RdfaEditorStandardTemplatePluginService extends Service {
6
- @service store;
7
- @tracked templates;
9
+ export default class StandardTemplatePluginService extends Service {
10
+ @service declare store: Store;
11
+ @tracked declare templates: DS.RecordArray<TemplateModel>;
8
12
 
9
13
  constructor() {
14
+ // eslint-disable-next-line prefer-rest-params
10
15
  super(...arguments);
11
- this.loadTemplates();
16
+ void this.loadTemplates();
12
17
  }
13
18
 
14
- @task
15
- *fetchTemplates() {
16
- yield waitForProperty(this, 'templates');
19
+ fetchTemplates: Task<DS.RecordArray<TemplateModel>, []> = task(async () => {
20
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
21
+ // @ts-ignore
22
+ await waitForProperty(this, 'templates');
17
23
  return this.templates;
18
- }
24
+ });
19
25
 
20
26
  async loadTemplates() {
21
27
  this.templates = await this.store.query('template', {
@@ -31,8 +37,8 @@ export default class RdfaEditorStandardTemplatePluginService extends Service {
31
37
  @return {Array} Array of templates (filtered)
32
38
  @private
33
39
  */
34
- templatesForContext(templates, rdfaTypes) {
35
- let isMatchingForContext = (template) => {
40
+ templatesForContext(templates: TemplateModel[], rdfaTypes: string[]) {
41
+ const isMatchingForContext = (template: TemplateModel) => {
36
42
  return (
37
43
  rdfaTypes.filter((e) => template.get('contexts').includes(e)).length >
38
44
  0 &&
@@ -0,0 +1,260 @@
1
+ import { StructureSpec } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/article-structure-plugin';
2
+ import romanize from '../romanize';
3
+
4
+ export const STRUCTURES: Record<string, StructureSpec> = {
5
+ title: {
6
+ uriBase: 'http://data.lblod.info/titles/',
7
+ title: 'Title',
8
+ type: 'https://say.data.gift/ns/Title',
9
+ numberPredicate: 'http://data.europa.eu/eli/ontology#number',
10
+ numberingFunction: romanize,
11
+ heading: 'h3',
12
+ translation: 'article-structure-plugin.insert.title',
13
+ moveUp: 'article-structure-plugin.moveUp.title',
14
+ moveDown: 'article-structure-plugin.moveDown.title',
15
+ shaclConstraint: `
16
+ @prefix sh: <http://www.w3.org/ns/shacl#> .
17
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
18
+ @prefix schema: <http://schema.org/> .
19
+ schema:ArticleShape
20
+ a sh:NodeShape ;
21
+ sh:targetSubjectsOf <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>;
22
+ sh:property [
23
+ sh:path <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ;
24
+ sh:hasValue <https://say.data.gift/ns/DocumentContent>
25
+ ].
26
+ `,
27
+ template: (uri, intlService) => `
28
+ <div
29
+ property="say:hasPart"
30
+ typeof="https://say.data.gift/ns/Title https://say.data.gift/ns/ArticleContainer"
31
+ resource="${uri}"
32
+ >
33
+ <h4 property="say:heading">
34
+ <span property="eli:number" datatype="xsd:string">
35
+ <span class="mark-highlight-manual">nummer</span>
36
+ </span>.
37
+ <span property="ext:title"><span class="mark-highlight-manual">${intlService.t(
38
+ 'article-structure-plugin.placeholder.title'
39
+ )}</span></span>
40
+ </h4>
41
+ <div property="say:body" datatype='rdf:XMLLiteral'>
42
+ <span class="mark-highlight-manual">Voer inhoud in</span>
43
+ </div>
44
+ </div>`,
45
+ },
46
+ chapter: {
47
+ uriBase: 'http://data.lblod.info/chapters/',
48
+ title: 'Chapter',
49
+ type: 'https://say.data.gift/ns/Chapter',
50
+ numberPredicate: 'http://data.europa.eu/eli/ontology#number',
51
+ numberingFunction: romanize,
52
+ translation: 'article-structure-plugin.insert.chapter',
53
+ moveUp: 'article-structure-plugin.moveUp.chapter',
54
+ moveDown: 'article-structure-plugin.moveDown.chapter',
55
+ insertPredicate: {
56
+ long: 'https://say.data.gift/ns/body',
57
+ short: 'say:body',
58
+ },
59
+ shaclConstraint: `
60
+ @prefix sh: <http://www.w3.org/ns/shacl#> .
61
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
62
+ @prefix schema: <http://schema.org/> .
63
+ schema:ArticleShape
64
+ a sh:NodeShape ;
65
+ sh:targetSubjectsOf <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>;
66
+ sh:property [
67
+ sh:path <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ;
68
+ sh:hasValue <https://say.data.gift/ns/Title>
69
+ ].
70
+ `,
71
+ template: (uri, intlService) => `
72
+ <div
73
+ property="say:hasPart"
74
+ typeof="https://say.data.gift/ns/Chapter https://say.data.gift/ns/ArticleContainer"
75
+ resource="${uri}"
76
+ >
77
+ <h4 property="say:heading">
78
+ <span property="eli:number" datatype="xsd:string">
79
+ <span class="mark-highlight-manual">nummer</span>
80
+ </span>.
81
+ <span property="ext:title"><span class="mark-highlight-manual">${intlService.t(
82
+ 'article-structure-plugin.placeholder.chapter'
83
+ )}</span></span>
84
+ </h4>
85
+ <div property="say:body" datatype='rdf:XMLLiteral'>
86
+ <span class="mark-highlight-manual">Voer inhoud in</span>
87
+ </div>
88
+ </div>`,
89
+ },
90
+ section: {
91
+ uriBase: 'http://data.lblod.info/sections/',
92
+ title: 'Section',
93
+ heading: 'h5',
94
+ type: 'https://say.data.gift/ns/Section',
95
+ numberPredicate: 'http://data.europa.eu/eli/ontology#number',
96
+ numberingFunction: romanize,
97
+ translation: 'article-structure-plugin.insert.section',
98
+ moveUp: 'article-structure-plugin.moveUp.section',
99
+ moveDown: 'article-structure-plugin.moveDown.section',
100
+ insertPredicate: {
101
+ long: 'https://say.data.gift/ns/body',
102
+ short: 'say:body',
103
+ },
104
+ shaclConstraint: `
105
+ @prefix sh: <http://www.w3.org/ns/shacl#> .
106
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
107
+ @prefix schema: <http://schema.org/> .
108
+ schema:ArticleShape
109
+ a sh:NodeShape ;
110
+ sh:targetSubjectsOf <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>;
111
+ sh:property [
112
+ sh:path <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ;
113
+ sh:hasValue <https://say.data.gift/ns/Chapter>
114
+ ].
115
+ `,
116
+ template: (uri, intlService) => `
117
+ <div
118
+ property="say:hasPart"
119
+ typeof="https://say.data.gift/ns/Section https://say.data.gift/ns/ArticleContainer"
120
+ resource="${uri}"
121
+ >
122
+ <h5 property="say:heading">
123
+ <span property="eli:number" datatype="xsd:string">
124
+ <span class="mark-highlight-manual">nummer</span>
125
+ </span>.
126
+ <span property="ext:title"><span class="mark-highlight-manual">${intlService.t(
127
+ 'article-structure-plugin.placeholder.section'
128
+ )}</span></span>
129
+ </h5>
130
+ <div property="say:body" datatype='rdf:XMLLiteral'>
131
+ <span class="mark-highlight-manual">Voer inhoud in</span>
132
+ </div>
133
+ </div>`,
134
+ },
135
+ subsection: {
136
+ uriBase: 'http://data.lblod.info/subsections/',
137
+ title: 'Subsection',
138
+ heading: 'h6',
139
+ type: 'https://say.data.gift/ns/Subsection',
140
+ numberingFunction: romanize,
141
+ numberPredicate: 'http://data.europa.eu/eli/ontology#number',
142
+ translation: 'article-structure-plugin.insert.subsection',
143
+ moveUp: 'article-structure-plugin.moveUp.subsection',
144
+ moveDown: 'article-structure-plugin.moveDown.subsection',
145
+ insertPredicate: {
146
+ long: 'https://say.data.gift/ns/body',
147
+ short: 'say:body',
148
+ },
149
+ shaclConstraint: `
150
+ @prefix sh: <http://www.w3.org/ns/shacl#> .
151
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
152
+ @prefix schema: <http://schema.org/> .
153
+ schema:ArticleShape
154
+ a sh:NodeShape ;
155
+ sh:targetSubjectsOf <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>;
156
+ sh:property [
157
+ sh:path <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ;
158
+ sh:hasValue <https://say.data.gift/ns/Section>
159
+ ].
160
+ `,
161
+ template: (uri, intlService) => `
162
+ <div
163
+ property="say:hasPart"
164
+ typeof="https://say.data.gift/ns/Subsection https://say.data.gift/ns/ArticleContainer"
165
+ resource="${uri}"
166
+ >
167
+ <h6 property="say:heading">
168
+ <span property="eli:number" datatype="xsd:string">
169
+ <span class="mark-highlight-manual">nummer</span>
170
+ </span>.
171
+ <span property="ext:title"><span class="mark-highlight-manual">${intlService.t(
172
+ 'article-structure-plugin.placeholder.subsection'
173
+ )}</span></span>
174
+ </h6>
175
+ <div property="say:body" datatype='rdf:XMLLiteral'>
176
+ <span class="mark-highlight-manual">Voer inhoud in</span>
177
+ </div>
178
+ </div>`,
179
+ },
180
+ article: {
181
+ uriBase: 'http://data.lblod.info/artikels/',
182
+ title: 'Article',
183
+ translation: 'article-structure-plugin.insert.article',
184
+ moveUp: 'article-structure-plugin.moveUp.article',
185
+ moveDown: 'article-structure-plugin.moveDown.article',
186
+ type: 'http://data.vlaanderen.be/ns/besluit#Artikel',
187
+ numberPredicate: 'http://data.europa.eu/eli/ontology#number',
188
+ insertPredicate: {
189
+ long: 'https://say.data.gift/ns/body',
190
+ short: 'say:body',
191
+ },
192
+ numbering: 'continuous',
193
+ shaclConstraint: `
194
+ @prefix sh: <http://www.w3.org/ns/shacl#> .
195
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
196
+ @prefix schema: <http://schema.org/> .
197
+ schema:ArticleShape
198
+ a sh:NodeShape ;
199
+ sh:targetSubjectsOf <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>;
200
+ sh:property [
201
+ sh:path <https://say.data.gift/ns/hasPart> ;
202
+ sh:class <http://data.vlaanderen.be/ns/besluit#Artikel>
203
+ ];
204
+ sh:property [
205
+ sh:path <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ;
206
+ sh:hasValue <https://say.data.gift/ns/ArticleContainer>
207
+ ].
208
+ `,
209
+ template: (uri) => `
210
+ <div property="say:hasPart" typeof="http://data.vlaanderen.be/ns/besluit#Artikel" resource="${uri}">
211
+ <div property="say:heading">
212
+ Artikel
213
+ <span property="eli:number" datatype="xsd:integer">
214
+ <span class="mark-highlight-manual">nummer</span>
215
+ </span>
216
+ :
217
+ <span property="ext:title"><span class="mark-highlight-manual">Voer inhoud in</span></span>
218
+ </div>
219
+ <span style="display:none;" property="eli:language" resource="http://publications.europa.eu/resource/authority/language/NLD" typeof="skos:Concept">&nbsp;</span>
220
+ <div property="say:body" datatype='rdf:XMLLiteral'>
221
+ <span class="mark-highlight-manual">Voer inhoud in</span>
222
+ </div>
223
+ </div>
224
+
225
+ `,
226
+ },
227
+ paragraph: {
228
+ uriBase: 'http://data.lblod.info/paragraphs/',
229
+ title: 'Paragraph',
230
+ translation: 'article-structure-plugin.insert.paragraph',
231
+ moveUp: 'article-structure-plugin.moveUp.paragrah',
232
+ moveDown: 'article-structure-plugin.moveDown.paragrah',
233
+ type: 'https://say.data.gift/ns/Paragraph',
234
+ numberPredicate: 'http://data.europa.eu/eli/ontology#number',
235
+ insertPredicate: {
236
+ long: 'https://say.data.gift/ns/body',
237
+ short: 'say:body',
238
+ },
239
+ shaclConstraint: `
240
+ @prefix sh: <http://www.w3.org/ns/shacl#> .
241
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
242
+ @prefix schema: <http://schema.org/> .
243
+ schema:ParagraphShape
244
+ a sh:NodeShape ;
245
+ sh:targetSubjectsOf <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>;
246
+ sh:property [
247
+ sh:path <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ;
248
+ sh:hasValue <http://data.vlaanderen.be/ns/besluit#Artikel>
249
+ ].
250
+ `,
251
+ template: (uri) => `
252
+ <div property="say:hasParagraph" typeof="say:Paragraph" resource="${uri}">
253
+ §<span property="eli:number" datatype="xsd:integer">
254
+ <span class="mark-highlight-manual">nummer</span>
255
+ </span>.
256
+ <span class="mark-highlight-manual">Voer inhoud in</span>
257
+ </div>
258
+ `,
259
+ },
260
+ };
@@ -0,0 +1,3 @@
1
+ export default {
2
+ numberPredicate: 'http://data.europa.eu/eli/ontology#number',
3
+ };
@@ -0,0 +1,31 @@
1
+ import {
2
+ ArticleStructurePluginOptions,
3
+ ResolvedArticleStructurePluginOptions,
4
+ } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/article-structure-plugin';
5
+ import { STRUCTURES } from './constants';
6
+
7
+ export default function optionsWithDefaults(
8
+ options?: ArticleStructurePluginOptions
9
+ ): ResolvedArticleStructurePluginOptions {
10
+ const structuresSelected = [];
11
+ const structuresTypesSelectedByUser =
12
+ (options && options.structures) || Object.keys(STRUCTURES);
13
+ for (const type of structuresTypesSelectedByUser) {
14
+ if (typeof type === 'string') {
15
+ const defaultStructure = STRUCTURES[type];
16
+ if (defaultStructure) {
17
+ structuresSelected.push(defaultStructure);
18
+ } else {
19
+ console.warn(
20
+ `Article Structure Plugin: structure type ${type} not found in the default structure types`
21
+ );
22
+ }
23
+ } else {
24
+ structuresSelected.push(type);
25
+ }
26
+ }
27
+ return {
28
+ structures: structuresSelected,
29
+ structureTypes: structuresSelected.map((structure) => structure.type),
30
+ };
31
+ }
@@ -0,0 +1,23 @@
1
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
+ // @ts-nocheck
3
+ import ParserN3 from '@rdfjs/parser-n3';
4
+ import SHACLValidator from 'rdf-validate-shacl';
5
+ import factory from 'rdf-ext';
6
+ import { Readable } from 'stream-browserify';
7
+ import { ProseStore } from '@lblod/ember-rdfa-editor/addon/plugins/datastore';
8
+
9
+ export default async function validateDatastore(
10
+ datastore: ProseStore,
11
+ shaclConstraint: string
12
+ ) {
13
+ const s = new Readable();
14
+ s.push(shaclConstraint);
15
+ s.push(null);
16
+ const parser = new ParserN3({ factory });
17
+ const shapes = await factory.dataset().import(parser.import(s));
18
+ const data = datastore.dataset;
19
+ const validator = new SHACLValidator(shapes, { factory });
20
+ // eslint-disable-next-line @typescript-eslint/await-thenable
21
+ const report = await validator.validate(data);
22
+ return report;
23
+ }