@lblod/ember-rdfa-editor-lblod-plugins 1.0.0-alpha.3 → 1.0.0-beta.2

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 (124) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/addon/components/article-structure-plugin/article-structure-card.hbs +3 -1
  3. package/addon/components/au-dropdown-pill.hbs +32 -0
  4. package/addon/components/au-dropdown-pill.ts +65 -0
  5. package/addon/components/besluit-type-plugin/toolbar-dropdown.ts +19 -12
  6. package/addon/components/citation-plugin/citation-card.hbs +2 -2
  7. package/addon/components/citation-plugin/citation-card.ts +1 -1
  8. package/addon/components/citation-plugin/citation-insert.hbs +3 -1
  9. package/addon/components/citation-plugin/citation-insert.ts +28 -2
  10. package/addon/components/citation-plugin/citations/search-modal.hbs +1 -1
  11. package/addon/components/citation-plugin/citations/search-modal.ts +3 -18
  12. package/addon/components/import-snippet-plugin/card.ts +8 -12
  13. package/addon/components/rdfa-date-plugin/card.hbs +28 -0
  14. package/addon/components/rdfa-date-plugin/card.ts +72 -38
  15. package/addon/components/rdfa-date-plugin/date-time-picker.ts +1 -0
  16. package/addon/components/rdfa-date-plugin/insert.hbs +2 -2
  17. package/addon/components/rdfa-date-plugin/insert.ts +14 -23
  18. package/addon/components/roadsign-regulation-plugin/roadsign-regulation-card.ts +24 -25
  19. package/addon/components/roadsign-regulation-plugin/roadsigns-modal.ts +37 -18
  20. package/addon/components/standard-template-plugin/template-provider.ts +54 -11
  21. package/addon/components/table-of-contents-plugin/ember-nodes/table-of-contents.ts +27 -30
  22. package/addon/components/table-of-contents-plugin/toolbar-button.hbs +8 -0
  23. package/addon/components/table-of-contents-plugin/{card.ts → toolbar-button.ts} +1 -18
  24. package/addon/components/{insert-variable-plugin → variable-plugin}/insert-variable-card.hbs +4 -4
  25. package/addon/components/{insert-variable-plugin → variable-plugin}/insert-variable-card.ts +26 -35
  26. package/addon/components/{template-variable-plugin → variable-plugin}/template-variable-card.hbs +6 -6
  27. package/addon/components/variable-plugin/template-variable-card.ts +174 -0
  28. package/addon/components/variable-plugin/variable.hbs +4 -0
  29. package/addon/components/variable-plugin/variable.ts +250 -0
  30. package/addon/plugins/article-structure-plugin/commands/insert-structure.ts +58 -31
  31. package/addon/plugins/article-structure-plugin/index.ts +1 -1
  32. package/addon/plugins/article-structure-plugin/structures/article-paragraph.ts +42 -6
  33. package/addon/plugins/article-structure-plugin/structures/article.ts +14 -4
  34. package/addon/plugins/article-structure-plugin/structures/chapter.ts +2 -3
  35. package/addon/plugins/article-structure-plugin/structures/section.ts +2 -2
  36. package/addon/plugins/article-structure-plugin/structures/structure-header.ts +11 -4
  37. package/addon/plugins/article-structure-plugin/structures/subsection.ts +2 -2
  38. package/addon/plugins/article-structure-plugin/structures/title.ts +2 -3
  39. package/addon/plugins/article-structure-plugin/utils/structure.ts +29 -9
  40. package/addon/plugins/citation-plugin/index.ts +184 -113
  41. package/addon/plugins/rdfa-date-plugin/index.ts +42 -3
  42. package/addon/plugins/rdfa-date-plugin/nodes/date.ts +127 -0
  43. package/addon/plugins/rdfa-date-plugin/nodes/index.ts +1 -0
  44. package/addon/plugins/rdfa-date-plugin/utils.ts +10 -0
  45. package/addon/plugins/roadsign-regulation-plugin/nodes.ts +107 -0
  46. package/addon/plugins/standard-template-plugin/index.ts +26 -0
  47. package/addon/plugins/standard-template-plugin/utils/nodes.ts +366 -0
  48. package/addon/plugins/table-of-contents-plugin/index.ts +8 -12
  49. package/addon/plugins/table-of-contents-plugin/nodes/table-of-contents.ts +35 -42
  50. package/addon/plugins/{insert-variable-plugin → variable-plugin}/index.ts +6 -1
  51. package/addon/plugins/variable-plugin/nodes.ts +137 -0
  52. package/addon/plugins/variable-plugin/utils/constants.ts +107 -0
  53. package/addon/plugins/{template-variable-plugin → variable-plugin}/utils/fetch-data.ts +41 -0
  54. package/addon/services/standard-template-plugin.ts +16 -12
  55. package/addon/utils/changed-descendants.ts +29 -0
  56. package/addon/utils/constants.ts +22 -0
  57. package/addon/utils/namespace.ts +60 -0
  58. package/app/components/{table-of-contents-plugin/card.js → au-dropdown-pill.js} +1 -1
  59. package/app/components/table-of-contents-plugin/toolbar-button.js +1 -0
  60. package/app/components/{insert-variable-plugin → variable-plugin}/insert-variable-card.js +1 -1
  61. package/app/components/{template-variable-plugin → variable-plugin}/template-variable-card.js +1 -1
  62. package/app/components/variable-plugin/variable-edit-modal.js +1 -0
  63. package/app/components/variable-plugin/variable.js +1 -0
  64. package/app/styles/date-plugin.scss +17 -0
  65. package/app/styles/variable-plugin.scss +65 -0
  66. package/components/au-dropdown-pill.d.ts +19 -0
  67. package/components/au-native-input.d.ts +1 -1
  68. package/components/citation-plugin/citation-card.d.ts +1 -1
  69. package/components/citation-plugin/citation-insert.d.ts +7 -0
  70. package/components/citation-plugin/citations/search-modal.d.ts +1 -3
  71. package/components/rdfa-date-plugin/card.d.ts +14 -5
  72. package/components/rdfa-date-plugin/insert.d.ts +1 -2
  73. package/components/roadsign-regulation-plugin/roadsign-regulation-card.d.ts +1 -0
  74. package/components/roadsign-regulation-plugin/roadsigns-modal.d.ts +3 -0
  75. package/components/standard-template-plugin/template-provider.d.ts +6 -1
  76. package/components/table-of-contents-plugin/ember-nodes/table-of-contents.d.ts +1 -1
  77. package/components/table-of-contents-plugin/{card.d.ts → toolbar-button.d.ts} +0 -5
  78. package/components/{insert-variable-plugin → variable-plugin}/insert-variable-card.d.ts +3 -4
  79. package/components/{template-variable-plugin → variable-plugin}/template-variable-card.d.ts +8 -5
  80. package/components/variable-plugin/variable.d.ts +42 -0
  81. package/package.json +6 -6
  82. package/plugins/article-structure-plugin/commands/insert-structure.d.ts +2 -2
  83. package/plugins/article-structure-plugin/index.d.ts +1 -1
  84. package/plugins/article-structure-plugin/utils/structure.d.ts +4 -3
  85. package/plugins/citation-plugin/index.d.ts +11 -4
  86. package/plugins/rdfa-date-plugin/index.d.ts +13 -1
  87. package/plugins/rdfa-date-plugin/nodes/date.d.ts +9 -0
  88. package/plugins/rdfa-date-plugin/nodes/index.d.ts +1 -0
  89. package/plugins/rdfa-date-plugin/utils.d.ts +1 -0
  90. package/plugins/roadsign-regulation-plugin/nodes.d.ts +2 -0
  91. package/plugins/standard-template-plugin/index.d.ts +12 -0
  92. package/plugins/standard-template-plugin/utils/nodes.d.ts +12 -0
  93. package/plugins/table-of-contents-plugin/index.d.ts +4 -2
  94. package/plugins/table-of-contents-plugin/nodes/table-of-contents.d.ts +4 -3
  95. package/plugins/{insert-variable-plugin → variable-plugin}/index.d.ts +1 -0
  96. package/plugins/variable-plugin/nodes.d.ts +2 -0
  97. package/plugins/variable-plugin/utils/constants.d.ts +9 -0
  98. package/plugins/{template-variable-plugin → variable-plugin}/utils/fetch-data.d.ts +5 -0
  99. package/services/standard-template-plugin.d.ts +9 -10
  100. package/translations/en-US.yaml +4 -3
  101. package/translations/nl-BE.yaml +8 -7
  102. package/utils/changed-descendants.d.ts +2 -0
  103. package/utils/constants.d.ts +10 -0
  104. package/utils/namespace.d.ts +11 -0
  105. package/addon/components/table-of-contents-plugin/card.hbs +0 -16
  106. package/addon/components/template-variable-plugin/template-variable-card.ts +0 -227
  107. package/addon/plugins/article-structure-plugin/constants.ts +0 -11
  108. package/addon/plugins/article-structure-plugin/utils/namespace.ts +0 -25
  109. package/addon/plugins/insert-variable-plugin/utils/constants.ts +0 -67
  110. package/addon/plugins/insert-variable-plugin/utils/fetch-data.ts +0 -41
  111. package/addon/plugins/rdfa-date-plugin/commands/index.ts +0 -1
  112. package/addon/plugins/rdfa-date-plugin/commands/modify-date.ts +0 -48
  113. package/addon/plugins/table-of-contents-plugin/utils/constants.ts +0 -17
  114. package/addon/plugins/template-variable-plugin/index.ts +0 -6
  115. package/addon/plugins/template-variable-plugin/utils/constants.ts +0 -2
  116. package/plugins/article-structure-plugin/constants.d.ts +0 -5
  117. package/plugins/article-structure-plugin/utils/namespace.d.ts +0 -6
  118. package/plugins/insert-variable-plugin/utils/constants.d.ts +0 -7
  119. package/plugins/insert-variable-plugin/utils/fetch-data.d.ts +0 -5
  120. package/plugins/rdfa-date-plugin/commands/index.d.ts +0 -1
  121. package/plugins/rdfa-date-plugin/commands/modify-date.d.ts +0 -2
  122. package/plugins/table-of-contents-plugin/utils/constants.d.ts +0 -7
  123. package/plugins/template-variable-plugin/index.d.ts +0 -2
  124. package/plugins/template-variable-plugin/utils/constants.d.ts +0 -1
