@lblod/ember-rdfa-editor-lblod-plugins 1.0.0-beta.1 → 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 (98) hide show
  1. package/CHANGELOG.md +29 -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.ts +1 -1
  7. package/addon/components/citation-plugin/citation-insert.ts +1 -1
  8. package/addon/components/import-snippet-plugin/card.ts +8 -12
  9. package/addon/components/rdfa-date-plugin/card.hbs +28 -0
  10. package/addon/components/rdfa-date-plugin/card.ts +72 -38
  11. package/addon/components/rdfa-date-plugin/date-time-picker.ts +1 -0
  12. package/addon/components/rdfa-date-plugin/insert.hbs +2 -2
  13. package/addon/components/rdfa-date-plugin/insert.ts +14 -23
  14. package/addon/components/roadsign-regulation-plugin/roadsign-regulation-card.ts +24 -25
  15. package/addon/components/roadsign-regulation-plugin/roadsigns-modal.ts +36 -17
  16. package/addon/components/standard-template-plugin/template-provider.ts +54 -11
  17. package/addon/components/{insert-variable-plugin → variable-plugin}/insert-variable-card.hbs +4 -4
  18. package/addon/components/{insert-variable-plugin → variable-plugin}/insert-variable-card.ts +26 -35
  19. package/addon/components/{template-variable-plugin → variable-plugin}/template-variable-card.hbs +6 -6
  20. package/addon/components/variable-plugin/template-variable-card.ts +174 -0
  21. package/addon/components/variable-plugin/variable.hbs +4 -0
  22. package/addon/components/variable-plugin/variable.ts +250 -0
  23. package/addon/plugins/article-structure-plugin/commands/insert-structure.ts +4 -2
  24. package/addon/plugins/article-structure-plugin/index.ts +1 -1
  25. package/addon/plugins/article-structure-plugin/structures/article-paragraph.ts +6 -2
  26. package/addon/plugins/article-structure-plugin/structures/article.ts +1 -1
  27. package/addon/plugins/article-structure-plugin/structures/chapter.ts +1 -2
  28. package/addon/plugins/article-structure-plugin/structures/section.ts +1 -1
  29. package/addon/plugins/article-structure-plugin/structures/subsection.ts +1 -1
  30. package/addon/plugins/article-structure-plugin/structures/title.ts +1 -2
  31. package/addon/plugins/citation-plugin/index.ts +184 -113
  32. package/addon/plugins/rdfa-date-plugin/index.ts +42 -3
  33. package/addon/plugins/rdfa-date-plugin/nodes/date.ts +127 -0
  34. package/addon/plugins/rdfa-date-plugin/nodes/index.ts +1 -0
  35. package/addon/plugins/rdfa-date-plugin/utils.ts +10 -0
  36. package/addon/plugins/roadsign-regulation-plugin/nodes.ts +107 -0
  37. package/addon/plugins/standard-template-plugin/index.ts +26 -0
  38. package/addon/plugins/standard-template-plugin/utils/nodes.ts +366 -0
  39. package/addon/plugins/{insert-variable-plugin → variable-plugin}/index.ts +6 -1
  40. package/addon/plugins/variable-plugin/nodes.ts +137 -0
  41. package/addon/plugins/variable-plugin/utils/constants.ts +107 -0
  42. package/addon/plugins/{template-variable-plugin → variable-plugin}/utils/fetch-data.ts +41 -0
  43. package/addon/services/standard-template-plugin.ts +16 -12
  44. package/addon/utils/changed-descendants.ts +29 -0
  45. package/addon/utils/constants.ts +11 -0
  46. package/addon/utils/namespace.ts +42 -7
  47. package/app/components/au-dropdown-pill.js +1 -0
  48. package/app/components/{insert-variable-plugin → variable-plugin}/insert-variable-card.js +1 -1
  49. package/app/components/{template-variable-plugin → variable-plugin}/template-variable-card.js +1 -1
  50. package/app/components/variable-plugin/variable-edit-modal.js +1 -0
  51. package/app/components/variable-plugin/variable.js +1 -0
  52. package/app/styles/date-plugin.scss +17 -0
  53. package/app/styles/variable-plugin.scss +65 -0
  54. package/components/au-dropdown-pill.d.ts +19 -0
  55. package/components/au-native-input.d.ts +1 -1
  56. package/components/citation-plugin/citation-card.d.ts +1 -1
  57. package/components/rdfa-date-plugin/card.d.ts +14 -5
  58. package/components/rdfa-date-plugin/insert.d.ts +1 -2
  59. package/components/roadsign-regulation-plugin/roadsign-regulation-card.d.ts +1 -0
  60. package/components/roadsign-regulation-plugin/roadsigns-modal.d.ts +3 -0
  61. package/components/standard-template-plugin/template-provider.d.ts +6 -1
  62. package/components/{insert-variable-plugin → variable-plugin}/insert-variable-card.d.ts +3 -4
  63. package/components/{template-variable-plugin → variable-plugin}/template-variable-card.d.ts +8 -5
  64. package/components/variable-plugin/variable.d.ts +42 -0
  65. package/package.json +4 -4
  66. package/plugins/article-structure-plugin/commands/insert-structure.d.ts +2 -2
  67. package/plugins/article-structure-plugin/index.d.ts +1 -1
  68. package/plugins/citation-plugin/index.d.ts +11 -4
  69. package/plugins/rdfa-date-plugin/index.d.ts +13 -1
  70. package/plugins/rdfa-date-plugin/nodes/date.d.ts +9 -0
  71. package/plugins/rdfa-date-plugin/nodes/index.d.ts +1 -0
  72. package/plugins/rdfa-date-plugin/utils.d.ts +1 -0
  73. package/plugins/roadsign-regulation-plugin/nodes.d.ts +2 -0
  74. package/plugins/standard-template-plugin/index.d.ts +12 -0
  75. package/plugins/standard-template-plugin/utils/nodes.d.ts +12 -0
  76. package/plugins/{insert-variable-plugin → variable-plugin}/index.d.ts +1 -0
  77. package/plugins/variable-plugin/nodes.d.ts +2 -0
  78. package/plugins/variable-plugin/utils/constants.d.ts +9 -0
  79. package/plugins/{template-variable-plugin → variable-plugin}/utils/fetch-data.d.ts +5 -0
  80. package/services/standard-template-plugin.d.ts +9 -10
  81. package/translations/en-US.yaml +4 -3
  82. package/translations/nl-BE.yaml +5 -4
  83. package/utils/changed-descendants.d.ts +2 -0
  84. package/utils/constants.d.ts +5 -0
  85. package/utils/namespace.d.ts +8 -3
  86. package/addon/components/template-variable-plugin/template-variable-card.ts +0 -227
  87. package/addon/plugins/insert-variable-plugin/utils/constants.ts +0 -67
  88. package/addon/plugins/insert-variable-plugin/utils/fetch-data.ts +0 -41
  89. package/addon/plugins/rdfa-date-plugin/commands/index.ts +0 -1
  90. package/addon/plugins/rdfa-date-plugin/commands/modify-date.ts +0 -48
  91. package/addon/plugins/template-variable-plugin/index.ts +0 -6
  92. package/addon/plugins/template-variable-plugin/utils/constants.ts +0 -2
  93. package/plugins/insert-variable-plugin/utils/constants.d.ts +0 -7
  94. package/plugins/insert-variable-plugin/utils/fetch-data.d.ts +0 -5
  95. package/plugins/rdfa-date-plugin/commands/index.d.ts +0 -1
  96. package/plugins/rdfa-date-plugin/commands/modify-date.d.ts +0 -2
  97. package/plugins/template-variable-plugin/index.d.ts +0 -2
  98. package/plugins/template-variable-plugin/utils/constants.d.ts +0 -1
