@lblod/ember-rdfa-editor-lblod-plugins 32.7.0 → 32.8.0-dev.ccd8888d1efc5ccdedb5c16e6a952e3a0892d760
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.
- package/.changeset/tender-actors-shout.md +5 -0
- package/CHANGELOG.md +17 -0
- package/addon/components/besluit-topic-plugin/besluit-topic-toolbar-dropdown.ts +1 -1
- package/addon/components/besluit-type-plugin/toolbar-dropdown.gts +1 -1
- package/addon/components/decision-plugin/decision-plugin-card.gts +3 -2
- package/addon/components/decision-plugin/insert-article.gts +1 -1
- package/addon/components/document-validation-plugin/card.gts +130 -33
- package/addon/components/lpdc-plugin/lpdc-insert.ts +1 -1
- package/addon/components/roadsign-regulation-plugin/roadsign-regulation-card.gts +1 -1
- package/addon/components/roadsign-regulation-plugin/roadsigns-modal.gts +1 -1
- package/addon/plugins/besluit-type-plugin/utils/besluit-type-instances.ts +1 -1
- package/addon/plugins/besluit-type-plugin/utils/set-besluit-type.ts +1 -1
- package/addon/plugins/decision-plugin/commands/insert-article-container.ts +14 -1
- package/addon/plugins/decision-plugin/commands/insert-description.ts +9 -1
- package/addon/plugins/decision-plugin/commands/insert-motivation.ts +9 -1
- package/addon/plugins/decision-plugin/commands/insert-title.ts +9 -1
- package/addon/plugins/document-validation-plugin/common-fixes.ts +126 -0
- package/addon/plugins/document-validation-plugin/index.ts +61 -32
- package/addon/plugins/roadsign-regulation-plugin/actions/insert-measure.ts +4 -2
- package/addon/plugins/roadsign-regulation-plugin/constants.ts +3 -3
- package/addon/plugins/roadsign-regulation-plugin/nodes.ts +76 -2
- package/addon/plugins/roadsign-regulation-plugin/queries/road-sign-category.ts +1 -1
- package/addon/plugins/roadsign-regulation-plugin/queries/traffic-signal-concept.ts +5 -0
- package/addon/plugins/roadsign-regulation-plugin/schemas/traffic-signal-concept.ts +1 -0
- package/addon/plugins/structure-plugin/commands/move-structure.ts +6 -19
- package/addon/plugins/structure-plugin/monads/recalculate-structure-numbers.ts +3 -0
- package/addon/plugins/variable-plugin/utils/recreate-variable-uris.ts +0 -5
- package/addon/services/import-rdfa-snippet.ts +1 -5
- package/addon/{plugins/besluit-topic-plugin/utils/helpers.ts → utils/decision-utils.ts} +33 -9
- package/declarations/addon/components/document-validation-plugin/card.d.ts +51 -1
- package/declarations/addon/components/roadsign-regulation-plugin/roadsigns-modal.d.ts +2 -0
- package/declarations/addon/plugins/decision-plugin/commands/insert-article-container.d.ts +3 -1
- package/declarations/addon/plugins/document-validation-plugin/common-fixes.d.ts +6 -0
- package/declarations/addon/plugins/document-validation-plugin/index.d.ts +30 -6
- package/declarations/addon/plugins/roadsign-regulation-plugin/constants.d.ts +6 -6
- package/declarations/addon/plugins/roadsign-regulation-plugin/nodes.d.ts +6 -0
- package/declarations/addon/plugins/roadsign-regulation-plugin/queries/mobility-measure-concept.d.ts +1 -0
- package/declarations/addon/plugins/roadsign-regulation-plugin/queries/traffic-signal-concept.d.ts +2 -0
- package/declarations/addon/plugins/roadsign-regulation-plugin/schemas/mobility-measure-concept.d.ts +5 -0
- package/declarations/addon/plugins/roadsign-regulation-plugin/schemas/traffic-signal-concept.d.ts +3 -0
- package/declarations/addon/{plugins/besluit-topic-plugin/utils/helpers.d.ts → utils/decision-utils.d.ts} +5 -1
- package/package.json +3 -3
- package/pnpm-lock.yaml +17 -11
- package/translations/en-US.yaml +1 -0
- package/translations/nl-BE.yaml +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @lblod/ember-rdfa-editor-lblod-plugins
|
|
2
2
|
|
|
3
|
+
## 32.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#603](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/603) [`8f109f8`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/8f109f8799741e529d627e4fdea03bb6cf47d181) Thanks [@lagartoverde](https://github.com/lagartoverde)! - IRGN: Use IRGN name when present for traffic signs
|
|
8
|
+
|
|
9
|
+
- [#605](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/605) [`40b481c`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/40b481cce0884e958174c10530cff019c4e53ddc) Thanks [@piemonkey](https://github.com/piemonkey)! - Update data model used for roadsigns to us correct classnames for different subclasses of traffic signal
|
|
10
|
+
|
|
11
|
+
- [#597](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/597) [`b04e6d2`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/b04e6d26c370dd3100fb674dc081eb1a53f445b8) Thanks [@piemonkey](https://github.com/piemonkey)! - Add model migration to update older roadsign regulation documents to the latest model
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#606](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/606) [`b4e4d9a`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/b4e4d9a502fdb07974f13894d0168dc3548b7ed2) Thanks [@elpoelma](https://github.com/elpoelma)! - Resolve issue where selection was not correctly set when moving articles around
|
|
16
|
+
Note: this solution only works when having `@lblod/ember-rdfa-editor` 12.14.0 or later installed in your host-app.
|
|
17
|
+
|
|
18
|
+
- [#597](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/597) [`533ccab`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/533ccab48508c9765e9dc7e176e63701fdb056d9) Thanks [@piemonkey](https://github.com/piemonkey)! - Update @lblod/ember-rdfa-editor to 12.13.0
|
|
19
|
+
|
|
3
20
|
## 32.7.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
import {
|
|
16
16
|
getCurrentBesluitRange,
|
|
17
17
|
getCurrentBesluitURI,
|
|
18
|
-
} from '@lblod/ember-rdfa-editor-lblod-plugins/
|
|
18
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/decision-utils';
|
|
19
19
|
import {
|
|
20
20
|
updateBesluitTopicResource,
|
|
21
21
|
TOPIC_PREDICATE,
|
|
@@ -16,7 +16,7 @@ import { CircleXIcon } from '@appuniversum/ember-appuniversum/components/icons/c
|
|
|
16
16
|
import { SayController } from '@lblod/ember-rdfa-editor';
|
|
17
17
|
import fetchBesluitTypes from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/besluit-type-plugin/utils/fetchBesluitTypes';
|
|
18
18
|
import { BesluitTypePluginOptions } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/besluit-type-plugin';
|
|
19
|
-
import { getCurrentBesluitRange } from '@lblod/ember-rdfa-editor-lblod-plugins/
|
|
19
|
+
import { getCurrentBesluitRange } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/decision-utils';
|
|
20
20
|
import {
|
|
21
21
|
BesluitTypeInstance,
|
|
22
22
|
checkBesluitTypeInstance,
|
|
@@ -23,7 +23,7 @@ import { on } from '@ember/modifier';
|
|
|
23
23
|
import { not } from 'ember-truth-helpers';
|
|
24
24
|
import t from 'ember-intl/helpers/t';
|
|
25
25
|
import { TemplateOnlyComponent } from '@ember/component/template-only';
|
|
26
|
-
import { getCurrentBesluitRange } from '@lblod/ember-rdfa-editor-lblod-plugins/
|
|
26
|
+
import { getCurrentBesluitRange } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/decision-utils';
|
|
27
27
|
|
|
28
28
|
interface DecisionCardOptions {
|
|
29
29
|
articleUriGenerator?: () => string;
|
|
@@ -145,12 +145,13 @@ export default class DecisionPluginCard extends Component<Sig> {
|
|
|
145
145
|
}
|
|
146
146
|
@action
|
|
147
147
|
insertArticleBlock() {
|
|
148
|
-
if (this.decisionUri) {
|
|
148
|
+
if (this.decisionUri && this.decisionNodeLocation) {
|
|
149
149
|
this.controller.doCommand(
|
|
150
150
|
insertArticleContainer({
|
|
151
151
|
intl: this.intl,
|
|
152
152
|
decisionUri: this.decisionUri,
|
|
153
153
|
articleUriGenerator: this.args.options?.articleUriGenerator,
|
|
154
|
+
decisionLocation: this.decisionNodeLocation,
|
|
154
155
|
}),
|
|
155
156
|
{
|
|
156
157
|
view: this.controller.mainEditorView,
|
|
@@ -4,7 +4,7 @@ import { action } from '@ember/object';
|
|
|
4
4
|
import Component from '@glimmer/component';
|
|
5
5
|
import { AddIcon } from '@appuniversum/ember-appuniversum/components/icons/add';
|
|
6
6
|
import { PNode, SayController } from '@lblod/ember-rdfa-editor';
|
|
7
|
-
import { getCurrentBesluitRange } from '@lblod/ember-rdfa-editor-lblod-plugins/
|
|
7
|
+
import { getCurrentBesluitRange } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/decision-utils';
|
|
8
8
|
import { buildArticleStructure } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/decision-plugin/utils/build-article-structure';
|
|
9
9
|
import { not } from 'ember-truth-helpers';
|
|
10
10
|
import { service } from '@ember/service';
|
|
@@ -12,6 +12,8 @@ import AuButton from '@appuniversum/ember-appuniversum/components/au-button';
|
|
|
12
12
|
import { ExternalLinkIcon } from '@appuniversum/ember-appuniversum/components/icons/external-link';
|
|
13
13
|
import t from 'ember-intl/helpers/t';
|
|
14
14
|
import { eq } from 'ember-truth-helpers';
|
|
15
|
+
import ValidationReport from 'rdf-validate-shacl/src/validation-report';
|
|
16
|
+
import { CircleInfoIcon } from '@appuniversum/ember-appuniversum/components/icons/circle-info';
|
|
15
17
|
|
|
16
18
|
interface Sig {
|
|
17
19
|
Args: {
|
|
@@ -19,6 +21,17 @@ interface Sig {
|
|
|
19
21
|
};
|
|
20
22
|
}
|
|
21
23
|
|
|
24
|
+
type ExtractWithKey<T, K extends PropertyKey> = T extends Record<K, unknown>
|
|
25
|
+
? T
|
|
26
|
+
: never;
|
|
27
|
+
|
|
28
|
+
function hasProperty<
|
|
29
|
+
O extends object = object,
|
|
30
|
+
K extends PropertyKey = PropertyKey,
|
|
31
|
+
>(obj: O, key: K): obj is ExtractWithKey<O, K> {
|
|
32
|
+
return key in obj;
|
|
33
|
+
}
|
|
34
|
+
|
|
22
35
|
export default class DocumentValidationPluginCard extends Component<Sig> {
|
|
23
36
|
get controller() {
|
|
24
37
|
return this.args.controller;
|
|
@@ -37,10 +50,26 @@ export default class DocumentValidationPluginCard extends Component<Sig> {
|
|
|
37
50
|
}
|
|
38
51
|
get documentValidationErrors() {
|
|
39
52
|
if (!this.validationState) return [];
|
|
40
|
-
|
|
53
|
+
|
|
54
|
+
const { propertiesWithErrors, rules } = this.validationState;
|
|
41
55
|
if (!propertiesWithErrors) return undefined;
|
|
42
56
|
|
|
43
|
-
|
|
57
|
+
const documentValidationErrors = propertiesWithErrors.map((property) => {
|
|
58
|
+
const rule = rules.find((rule) => property?.shape === rule.shaclRule);
|
|
59
|
+
if (rule && 'violations' in rule) {
|
|
60
|
+
const rulePerConstraint = rule.violations[property?.constraint];
|
|
61
|
+
return {
|
|
62
|
+
...property,
|
|
63
|
+
rule: rulePerConstraint,
|
|
64
|
+
};
|
|
65
|
+
} else {
|
|
66
|
+
return {
|
|
67
|
+
...property,
|
|
68
|
+
rule: rule,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return documentValidationErrors;
|
|
44
73
|
}
|
|
45
74
|
get propertiesWithoutErrors() {
|
|
46
75
|
if (!this.validationState) return [];
|
|
@@ -65,6 +94,53 @@ export default class DocumentValidationPluginCard extends Component<Sig> {
|
|
|
65
94
|
return ['valid', 'no-matches'].includes(this.status);
|
|
66
95
|
}
|
|
67
96
|
|
|
97
|
+
doActionAndTriggerValidation = async (
|
|
98
|
+
action: (controller: SayController, report: ValidationReport) => void,
|
|
99
|
+
) => {
|
|
100
|
+
action(this.controller, this.validationState?.report as ValidationReport);
|
|
101
|
+
const pluginState = documentValidationPluginKey.getState(
|
|
102
|
+
this.controller.mainEditorView.state,
|
|
103
|
+
);
|
|
104
|
+
if (!pluginState) return;
|
|
105
|
+
const { validationCallback } = pluginState;
|
|
106
|
+
await validationCallback(
|
|
107
|
+
this.controller.mainEditorView,
|
|
108
|
+
this.controller.htmlContent,
|
|
109
|
+
);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
oldVal: typeof this.documentValidationErrors;
|
|
113
|
+
|
|
114
|
+
dedupeDocumentValidationErrors = (
|
|
115
|
+
val: typeof this.documentValidationErrors,
|
|
116
|
+
) => {
|
|
117
|
+
if (this.compareDocumentValidationErrors(val, this.oldVal)) {
|
|
118
|
+
return this.oldVal;
|
|
119
|
+
} else {
|
|
120
|
+
this.oldVal = val;
|
|
121
|
+
return val;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
compareDocumentValidationErrors = (
|
|
126
|
+
val1: typeof this.documentValidationErrors,
|
|
127
|
+
val2: typeof this.documentValidationErrors,
|
|
128
|
+
) => {
|
|
129
|
+
if (!val1?.length) return false;
|
|
130
|
+
if (val1.length !== val2?.length) return false;
|
|
131
|
+
for (let i = 0; i < val1.length; i++) {
|
|
132
|
+
if (
|
|
133
|
+
!val1 ||
|
|
134
|
+
!val2 ||
|
|
135
|
+
!val1[i] ||
|
|
136
|
+
!val2[i] ||
|
|
137
|
+
val1[i].shape !== val2[i].shape
|
|
138
|
+
)
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
return true;
|
|
142
|
+
};
|
|
143
|
+
|
|
68
144
|
<template>
|
|
69
145
|
<AuCard
|
|
70
146
|
@flex={{true}}
|
|
@@ -94,42 +170,63 @@ export default class DocumentValidationPluginCard extends Component<Sig> {
|
|
|
94
170
|
</p>
|
|
95
171
|
</c.header>
|
|
96
172
|
<c.content>
|
|
97
|
-
<
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
<
|
|
103
|
-
@icon={{CloseFilledIcon}}
|
|
104
|
-
@size='large'
|
|
105
|
-
@ariaHidden={{true}}
|
|
106
|
-
class='say-document-validation__icon-error au-u-margin-right-small'
|
|
107
|
-
/>
|
|
108
|
-
<div>
|
|
109
|
-
{{error.message}}
|
|
110
|
-
<AuButton
|
|
111
|
-
class='au-u-padding-left-none au-u-padding-right-none'
|
|
112
|
-
@icon={{ExternalLinkIcon}}
|
|
113
|
-
@skin='link'
|
|
114
|
-
title={{error.subject}}
|
|
115
|
-
{{on 'click' (fn this.goToSubject error.subject)}}
|
|
116
|
-
>{{t 'document-validation-plugin.see-related-node'}}</AuButton>
|
|
117
|
-
</div>
|
|
118
|
-
</div>
|
|
119
|
-
{{/each}}
|
|
120
|
-
{{#each this.propertiesWithoutErrors as |property|}}
|
|
121
|
-
<div class='say-document-validation__error-container'>
|
|
122
|
-
<div class='au-u-margin-right-small'>
|
|
173
|
+
<div>
|
|
174
|
+
{{#each
|
|
175
|
+
(this.dedupeDocumentValidationErrors this.documentValidationErrors)
|
|
176
|
+
as |error|
|
|
177
|
+
}}
|
|
178
|
+
<div class='say-document-validation__error-container'>
|
|
123
179
|
<AuIcon
|
|
124
|
-
@icon={{
|
|
180
|
+
@icon={{CloseFilledIcon}}
|
|
125
181
|
@size='large'
|
|
126
182
|
@ariaHidden={{true}}
|
|
127
|
-
class='say-document-validation__icon-
|
|
183
|
+
class='say-document-validation__icon-error au-u-margin-right-small'
|
|
128
184
|
/>
|
|
185
|
+
<div>
|
|
186
|
+
{{error.message}}
|
|
187
|
+
<AuButton
|
|
188
|
+
class='au-u-padding-left-none au-u-padding-right-none'
|
|
189
|
+
@icon={{ExternalLinkIcon}}
|
|
190
|
+
@skin='link'
|
|
191
|
+
title={{error.subject}}
|
|
192
|
+
{{on 'click' (fn this.goToSubject error.subject)}}
|
|
193
|
+
>{{t 'document-validation-plugin.see-related-node'}}</AuButton>
|
|
194
|
+
{{#if error.rule}}
|
|
195
|
+
{{#if (hasProperty error.rule 'action')}}
|
|
196
|
+
<AuButton
|
|
197
|
+
class='au-u-padding-left-none au-u-padding-right-none'
|
|
198
|
+
@icon={{ExternalLinkIcon}}
|
|
199
|
+
@skin='link'
|
|
200
|
+
title={{error.subject}}
|
|
201
|
+
{{on
|
|
202
|
+
'click'
|
|
203
|
+
(fn this.doActionAndTriggerValidation error.rule.action)
|
|
204
|
+
}}
|
|
205
|
+
>{{error.rule.buttonTitle}}</AuButton>
|
|
206
|
+
{{/if}}
|
|
207
|
+
{{#if (hasProperty error.rule 'helpText')}}
|
|
208
|
+
<span title={{error.rule.helpText}}>
|
|
209
|
+
<AuIcon @icon={{CircleInfoIcon}} />
|
|
210
|
+
</span>
|
|
211
|
+
{{/if}}
|
|
212
|
+
{{/if}}
|
|
213
|
+
</div>
|
|
214
|
+
</div>
|
|
215
|
+
{{/each}}
|
|
216
|
+
{{#each this.propertiesWithoutErrors as |property|}}
|
|
217
|
+
<div class='say-document-validation__error-container'>
|
|
218
|
+
<div class='au-u-margin-right-small'>
|
|
219
|
+
<AuIcon
|
|
220
|
+
@icon={{CheckFilledIcon}}
|
|
221
|
+
@size='large'
|
|
222
|
+
@ariaHidden={{true}}
|
|
223
|
+
class='say-document-validation__icon-success'
|
|
224
|
+
/>
|
|
225
|
+
</div>
|
|
226
|
+
{{property.message}}
|
|
129
227
|
</div>
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
{{/each}}
|
|
228
|
+
{{/each}}
|
|
229
|
+
</div>
|
|
133
230
|
</c.content>
|
|
134
231
|
|
|
135
232
|
</AuCard>
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
type LpdcPluginConfig,
|
|
12
12
|
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/lpdc-plugin';
|
|
13
13
|
import { v4 as uuidv4 } from 'uuid';
|
|
14
|
-
import { getCurrentBesluitURI } from '
|
|
14
|
+
import { getCurrentBesluitURI } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/decision-utils';
|
|
15
15
|
import { SRO } from '../../utils/constants';
|
|
16
16
|
|
|
17
17
|
interface Args {
|
|
@@ -3,7 +3,7 @@ import { action } from '@ember/object';
|
|
|
3
3
|
import Component from '@glimmer/component';
|
|
4
4
|
import { tracked } from '@glimmer/tracking';
|
|
5
5
|
import { SayController } from '@lblod/ember-rdfa-editor';
|
|
6
|
-
import { getCurrentBesluitRange } from '@lblod/ember-rdfa-editor-lblod-plugins/
|
|
6
|
+
import { getCurrentBesluitRange } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/decision-utils';
|
|
7
7
|
import { RoadsignRegulationPluginOptions } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/roadsign-regulation-plugin';
|
|
8
8
|
import { RDF } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
|
|
9
9
|
import { OutgoingTriple } from '@lblod/ember-rdfa-editor/core/rdfa-processor';
|
|
@@ -6,7 +6,7 @@ import { action } from '@ember/object';
|
|
|
6
6
|
import Component from '@glimmer/component';
|
|
7
7
|
import { tracked } from '@glimmer/tracking';
|
|
8
8
|
import { SayController } from '@lblod/ember-rdfa-editor';
|
|
9
|
-
import { getCurrentBesluitRange } from '@lblod/ember-rdfa-editor-lblod-plugins/
|
|
9
|
+
import { getCurrentBesluitRange } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/decision-utils';
|
|
10
10
|
import { RoadsignRegulationPluginOptions } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/roadsign-regulation-plugin';
|
|
11
11
|
import {
|
|
12
12
|
countMobilityMeasures,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type EditorState } from '@lblod/ember-rdfa-editor';
|
|
2
2
|
import { getOutgoingTripleList } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/namespace';
|
|
3
|
-
import { getCurrentBesluitRange } from '@lblod/ember-rdfa-editor-lblod-plugins/
|
|
3
|
+
import { getCurrentBesluitRange } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/decision-utils';
|
|
4
4
|
import { RDF } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
|
|
5
5
|
import { type BesluitType } from './fetchBesluitTypes';
|
|
6
6
|
import { type NamedNodeTriple } from '@lblod/ember-rdfa-editor/core/rdfa-processor';
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
removePropertyFromNode,
|
|
9
9
|
} from '@lblod/ember-rdfa-editor/utils/rdfa-utils';
|
|
10
10
|
import { sayDataFactory } from '@lblod/ember-rdfa-editor/core/say-data-factory';
|
|
11
|
-
import { getCurrentBesluitURI } from '@lblod/ember-rdfa-editor-lblod-plugins/
|
|
11
|
+
import { getCurrentBesluitURI } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/decision-utils';
|
|
12
12
|
import {
|
|
13
13
|
extractBesluitTypeUris,
|
|
14
14
|
isValidTypeChoice,
|
|
@@ -8,16 +8,19 @@ import { buildArticleStructure } from '../utils/build-article-structure';
|
|
|
8
8
|
import { transactionCombinator } from '@lblod/ember-rdfa-editor/utils/transaction-utils';
|
|
9
9
|
import { insertArticle } from '../actions/insert-article';
|
|
10
10
|
import { recalculateNumbers } from '../../structure-plugin/monads/recalculate-structure-numbers';
|
|
11
|
+
import { NodeWithPos } from '@curvenote/prosemirror-utils';
|
|
11
12
|
|
|
12
13
|
interface InsertArticleContainerArgs {
|
|
13
14
|
intl: IntlService;
|
|
14
15
|
decisionUri: string;
|
|
15
16
|
articleUriGenerator?: () => string;
|
|
17
|
+
decisionLocation: NodeWithPos;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
export default function insertArticleContainer({
|
|
19
21
|
decisionUri,
|
|
20
22
|
articleUriGenerator,
|
|
23
|
+
decisionLocation,
|
|
21
24
|
}: InsertArticleContainerArgs): Command {
|
|
22
25
|
return function (state: EditorState, dispatch?: (tr: Transaction) => void) {
|
|
23
26
|
const { schema } = state;
|
|
@@ -33,9 +36,19 @@ export default function insertArticleContainer({
|
|
|
33
36
|
const articleNode = buildArticleStructure(schema, articleUriGenerator);
|
|
34
37
|
|
|
35
38
|
const factory = new SayDataFactory();
|
|
39
|
+
let replaceTr;
|
|
40
|
+
if (state.selection.$from.pos === decisionLocation.pos) {
|
|
41
|
+
replaceTr = state.tr.replaceRangeWith(
|
|
42
|
+
decisionLocation.pos + decisionLocation.node.nodeSize - 1,
|
|
43
|
+
decisionLocation.pos + decisionLocation.node.nodeSize - 1,
|
|
44
|
+
containerNode,
|
|
45
|
+
);
|
|
46
|
+
} else {
|
|
47
|
+
replaceTr = state.tr.replaceSelectionWith(containerNode);
|
|
48
|
+
}
|
|
36
49
|
const { transaction: newTr, result } = transactionCombinator<boolean>(
|
|
37
50
|
state,
|
|
38
|
-
|
|
51
|
+
replaceTr,
|
|
39
52
|
)([
|
|
40
53
|
addPropertyToNode({
|
|
41
54
|
resource: decisionUri,
|
|
@@ -31,7 +31,15 @@ export default function insertDescription({
|
|
|
31
31
|
);
|
|
32
32
|
const tr = state.tr;
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
if (state.selection.$from.pos === decisionLocation.pos) {
|
|
35
|
+
tr.replaceRangeWith(
|
|
36
|
+
decisionLocation.pos + decisionLocation.node.nodeSize - 1,
|
|
37
|
+
decisionLocation.pos + decisionLocation.node.nodeSize - 1,
|
|
38
|
+
nodeToInsert,
|
|
39
|
+
);
|
|
40
|
+
} else {
|
|
41
|
+
tr.replaceSelectionWith(nodeToInsert);
|
|
42
|
+
}
|
|
35
43
|
|
|
36
44
|
const factory = new SayDataFactory();
|
|
37
45
|
const { transaction: newTr, result } = transactionCombinator<boolean>(
|
|
@@ -110,7 +110,15 @@ export default function insertMotivation({
|
|
|
110
110
|
],
|
|
111
111
|
);
|
|
112
112
|
const tr = state.tr;
|
|
113
|
-
|
|
113
|
+
if (state.selection.$from.pos === decisionLocation.pos) {
|
|
114
|
+
tr.replaceRangeWith(
|
|
115
|
+
decisionLocation.pos + decisionLocation.node.nodeSize - 1,
|
|
116
|
+
decisionLocation.pos + decisionLocation.node.nodeSize - 1,
|
|
117
|
+
nodeToInsert,
|
|
118
|
+
);
|
|
119
|
+
} else {
|
|
120
|
+
tr.replaceSelectionWith(nodeToInsert);
|
|
121
|
+
}
|
|
114
122
|
const factory = new SayDataFactory();
|
|
115
123
|
|
|
116
124
|
const { transaction: newTr, result } = transactionCombinator<boolean>(
|
|
@@ -31,7 +31,15 @@ export default function insertTitle({
|
|
|
31
31
|
);
|
|
32
32
|
|
|
33
33
|
const tr = state.tr;
|
|
34
|
-
|
|
34
|
+
if (state.selection.$from.pos === decisionLocation.pos) {
|
|
35
|
+
tr.replaceRangeWith(
|
|
36
|
+
decisionLocation.pos + decisionLocation.node.nodeSize - 1,
|
|
37
|
+
decisionLocation.pos + decisionLocation.node.nodeSize - 1,
|
|
38
|
+
nodeToInsert,
|
|
39
|
+
);
|
|
40
|
+
} else {
|
|
41
|
+
tr.replaceSelectionWith(nodeToInsert);
|
|
42
|
+
}
|
|
35
43
|
|
|
36
44
|
const factory = new SayDataFactory();
|
|
37
45
|
const { transaction: newTr, result } = transactionCombinator<boolean>(
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { SayController } from '@lblod/ember-rdfa-editor';
|
|
2
|
+
import { getDecisionNodeLocation } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/decision-utils';
|
|
3
|
+
import IntlService from 'ember-intl/services/intl';
|
|
4
|
+
import {
|
|
5
|
+
Notification,
|
|
6
|
+
notificationPluginKey,
|
|
7
|
+
} from '@lblod/ember-rdfa-editor/plugins/notification';
|
|
8
|
+
import {
|
|
9
|
+
insertMotivation,
|
|
10
|
+
insertArticleContainer,
|
|
11
|
+
insertDescription,
|
|
12
|
+
insertTitle,
|
|
13
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/decision-plugin/commands';
|
|
14
|
+
import { CircleXIcon } from '@appuniversum/ember-appuniversum/components/icons/circle-x';
|
|
15
|
+
import { NodeWithPos } from '@curvenote/prosemirror-utils';
|
|
16
|
+
|
|
17
|
+
export function insertTitleAtCursor(
|
|
18
|
+
controller: SayController,
|
|
19
|
+
intl: IntlService,
|
|
20
|
+
) {
|
|
21
|
+
const decisionNodeLocation = getDecisionNodeLocation(controller);
|
|
22
|
+
if (!decisionNodeLocation) {
|
|
23
|
+
return sendNotificationError(
|
|
24
|
+
controller,
|
|
25
|
+
intl.t('document-validation-plugin.decision-node-not-found'),
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
controller.doCommand(
|
|
29
|
+
insertTitle({
|
|
30
|
+
placeholderText: intl.t('besluit-plugin.placeholder.decision-title'),
|
|
31
|
+
decisionLocation: decisionNodeLocation,
|
|
32
|
+
}),
|
|
33
|
+
{ view: controller.mainEditorView },
|
|
34
|
+
);
|
|
35
|
+
controller.focus();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function insertDescriptionAtCursor(
|
|
39
|
+
controller: SayController,
|
|
40
|
+
intl: IntlService,
|
|
41
|
+
) {
|
|
42
|
+
const decisionNodeLocation = getDecisionNodeLocation(controller);
|
|
43
|
+
if (!decisionNodeLocation) {
|
|
44
|
+
return sendNotificationError(
|
|
45
|
+
controller,
|
|
46
|
+
intl.t('document-validation-plugin.decision-node-not-found'),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
controller.doCommand(
|
|
50
|
+
insertDescription({
|
|
51
|
+
placeholderText: intl.t(
|
|
52
|
+
'besluit-plugin.placeholder.decision-description',
|
|
53
|
+
),
|
|
54
|
+
decisionLocation: decisionNodeLocation,
|
|
55
|
+
}),
|
|
56
|
+
{
|
|
57
|
+
view: controller.mainEditorView,
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
controller.focus();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function insertMotivationAtCursor(
|
|
64
|
+
controller: SayController,
|
|
65
|
+
intl: IntlService,
|
|
66
|
+
) {
|
|
67
|
+
const decisionNodeLocation = getDecisionNodeLocation(controller);
|
|
68
|
+
if (!decisionNodeLocation) {
|
|
69
|
+
return sendNotificationError(
|
|
70
|
+
controller,
|
|
71
|
+
intl.t('document-validation-plugin.decision-node-not-found'),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
controller.doCommand(
|
|
75
|
+
insertMotivation({
|
|
76
|
+
intl: intl,
|
|
77
|
+
decisionLocation: decisionNodeLocation,
|
|
78
|
+
}),
|
|
79
|
+
{
|
|
80
|
+
view: controller.mainEditorView,
|
|
81
|
+
},
|
|
82
|
+
);
|
|
83
|
+
controller.focus();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function insertArticleContainerAtCursor(
|
|
87
|
+
controller: SayController,
|
|
88
|
+
intl: IntlService,
|
|
89
|
+
articleUriGenerator?: () => string,
|
|
90
|
+
) {
|
|
91
|
+
const decisionNodeLocation = getDecisionNodeLocation(controller);
|
|
92
|
+
if (!decisionNodeLocation) {
|
|
93
|
+
return sendNotificationError(
|
|
94
|
+
controller,
|
|
95
|
+
intl.t('document-validation-plugin.decision-node-not-found'),
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
controller.doCommand(
|
|
99
|
+
insertArticleContainer({
|
|
100
|
+
intl: intl,
|
|
101
|
+
decisionUri: decisionNodeLocation?.node.attrs.subject,
|
|
102
|
+
articleUriGenerator: articleUriGenerator,
|
|
103
|
+
decisionLocation: decisionNodeLocation,
|
|
104
|
+
}),
|
|
105
|
+
{
|
|
106
|
+
view: controller.mainEditorView,
|
|
107
|
+
},
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function sendNotificationError(controller: SayController, text: string) {
|
|
112
|
+
// Show a notification via the notification plugin
|
|
113
|
+
const { notificationCallback } = notificationPluginKey.getState(
|
|
114
|
+
controller.mainEditorState,
|
|
115
|
+
) as {
|
|
116
|
+
notificationCallback: (notification: Notification) => void;
|
|
117
|
+
intl: IntlService;
|
|
118
|
+
};
|
|
119
|
+
notificationCallback({
|
|
120
|
+
title: text,
|
|
121
|
+
options: {
|
|
122
|
+
type: 'error',
|
|
123
|
+
icon: CircleXIcon,
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
}
|