@@ -1,3 +1,4 @@
1
+ import { findParentNode } from '@curvenote/prosemirror-utils';
1
2
  import { action } from '@ember/object';
2
3
  import Component from '@glimmer/component';
3
4
  import { tracked } from '@glimmer/tracking';
@@ -11,13 +12,13 @@ import { ProseController } from '@lblod/ember-rdfa-editor/core/prosemirror';
11
12
  * @extends Ember.Component
12
13
  */
13
14
  const acceptedTypes = [
14
- '>https://data.vlaanderen.be/id/concept/BesluitType/4d8f678a-6fa4-4d5f-a2a1-80974e43bf34',
15
- '>https://data.vlaanderen.be/id/concept/BesluitType/7d95fd2e-3cc9-4a4c-a58e-0fbc408c2f9b',
16
- '>https://data.vlaanderen.be/id/concept/BesluitType/3bba9f10-faff-49a6-acaa-85af7f2199a3',
17
- '>https://data.vlaanderen.be/id/concept/BesluitType/0d1278af-b69e-4152-a418-ec5cfd1c7d0b',
18
- '>https://data.vlaanderen.be/id/concept/BesluitType/e8afe7c5-9640-4db8-8f74-3f023bec3241',
19
- '>https://data.vlaanderen.be/id/concept/BesluitType/256bd04a-b74b-4f2a-8f5d-14dda4765af9',
20
- '>https://data.vlaanderen.be/id/concept/BesluitType/67378dd0-5413-474b-8996-d992ef81637a',
15
+ 'https://data.vlaanderen.be/id/concept/BesluitType/4d8f678a-6fa4-4d5f-a2a1-80974e43bf34',
16
+ 'https://data.vlaanderen.be/id/concept/BesluitType/7d95fd2e-3cc9-4a4c-a58e-0fbc408c2f9b',
17
+ 'https://data.vlaanderen.be/id/concept/BesluitType/3bba9f10-faff-49a6-acaa-85af7f2199a3',
18
+ 'https://data.vlaanderen.be/id/concept/BesluitType/0d1278af-b69e-4152-a418-ec5cfd1c7d0b',
19
+ 'https://data.vlaanderen.be/id/concept/BesluitType/e8afe7c5-9640-4db8-8f74-3f023bec3241',
20
+ 'https://data.vlaanderen.be/id/concept/BesluitType/256bd04a-b74b-4f2a-8f5d-14dda4765af9',
21
+ 'https://data.vlaanderen.be/id/concept/BesluitType/67378dd0-5413-474b-8996-d992ef81637a',
21
22
  ];