@@ -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
  }
@@ -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}}
@@ -0,0 +1,174 @@
1
+ import Component from '@glimmer/component';
2
+ import { tracked } from '@glimmer/tracking';
3
+ import { action } from '@ember/object';
4
+ import { getOwner } from '@ember/application';
5
+ import { task } from 'ember-concurrency';
6
+ import { ProseController } from '@lblod/ember-rdfa-editor/core/prosemirror';
7
+ import { unwrap } from '@lblod/ember-rdfa-editor/utils/option';
8
+ import {
9
+ CodeListOption,
10
+ fetchCodeListOptions,
11
+ } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/fetch-data';
12
+ import { MULTI_SELECT_CODELIST_TYPE } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/constants';
13
+ import { findParentNodeOfType } from '@curvenote/prosemirror-utils';
14
+ import { NodeSelection, PNode, ProseParser } from '@lblod/ember-rdfa-editor';
15
+ import { ZONAL_URI } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/roadsign-regulation-plugin/utils/constants';
16
+
17
+ type Args = {
18
+ controller: ProseController;
19
+ };
20
+ export default class EditorPluginsTemplateVariableCardComponent extends Component<Args> {
21
+ @tracked variableOptions: CodeListOption[] = [];
22
+ @tracked selectedVariableOption?: CodeListOption | CodeListOption[];
23
+ @tracked selectedVariable: { pos: number; node: PNode } | undefined;
24
+ @tracked showCard = false;
25
+ @tracked multiSelect = false;
26
+ mappingUri?: string;
27
+ zonalLocationCodelistUri: string;
28
+ endpoint: string;
29
+ nonZonalLocationCodelistUri: string;
30
+
31
+ constructor(parent: unknown, args: Args) {
32
+ super(parent, args);
33
+ const config = getOwner(this)?.resolveRegistration(
34
+ 'config:environment'
35
+ ) as {
36
+ templateVariablePlugin: {
37
+ zonalLocationCodelistUri: string;
38
+ endpoint: string;
39
+ nonZonalLocationCodelistUri: string;
40
+ };
41
+ };
42
+ const pluginConfig = config.templateVariablePlugin;
43
+ this.zonalLocationCodelistUri = pluginConfig.zonalLocationCodelistUri;
44
+ this.endpoint = pluginConfig.endpoint;
45
+ this.nonZonalLocationCodelistUri = pluginConfig.nonZonalLocationCodelistUri;
46
+ }
47
+
48
+ get controller() {
49
+ return this.args.controller;
50
+ }
51
+
52
+ @action
53
+ insert() {
54
+ if (!this.selectedVariable || !this.selectedVariableOption) {
55
+ return;
56
+ }
57
+ let htmlToInsert: string;
58
+ if (Array.isArray(this.selectedVariableOption)) {
59
+ htmlToInsert = this.selectedVariableOption
60
+ .map((variable) => variable.value)
61
+ .join(', ');
62
+ } else {
63
+ htmlToInsert = unwrap(this.selectedVariableOption.value);
64
+ }
65
+ htmlToInsert = this.wrapVariableInHighlight(htmlToInsert);
66
+ const domParser = new DOMParser();
67
+ const htmlNode = domParser.parseFromString(htmlToInsert, 'text/html');
68
+ const contentFragment = ProseParser.fromSchema(
69
+ this.args.controller.schema
70
+ ).parseSlice(htmlNode, {
71
+ preserveWhitespace: false,
72
+ }).content;
73
+ const range = {
74
+ from: this.selectedVariable.pos + 1,
75
+ to: this.selectedVariable.pos + this.selectedVariable.node.nodeSize - 1,
76
+ };
77
+ this.controller.withTransaction((tr) => {
78
+ return tr.replaceWith(range.from, range.to, contentFragment);
79
+ });
80
+ }
81
+
82
+ wrapVariableInHighlight(text: string) {
83
+ return text.replace(
84
+ /\$\{(.+?)\}/g,
85
+ '<span class="mark-highlight-manual">${$1}</span>'
86
+ );
87
+ }
88
+
89
+ @action
90
+ selectionChanged() {
91
+ this.showCard = false;
92
+ this.selectedVariableOption = undefined;
93
+ const { selection } = this.controller.state;
94
+ if (
95
+ selection instanceof NodeSelection &&
96
+ selection.node.type === this.controller.schema.nodes.variable
97
+ ) {
98
+ const variable = {
99
+ node: selection.node,
100
+ pos: selection.from,
101
+ };
102
+ this.selectedVariable = variable;
103
+ if (variable) {
104
+ const type = variable.node.attrs.type as string;
105
+ if (type === 'codelist') {
106
+ const source =
107
+ (variable.node.attrs.source as string | undefined) ?? this.endpoint;
108
+ const codelistURI = variable.node.attrs.codelistResource as string;
109
+ void this.fetchCodeListOptions.perform(source, codelistURI);
110
+ this.showCard = true;
111
+ } else if (type === 'location') {
112
+ const source =
113
+ (variable.node.attrs.source as string | undefined) ?? this.endpoint;
114
+ const roadSignRegulation = findParentNodeOfType(
115
+ this.controller.schema.nodes.roadsign_regulation
116
+ )(selection);
117
+ const zonalityUri = roadSignRegulation?.node.attrs.zonality as
118
+ | string
119
+ | undefined;
120
+ if (zonalityUri === ZONAL_URI) {
121
+ void this.fetchCodeListOptions.perform(
122
+ source,
123
+ this.zonalLocationCodelistUri,
124
+ true
125
+ );
126
+ } else {
127
+ void this.fetchCodeListOptions.perform(
128
+ source,
129
+ this.nonZonalLocationCodelistUri,
130
+ true
131
+ );
132
+ }
133
+
134
+ this.showCard = true;
135
+ }
136
+ }
137
+ }
138
+ }
139
+
140
+ @action
141
+ updateVariableOption(variableOption: CodeListOption | CodeListOption[]) {
142
+ this.selectedVariableOption = variableOption;
143
+ }
144
+
145
+ fetchCodeListOptions = task(
146
+ async (endpoint: string, codelistUri: string, isLocation?: boolean) => {
147
+ const { type, options } = await fetchCodeListOptions(
148
+ endpoint,
149
+ codelistUri
150
+ );
151
+ if (isLocation) {
152
+ this.variableOptions = options.map((option) => ({
153
+ label: option.label,
154
+ value: this.wrapInLocation(unwrap(option.value)),
155
+ }));
156
+ } else {
157
+ this.variableOptions = options;
158
+ }
159
+ if (type === MULTI_SELECT_CODELIST_TYPE) {
160
+ this.multiSelect = true;
161
+ } else {
162
+ this.multiSelect = false;
163
+ }
164
+ }
165
+ );
166
+
167
+ wrapInLocation(value: string) {
168
+ return `
169
+ <span property="https://data.vlaanderen.be/ns/mobiliteit#plaatsbepaling">
170
+ ${value}
171
+ </span>
172
+ `;
173
+ }
174
+ }
@@ -0,0 +1,4 @@
1
+ <AuPill @icon="pencil" @iconAlignment="right" class="variable">
2
+ <div {{did-insert this.didInsertContentWrapper}} {{did-update this.onNodeUpdate @node}}>
3
+ </div>
4
+ </AuPill>
@@ -0,0 +1,250 @@
1
+ /**
2
+ *
3
+ * Based on the footnotes example from https://github.com/ProseMirror/website
4
+ *
5
+ * Copyright (C) 2015-2017 by Marijn Haverbeke <marijnh@gmail.com> and others
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
24
+
25
+ import { action } from '@ember/object';
26
+ import { inject as service } from '@ember/service';
27
+ import { htmlSafe } from '@ember/template';
28
+ import Component from '@glimmer/component';
29
+ import {
30
+ chainCommands,
31
+ createParagraphNear,
32
+ DOMSerializer,
33
+ EditorState,
34
+ keymap,
35
+ liftEmptyBlock,
36
+ newlineInCode,
37
+ NodeSelection,
38
+ RdfaEditorView,
39
+ redo,
40
+ Schema,
41
+ splitBlock,
42
+ StepMap,
43
+ Transaction,
44
+ undo,
45
+ } from '@lblod/ember-rdfa-editor';
46
+ import { date } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/rdfa-date-plugin/nodes';
47
+ import {
48
+ isSome,
49
+ unwrap,
50
+ } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/option';
51
+ import { insertHardBreak } from '@lblod/ember-rdfa-editor/commands/insert-hard-break';
52
+ import { toggleMarkAddFirst } from '@lblod/ember-rdfa-editor/commands/toggle-mark-add-first';
53
+ import {
54
+ link,
55
+ em,
56
+ strong,
57
+ underline,
58
+ strikethrough,
59
+ } from '@lblod/ember-rdfa-editor/marks';
60
+ import {
61
+ block_rdfa,
62
+ hard_break,
63
+ placeholder,
64
+ text,
65
+ paragraph,
66
+ repaired_block,
67
+ } from '@lblod/ember-rdfa-editor/nodes';
68
+ import {
69
+ inline_rdfa,
70
+ invisible_rdfa,
71
+ } from '@lblod/ember-rdfa-editor/nodes/inline-rdfa';
72
+ import { EmberNodeArgs } from '@lblod/ember-rdfa-editor/utils/ember-node';
73
+ import IntlService from 'ember-intl/services/intl';
74
+
75
+ export default class Variable extends Component<EmberNodeArgs> {
76
+ @service declare intl: IntlService;
77
+ innerView: RdfaEditorView | null = null;
78
+
79
+ contentWrapper: Element | null = null;
80
+
81
+ get outerView() {
82
+ return this.args.view;
83
+ }
84
+
85
+ get node() {
86
+ return this.args.node;
87
+ }
88
+
89
+ get pos() {
90
+ return this.args.getPos();
91
+ }
92
+
93
+ get htmlContent() {
94
+ const fragment = DOMSerializer.fromSchema(this.schema).serializeFragment(
95
+ this.node.content,
96
+ {
97
+ document,
98
+ }
99
+ );
100
+ const div = document.createElement('div');
101
+ div.appendChild(fragment);
102
+ return htmlSafe(div.innerHTML);
103
+ }
104
+
105
+ get schema() {
106
+ return new Schema({
107
+ nodes: {
108
+ doc: {
109
+ content: 'block+',
110
+ },
111
+ paragraph,
112
+ date: date({
113
+ placeholder: {
114
+ insertDate: this.intl.t('date-plugin.insert.date'),
115
+ insertDateTime: this.intl.t('date-plugin.insert.datetime'),
116
+ },
117
+ }),
118
+ repaired_block,
119
+ placeholder,
120
+
121
+ text,
122
+
123
+ hard_break,
124
+ block_rdfa,
125
+ invisible_rdfa,
126
+ },
127
+ marks: {
128
+ inline_rdfa,
129
+ link,
130
+ em,
131
+ strong,
132
+ underline,
133
+ strikethrough,
134
+ },
135
+ });
136
+ }
137
+
138
+ @action
139
+ onFocus() {
140
+ const outerSelectionTr = this.outerView.state.tr;
141
+ const outerSelection = new NodeSelection(
142
+ this.outerView.state.doc.resolve(this.pos)
143
+ );
144
+ outerSelectionTr.setSelection(outerSelection);
145
+ this.outerView.dispatch(outerSelectionTr);
146
+ }
147
+
148
+ @action
149
+ didInsertContentWrapper(target: Element) {
150
+ this.contentWrapper = target;
151
+ this.innerView = new RdfaEditorView(this.contentWrapper, {
152
+ state: EditorState.create({
153
+ doc: this.node,
154
+ plugins: [
155
+ keymap({
156
+ 'Mod-z': () =>
157
+ undo(this.outerView.state, this.outerView.dispatch.bind(this)),
158
+ 'Mod-Z': () =>
159
+ undo(this.outerView.state, this.outerView.dispatch.bind(this)),
160
+ 'Mod-y': () =>
161
+ redo(this.outerView.state, this.outerView.dispatch.bind(this)),
162
+ 'Mod-Y': () =>
163
+ redo(this.outerView.state, this.outerView.dispatch.bind(this)),
164
+ 'Mod-b': toggleMarkAddFirst(this.schema.marks.strong),
165
+ 'Mod-B': toggleMarkAddFirst(this.schema.marks.strong),
166
+ 'Mod-i': toggleMarkAddFirst(this.schema.marks.em),
167
+ 'Mod-I': toggleMarkAddFirst(this.schema.marks.em),
168
+ 'Mod-u': toggleMarkAddFirst(this.schema.marks.underline),
169
+ 'Mod-U': toggleMarkAddFirst(this.schema.marks.underline),
170
+ Enter: chainCommands(
171
+ newlineInCode,
172
+ createParagraphNear,
173
+ liftEmptyBlock,
174
+ splitBlock,
175
+ insertHardBreak
176
+ ),
177
+ }),
178
+ ],
179
+ schema: this.schema,
180
+ }),
181
+ dispatchTransaction: this.dispatchInner,
182
+ handleDOMEvents: {
183
+ mousedown: () => {
184
+ // Kludge to prevent issues due to the fact that the whole
185
+ // footnote is node-selected (and thus DOM-selected) when
186
+ // the parent editor is focused.
187
+
188
+ if (this.outerView.hasFocus()) this.innerView?.focus();
189
+ },
190
+ focus: () => {
191
+ const outerSelectionTr = this.outerView.state.tr;
192
+ const outerSelection = new NodeSelection(
193
+ this.outerView.state.doc.resolve(this.pos)
194
+ );
195
+ outerSelectionTr.setSelection(outerSelection);
196
+ this.outerView.dispatch(outerSelectionTr);
197
+ if (this.innerView) {
198
+ this.args.controller.setEmbeddedView(this.innerView);
199
+ }
200
+ },
201
+ },
202
+ });
203
+ }
204
+
205
+ @action
206
+ onNodeUpdate() {
207
+ if (this.innerView) {
208
+ const state = this.innerView.state;
209
+ const start = this.node.content.findDiffStart(state.doc.content);
210
+ const end = this.node.content.findDiffEnd(state.doc.content);
211
+ if (isSome(start) && isSome(end)) {
212
+ let { a: endA, b: endB } = end;
213
+ const overlap = start - Math.min(endA, endB);
214
+ if (overlap > 0) {
215
+ endA += overlap;
216
+ endB += overlap;
217
+ }
218
+ this.innerView.dispatch(
219
+ state.tr
220
+ .replace(start, endB, this.node.slice(start, endA))
221
+ .setMeta('fromOutside', true)
222
+ );
223
+ }
224
+ }
225
+ }
226
+
227
+ dispatchInner = (tr: Transaction) => {
228
+ if (this.innerView) {
229
+ const { state, transactions } = this.innerView.state.applyTransaction(tr);
230
+ this.innerView.updateState(state);
231
+
232
+ if (!tr.getMeta('fromOutside')) {
233
+ const outerTr = this.outerView.state.tr,
234
+ offsetMap = StepMap.offset(this.pos + 1);
235
+ for (let i = 0; i < transactions.length; i++) {
236
+ const steps = transactions[i].steps;
237
+ for (let j = 0; j < steps.length; j++)
238
+ outerTr.step(unwrap(steps[j].map(offsetMap)));
239
+ }
240
+ if (outerTr.docChanged) this.outerView.dispatch(outerTr);
241
+ }
242
+ }
243
+ };
244
+
245
+ willDestroy(): void {
246
+ super.willDestroy();
247
+ this.innerView?.destroy();
248
+ this.innerView = null;
249
+ }
250
+ }
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  Command,
3
+ Fragment,
3
4
  NodeSelection,
4
5
  NodeType,
5
6
  PNode,
@@ -16,7 +17,8 @@ import { containsOnlyPlaceholder } from '../utils/structure';
16
17
 
17
18
  const insertStructure = (
18
19
  structureSpec: StructureSpec,
19
- intl: IntlService
20
+ intl: IntlService,
21
+ content?: Fragment
20
22
  ): Command => {
21
23
  return (state, dispatch) => {
22
24
  const { schema, selection, doc } = state;
@@ -31,7 +33,7 @@ const insertStructure = (
31
33
  }
32
34
  if (dispatch) {
33
35
  const { node: newStructureNode, selectionConfig } =
34
- structureSpec.constructor({ schema, intl });
36
+ structureSpec.constructor({ schema, intl, content });
35
37
  const transaction = state.tr;
36
38
 
37
39
  transaction.replaceWith(