22
23
 
23
24
  type Args = {
@@ -36,25 +37,23 @@ export default class RoadsignRegulationCard extends Component<Args> {
36
37
  return this.args.controller;
37
38
  }
38
39
 
40
+ get schema() {
41
+ return this.args.controller.schema;
42
+ }
43
+
39
44
  get showCard() {
40
45
  const selection = this.controller.state.selection;
41
- const limitedDatastore = this.controller.datastore.limitToRange(
42
- this.controller.state,
43
- selection.from,
44
- selection.to
45
- );
46
- const besluit = [
47
- ...limitedDatastore
48
- .match(undefined, 'a')
49
- .transformDataset((dataset, termConverter) => {
50
- return dataset.filter((quad) =>
51
- acceptedTypes
52
- .map((type) => termConverter(type).value)
53
- .includes(quad.object.value)
54
- );
55
- })
56
- .asQuadResultSet(),
57
- ][0];
58
- return !!besluit;
46
+ const besluitNode = findParentNode((node) => {
47
+ if (node.type === this.schema.nodes['besluit']) {
48
+ const rdfTypes = (node.attrs['typeof'] as string | undefined)?.split(
49
+ ' '
50
+ );
51
+ if (rdfTypes?.some((t) => acceptedTypes.includes(t))) {
52
+ return true;
53
+ }
54
+ }
55
+ return false;
56
+ })(selection);
57
+ return !!besluitNode;
59
58
  }
60
59
  }
@@ -16,7 +16,10 @@ import { assert } from '@ember/debug';
16
16
  import { unwrap } from '@lblod/ember-rdfa-editor/utils/option';
17
17
  import Measure from '@lblod/ember-rdfa-editor-lblod-plugins/models/measure';
18
18
  import { ProseController } from '@lblod/ember-rdfa-editor/core/prosemirror';
19
- import { insertArticle } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/besluit-plugin/commands';
19
+ import { insertStructure } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/article-structure-plugin/commands';
20
+ import { besluitArticleStructure } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/standard-template-plugin/utils/nodes';
21
+ import IntlService from 'ember-intl/services/intl';
22
+ import { ProseParser } from '@lblod/ember-rdfa-editor';
20
23
 
21
24
  const PAGE_SIZE = 10;
22
25
  const SIGN_TYPE_URI =
@@ -47,6 +50,7 @@ export default class RoadsignRegulationCard extends Component<Args> {
47
50
 
48
51
  pageSize = PAGE_SIZE;
49
52
  @service declare roadsignRegistry: RoadsignRegistryService;
53
+ @service declare intl: IntlService;
50
54
 
51
55
  @tracked typeSelected?: TypeOption;
52
56
 
@@ -91,6 +95,10 @@ export default class RoadsignRegulationCard extends Component<Args> {
91
95
  this.search();
92
96
  }
93
97
 
98
+ get schema() {
99
+ return this.args.controller.schema;
100
+ }
101
+
94
102
  @action
95
103
  selectTypeOrCategory(option: Option) {
96
104
  if (!option) {
@@ -260,7 +268,7 @@ export default class RoadsignRegulationCard extends Component<Args> {
260
268
  }</span>
261
269
  <span style="margin-left:0;margin-top:0;">${
262
270
  sign.zonality === POTENTIALLY_ZONAL_URI && zonality === ZONAL_URI
263
- ? 'met zonale geldigheid'
271
+ ? ' met zonale geldigheid'
264
272
  : ''
265
273
  }
266
274
  </span>
@@ -270,24 +278,35 @@ export default class RoadsignRegulationCard extends Component<Args> {
270
278
  })
271
279
  .join('\n');
272
280
  const regulationHTML = `<div property="mobiliteit:heeftVerkeersmaatregel" typeof="mobiliteit:Mobiliteitsmaatregel" resource="http://data.lblod.info/mobiliteitsmaatregels/${uuid()}">
273
- <span style="display:none;" property="prov:wasDerivedFrom" resource="${
274
- measure.uri
275
- }">&nbsp;</span>
276
- <span style="display:none;" property="ext:zonality" resource="${zonality}"></span>
277
- <span style="display:none;" property="ext:temporal" value="${measure.temporal.toString()}"></span>
278
- <div property="dct:description">
279
- ${html}
280
- <p>Dit wordt aangeduid door verkeerstekens:</p>
281
- <ul style="list-style:none;">
282
- ${signsHTML}
283
- </ul>
284
- ${temporalValue === 'true' ? 'Deze signalisatie is dynamisch.' : ''}
285
- </div>
286
- </div>
287
- `;
281
+ <span style="display:none;" property="prov:wasDerivedFrom" resource="${
282
+ measure.uri
283
+ }">&nbsp;</span>
284
+ <span style="display:none;" property="ext:zonality" resource="${zonality}"></span>
285
+ <span style="display:none;" property="ext:temporal" value="${measure.temporal.toString()}"></span>
286
+ <div property="dct:description">
287
+ ${html}
288
+ <p>Dit wordt aangeduid door verkeerstekens:</p>
289
+ <ul style="list-style:none;">
290
+ ${signsHTML}
291
+ </ul>
292
+ ${
293
+ temporalValue === 'true'
294
+ ? 'Deze signalisatie is dynamisch.'
295
+ : ''
296
+ }
297
+ </div>
298
+ </div>
299
+ `;
300
+ const domParser = new DOMParser();
301
+ const htmlNode = domParser.parseFromString(regulationHTML, 'text/html');
302
+ const contentFragment = ProseParser.fromSchema(
303
+ this.args.controller.schema
304
+ ).parseSlice(htmlNode, {
305
+ preserveWhitespace: false,
306
+ }).content;
288
307
 
289
308
  this.args.controller.doCommand(
290
- insertArticle(this.args.controller, regulationHTML)
309
+ insertStructure(besluitArticleStructure, this.intl, contentFragment)
291
310
  );
292
311
  this.args.closeModal();
293
312
  }
@@ -6,10 +6,41 @@ import { ProseController } from '@lblod/ember-rdfa-editor/core/prosemirror';
6
6
  import TemplateModel from '@lblod/ember-rdfa-editor-lblod-plugins/models/template';
7
7
  import { insertHtml } from '@lblod/ember-rdfa-editor/commands/insert-html-command';
8
8
  import instantiateUuids from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/standard-template-plugin/utils/instantiate-uuids';
9
+ import { PNode, ResolvedPos } from '@lblod/ember-rdfa-editor';
10
+ import { BESLUIT } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
11
+ import {
12
+ pnodeHasRdfaAttribute,
13
+ Resource,
14
+ } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/namespace';
9
15
 
10
16
  type Args = {
11
17
  controller: ProseController;
12
18
  };
19
+
20
+ const HACKY_LOOKUP: Record<string, Resource> = {
21
+ 'http://data.vlaanderen.be/ns/besluit#BehandelingVanAgendapunt': BESLUIT(
22
+ 'BehandelingVanAgendapunt'
23
+ ),
24
+ 'http://data.vlaanderen.be/ns/besluit#Besluit': BESLUIT('Besluit'),
25
+ 'http://data.vlaanderen.be/ns/besluit#Artikel': BESLUIT('Artikel'),
26
+ };
27
+
28
+ export function findAncestors(
29
+ pos: ResolvedPos,
30
+ predicate: (node: PNode) => boolean = () => true
31
+ ) {
32
+ const result: { node: PNode; pos: number }[] = [];
33
+ let depth = pos.depth;
34
+ while (depth >= 0) {
35
+ const parent = pos.node(depth);
36
+ if (predicate(parent)) {
37
+ result.push({ node: parent, pos: pos.before(depth) });
38
+ }
39
+ depth -= 1;
40
+ }
41
+ return result;
42
+ }
43
+
13
44
  export default class TemplateProviderComponent extends Component<Args> {
14
45
  @service declare standardTemplatePlugin: StandardTemplatePluginService;
15
46
 
@@ -34,17 +65,29 @@ export default class TemplateProviderComponent extends Component<Args> {
34
65
  }
35
66
 
36
67
  templateIsApplicable(template: TemplateModel) {
37
- const containsTypes = this.controller.datastore
38
- .match(null, 'a')
39
- .dataset.some((quad) => {
40
- return template.contexts.includes(quad.object.value);
41
- });
42
-
43
- const containsDisabledTypes = this.controller.datastore
44
- .match(null, 'a')
45
- .dataset.some((quad) =>
46
- template.disabledInContexts.includes(quad.object.value)
47
- );
68
+ const { $from } = this.controller.state.selection;
69
+ const containsTypes =
70
+ this.controller.externalContextStore
71
+ .match(null, 'a')
72
+ .dataset.some((quad) => {
73
+ return template.contexts.includes(quad.object.value);
74
+ }) ||
75
+ findAncestors($from, (node) => {
76
+ return template.contexts.some((type) =>
77
+ pnodeHasRdfaAttribute(node, 'typeof', HACKY_LOOKUP[type])
78
+ );
79
+ }).length;
80
+ const containsDisabledTypes =
81
+ this.controller.externalContextStore
82
+ .match(null, 'a')
83
+ .dataset.some((quad) => {
84
+ return template.disabledInContexts.includes(quad.object.value);
85
+ }) ||
86
+ findAncestors($from, (node) => {
87
+ return template.disabledInContexts.some((type) =>
88
+ pnodeHasRdfaAttribute(node, 'typeof', HACKY_LOOKUP[type])
89
+ );
90
+ }).length;
48
91
 
49
92
  return containsTypes && !containsDisabledTypes;
50
93
  }
@@ -3,9 +3,8 @@ import Component from '@glimmer/component';
3
3
  import { PNode } from '@lblod/ember-rdfa-editor';
4
4
  import { EmberNodeArgs } from '@lblod/ember-rdfa-editor/utils/ember-node';
5
5
  import { Selection } from '@lblod/ember-rdfa-editor';
6
- import { getRdfaAttribute } from '@lblod/ember-rdfa-editor/utils/rdfa-utils';
7
- import { unwrap } from '@lblod/ember-rdfa-editor/utils/option';
8
- import { TableOfContentsConfig } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/table-of-contents-plugin/utils/constants';
6
+ import { NodeWithPos } from '@curvenote/prosemirror-utils';
7
+ import { TableOfContentsConfig } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/table-of-contents-plugin';
9
8
  type OutlineEntry = {
10
9
  content: string;
11
10
  pos: number;
@@ -33,34 +32,32 @@ export default class TableOfContentsComponent extends Component<EmberNodeArgs> {
33
32
  extractOutline({ node, pos }: { node: PNode; pos: number }): OutlineEntry[] {
34
33
  let result: OutlineEntry[] = [];
35
34
  let parent: OutlineEntry | undefined;
36
- const properties = getRdfaAttribute(node, 'property').pop();
37
- const resource = getRdfaAttribute(node, 'resource').pop();
38
- if (properties && resource) {
39
- for (const tocConfigEntry of this.config) {
40
- if (
41
- tocConfigEntry.sectionPredicate.some((pred) =>
42
- properties.includes(pred)
43
- )
44
- ) {
45
- if (typeof tocConfigEntry.value === 'string') {
46
- parent = { content: tocConfigEntry.value, pos };
47
- break;
48
- } else {
49
- const range = [
50
- ...this.args.controller.datastore
51
- .match(`>${resource}`, `>${tocConfigEntry.value.predicate}`)
52
- .asPredicateNodeMapping()
53
- .nodes(),
54
- ][0];
55
- if (range) {
56
- const node = unwrap(this.controller.state.doc.nodeAt(range.from));
57
- parent = {
58
- content: node.textContent,
59
- pos: range.from,
60
- };
61
- break;
35
+ for (const option of this.config) {
36
+ const { nodeHierarchy } = option;
37
+ if (RegExp(`^${nodeHierarchy[0]}$`).exec(node.type.name)) {
38
+ let i = 1;
39
+ let currentNode: NodeWithPos | undefined = { node, pos };
40
+ while (currentNode && i < nodeHierarchy.length) {
41
+ let newCurrentNode: NodeWithPos | undefined;
42
+ currentNode.node.forEach((child, offset) => {
43
+ if (RegExp(`^${nodeHierarchy[i]}$`).exec(child.type.name)) {
44
+ newCurrentNode = { pos: pos + offset, node: child };
45
+ return;
62
46
  }
63
- }
47
+ });
48
+ currentNode = newCurrentNode;
49
+ i++;
50
+ }
51
+ if (currentNode) {
52
+ const outlineText = currentNode.node.type.spec.outlineText as
53
+ | ((node: PNode) => string)
54
+ | undefined;
55
+ const content =
56
+ outlineText?.(currentNode.node) ?? currentNode.node.textContent;
57
+ parent = {
58
+ pos: currentNode.pos,
59
+ content,
60
+ };
64
61
  }
65
62
  }
66
63
  }
@@ -0,0 +1,8 @@
1
+ <label class="au-c-toggle-switch">
2
+ <input type="checkbox"
3
+ checked={{this.toggled}}
4
+ class="au-c-toggle-switch__input au-u-hidden-visually"
5
+ {{on "input" this.toggle}}/>
6
+ <span class="au-c-toggle-switch__toggle"></span>
7
+ <span class="au-c-toggle-switch__label">{{t "table-of-contents-plugin.toggle" }}</span>
8
+ </label>
@@ -1,16 +1,9 @@
1
1
  import { action } from '@ember/object';
2
2
  import Component from '@glimmer/component';
3
- import {
4
- TableOfContentsConfig,
5
- TABLE_OF_CONTENTS_DEFAULT_CONFIG,
6
- } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/table-of-contents-plugin/utils/constants';
7
3
  import { ProseController } from '@lblod/ember-rdfa-editor/core/prosemirror';
8
4
 
9
5
  type Args = {
10
6
  controller: ProseController;
11
- widgetArgs: {
12
- config: TableOfContentsConfig;
13
- };
14
7
  };
15
8
 
16
9
  export default class TableOfContentsCardComponent extends Component<Args> {
@@ -33,10 +26,6 @@ export default class TableOfContentsCardComponent extends Component<Args> {
33
26
  return result;
34
27
  }
35
28
 
36
- get config() {
37
- return this.args.widgetArgs.config ?? TABLE_OF_CONTENTS_DEFAULT_CONFIG;
38
- }
39
-
40
29
  @action
41
30
  toggle() {
42
31
  if (this.tableOfContentsRange) {
@@ -47,13 +36,7 @@ export default class TableOfContentsCardComponent extends Component<Args> {
47
36
  } else {
48
37
  const { schema } = this.controller;
49
38
  this.controller.withTransaction((tr) => {
50
- return tr.replaceRangeWith(
51
- 0,
52
- 0,
53
- schema.node('table_of_contents', {
54
- config: this.config,
55
- })
56
- );
39
+ return tr.replaceRangeWith(0, 0, schema.node('table_of_contents'));
57
40
  });
58
41
  }
59
42
  }
@@ -1,9 +1,8 @@
1
- <div {{did-update this.selectionChanged @controller.state}}>
2
1
  {{#if this.showCard}}
3
2
  <AuCard @flex={{true}} @divided={{true}} @isOpenInitially={{true}} @expandable={{true}} @shadow={{true}} @size="small" as |c|>
4
3
  <c.header>
5
4
  <AuHeading @level="3" @skin="6">
6
- {{t "insert-variable-plugin.variable"}}
5
+ {{t "variable-plugin.insertVariable"}}
7
6
  </AuHeading>
8
7
  </c.header>
9
8
  <c.content>
@@ -27,8 +26,9 @@
27
26
  {{subtype.label}}
28
27
  </PowerSelect>
29
28
  {{/if}}
30
- <AuButton {{on 'click' this.insert}} @disabled={{or (not this.selectedVariable) (and this.hasSubtype (not this.selectedSubtype))}}>{{t "insert-variable-plugin.button"}}</AuButton>
29
+ <AuButton {{on 'click' this.insert}} @disabled={{or (not this.selectedVariable)
30
+ (and this.hasSubtype (not this.selectedSubtype))}}>{{t
31
+ "variable-plugin.button"}}</AuButton>
31
32
  </c.content>
32
33
  </AuCard>
33
34
  {{/if}}
34
- </div>
@@ -2,14 +2,14 @@ import Component from '@glimmer/component';
2
2
  import { tracked } from '@glimmer/tracking';
3
3
  import { action } from '@ember/object';
4
4
  import { task } from 'ember-concurrency';
5
- import { v4 as uuidv4 } from 'uuid';
6
5
  import { ProseController } from '@lblod/ember-rdfa-editor/core/prosemirror';
7
- import { insertHtml } from '@lblod/ember-rdfa-editor/commands/insert-html-command';
8
6
  import {
9
7
  DEFAULT_VARIABLE_TYPES,
10
8
  VariableType,
11
- } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/insert-variable-plugin/utils/constants';
12
- import { CodeList } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/insert-variable-plugin/utils/fetch-data';
9
+ } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/constants';
10
+ import { CodeList } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/fetch-data';
11
+ import { findParentNodeOfType } from '@curvenote/prosemirror-utils';
12
+ import { NodeSelection } from '@lblod/ember-rdfa-editor';
13
13
  type Args = {
14
14
  controller: ProseController;
15
15
  widgetArgs: {
@@ -24,7 +24,6 @@ type Args = {
24
24
  export default class EditorPluginsInsertCodelistCardComponent extends Component<Args> {
25
25
  @tracked variablesArray: VariableType[];
26
26
  @tracked selectedVariable?: VariableType;
27
- @tracked showCard = true;
28
27
  @tracked hasSubtype = false;
29
28
  @tracked selectedSubtype?: CodeList;
30
29
  @tracked subtypes?: CodeList[];
@@ -68,19 +67,14 @@ export default class EditorPluginsInsertCodelistCardComponent extends Component<
68
67
  if (!this.selectedVariable) {
69
68
  return;
70
69
  }
71
- const uri = `http://data.lblod.info/mappings/${uuidv4()}`;
72
- let variableContent;
73
- if (typeof this.selectedVariable.template === 'function') {
74
- variableContent = this.selectedVariable.template(
75
- this.endpoint,
76
- this.selectedSubtype
77
- );
78
- } else {
79
- variableContent = this.selectedVariable.template;
80
- }
81
- const htmlToInsert = `<span resource="${uri}" typeof="ext:Mapping">${variableContent}</span>`;
82
- const { from, to } = this.args.controller.state.selection;
83
- this.args.controller.doCommand(insertHtml(htmlToInsert, from, to));
70
+ const node = this.selectedVariable.constructor(
71
+ this.args.controller.schema,
72
+ this.endpoint,
73
+ this.selectedSubtype
74
+ );
75
+ this.args.controller.withTransaction((tr) => {
76
+ return tr.replaceSelectionWith(node);
77
+ });
84
78
  }
85
79
 
86
80
  @action
@@ -111,24 +105,21 @@ export default class EditorPluginsInsertCodelistCardComponent extends Component<
111
105
  this.selectedSubtype = subtype;
112
106
  }
113
107
 
114
- @action
115
- selectionChanged() {
116
- const currentSelection = this.args.controller.state.selection;
117
- this.showCard = false;
118
- const limitedDatastore = this.args.controller.datastore.limitToRange(
119
- this.args.controller.state,
120
- currentSelection.from,
121
- currentSelection.to
122
- );
123
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
124
- const quad = limitedDatastore
125
- .match(null, 'a', 'ext:Mapping')
126
- .asQuadResultSet()
127
- .first();
128
- if (quad) {
129
- this.showCard = false;
108
+ get showCard() {
109
+ if (this.args.controller.inEmbeddedView) {
110
+ return false;
111
+ }
112
+ const { selection } = this.args.controller.state;
113
+ if (
114
+ selection instanceof NodeSelection &&
115
+ selection.node.type === this.args.controller.schema.nodes.variable
116
+ ) {
117
+ return false;
130
118
  } else {
131
- this.showCard = true;
119
+ const variable = findParentNodeOfType(
120
+ this.args.controller.schema.nodes.variable
121
+ )(selection);
122
+ return !variable;
132
123
  }
133
124
  }
134
125
  }
@@ -3,7 +3,7 @@
3
3
  <AuCard @flex={{true}} @divided={{true}} @isOpenInitially={{true}} @expandable={{true}} @shadow={{true}} @size="small" as |c|>
4
4
  <c.header>
5
5
  <AuHeading @level="3" @skin="6">
6
- Maatregel parameters
6
+ {{t "variable-plugin.enterVariableValue"}}
7
7
  </AuHeading>
8
8
  </c.header>
9
9
  <c.content>
@@ -12,8 +12,8 @@
12
12
  @allowClear={{false}}
13
13
  @searchEnabled={{false}}
14
14
  @options={{this.variableOptions}}
15
- @selected={{this.selectedVariable}}
16
- @onChange={{this.updateVariable}} as |variable|
15
+ @selected={{this.selectedVariableOption}}
16
+ @onChange={{this.updateVariableOption}} as |variable|
17
17
  >
18
18
  {{variable.label}}
19
19
  </PowerSelectMultiple>
@@ -22,13 +22,13 @@
22
22
  @allowClear={{false}}
23
23
  @searchEnabled={{false}}
24
24
  @options={{this.variableOptions}}
25
- @selected={{this.selectedVariable}}
26
- @onChange={{this.updateVariable}} as |variable|
25
+ @selected={{this.selectedVariableOption}}
26
+ @onChange={{this.updateVariableOption}} as |variable|
27
27
  >
28
28
  {{variable.label}}
29
29
  </PowerSelect>
30
30
  {{/if}}
31
- <AuButton {{on 'click' this.insert}} @disabled={{not this.selectedVariable}}>Voeg in</AuButton>
31
+ <AuButton {{on 'click' this.insert}} @disabled={{not this.selectedVariableOption}}>Voeg in</AuButton>
32
32
  </c.content>
33
33
  </AuCard>
34
34
  {{/if}}