@lblod/ember-rdfa-editor-lblod-plugins 28.0.0 → 28.1.0-dev.ed578cc3a5b1de900ca53bd1e5ebe4e950e51439

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 (30) hide show
  1. package/.changeset/kind-cooks-cross.md +5 -0
  2. package/.changeset/lovely-carpets-grow.md +5 -0
  3. package/CHANGELOG.md +12 -0
  4. package/addon/components/besluit-type-plugin/besluit-type-form.gts +68 -0
  5. package/addon/components/besluit-type-plugin/besluit-type-select.gts +80 -0
  6. package/addon/components/besluit-type-plugin/toolbar-dropdown.gts +191 -0
  7. package/addon/components/common/documents/preview.gts +24 -6
  8. package/addon/components/common/documents/types.ts +2 -17
  9. package/addon/components/snippet-plugin/nodes/snippet.gts +1 -1
  10. package/addon/components/snippet-plugin/snippet-insert.gts +1 -1
  11. package/addon/plugins/besluit-type-plugin/utils/besluit-type-instances.ts +100 -0
  12. package/addon/plugins/besluit-type-plugin/utils/set-besluit-type.ts +57 -0
  13. package/addon/plugins/snippet-plugin/index.ts +5 -10
  14. package/addon/plugins/snippet-plugin/utils/collate-imported-resources.ts +5 -2
  15. package/app/components/besluit-type-plugin/besluit-type-form.js +1 -0
  16. package/declarations/addon/components/besluit-type-plugin/besluit-type-form.d.ts +17 -0
  17. package/declarations/addon/components/besluit-type-plugin/besluit-type-select.d.ts +15 -8
  18. package/declarations/addon/components/besluit-type-plugin/toolbar-dropdown.d.ts +8 -28
  19. package/declarations/addon/components/common/documents/preview.d.ts +2 -0
  20. package/declarations/addon/components/common/documents/types.d.ts +2 -9
  21. package/declarations/addon/plugins/besluit-type-plugin/utils/besluit-type-instances.d.ts +18 -0
  22. package/declarations/addon/plugins/besluit-type-plugin/utils/set-besluit-type.d.ts +4 -0
  23. package/declarations/addon/plugins/snippet-plugin/index.d.ts +3 -3
  24. package/package.json +1 -1
  25. package/translations/en-US.yaml +9 -7
  26. package/translations/nl-BE.yaml +12 -10
  27. package/addon/components/besluit-type-plugin/besluit-type-select.hbs +0 -32
  28. package/addon/components/besluit-type-plugin/besluit-type-select.ts +0 -29
  29. package/addon/components/besluit-type-plugin/toolbar-dropdown.hbs +0 -102
  30. package/addon/components/besluit-type-plugin/toolbar-dropdown.ts +0 -223
@@ -1,223 +0,0 @@
1
- import { tracked } from '@glimmer/tracking';
2
- import Component from '@glimmer/component';
3
- import { action } from '@ember/object';
4
- import { addProperty, removeProperty } from '@lblod/ember-rdfa-editor/commands';
5
- import { SayController } from '@lblod/ember-rdfa-editor';
6
- import { sayDataFactory } from '@lblod/ember-rdfa-editor/core/say-data-factory';
7
- import fetchBesluitTypes, {
8
- BesluitType,
9
- } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/besluit-type-plugin/utils/fetchBesluitTypes';
10
- import { trackedFunction } from 'reactiveweb/function';
11
- import { BesluitTypePluginOptions } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/besluit-type-plugin';
12
- import { RDF } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
13
- import { getOutgoingTripleList } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/namespace';
14
- import { AlertTriangleIcon } from '@appuniversum/ember-appuniversum/components/icons/alert-triangle';
15
- import { CrossIcon } from '@appuniversum/ember-appuniversum/components/icons/cross';
16
- import { MailIcon } from '@appuniversum/ember-appuniversum/components/icons/mail';
17
- import { CircleXIcon } from '@appuniversum/ember-appuniversum/components/icons/circle-x';
18
- import {
19
- getCurrentBesluitRange,
20
- getCurrentBesluitURI,
21
- } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/besluit-topic-plugin/utils/helpers';
22
-
23
- type Args = {
24
- controller: SayController;
25
- options: BesluitTypePluginOptions;
26
- };
27
-
28
- export default class EditorPluginsToolbarDropdownComponent extends Component<Args> {
29
- CircleIcon = CircleXIcon;
30
- MailIcon = MailIcon;
31
- CrossIcon = CrossIcon;
32
- AlertTriangleIcon = AlertTriangleIcon;
33
- /**
34
- * Actual besluit type selected
35
- * @property besluitType
36
- * @type BesluitType
37
- * @private
38
- */
39
- @tracked besluitType?: BesluitType;
40
- @tracked previousBesluitType?: string;
41
-
42
- //used to update selections since the other vars dont seem to work in octane
43
- @tracked besluit?: BesluitType;
44
- @tracked subBesluit?: BesluitType;
45
- @tracked subSubBesluit?: BesluitType;
46
-
47
- @tracked cardExpanded = false;
48
-
49
- constructor(parent: unknown, args: Args) {
50
- super(parent, args);
51
- }
52
-
53
- get controller() {
54
- return this.args.controller;
55
- }
56
-
57
- get doc() {
58
- return this.controller.mainEditorState.doc;
59
- }
60
-
61
- types = trackedFunction(this, async () => {
62
- const types = await fetchBesluitTypes(
63
- this.args.options.classificatieUri,
64
- this.args.options.endpoint,
65
- );
66
- return types;
67
- });
68
-
69
- get currentBesluitRange() {
70
- return getCurrentBesluitRange(this.controller);
71
- }
72
-
73
- get currentBesluitURI() {
74
- return getCurrentBesluitURI(this.controller);
75
- }
76
-
77
- get showCard() {
78
- return !!this.currentBesluitRange;
79
- }
80
-
81
- @action
82
- updateBesluitTypes() {
83
- if (!this.types.isFinished || !this.currentBesluitRange) {
84
- return;
85
- }
86
- if (!this.types.value) {
87
- console.warn('Request for besluit types failed');
88
- return;
89
- }
90
- const besluit = this.currentBesluitRange;
91
- const besluitTypes = getOutgoingTripleList(besluit.node.attrs, RDF('type'));
92
- const besluitTypeRelevant = besluitTypes.find(
93
- (type) =>
94
- type.object.termType === 'NamedNode' &&
95
- type.object.value.includes(
96
- 'https://data.vlaanderen.be/id/concept/BesluitType/',
97
- ),
98
- )?.object.value;
99
-
100
- if (besluitTypeRelevant) {
101
- this.previousBesluitType = besluitTypeRelevant;
102
- const besluitType = this.findBesluitTypeByURI(besluitTypeRelevant);
103
-
104
- const firstAncestor = this.findBesluitTypeParent(besluitType);
105
- const secondAncestor = this.findBesluitTypeParent(firstAncestor);
106
- if (firstAncestor && secondAncestor) {
107
- this.besluit = secondAncestor;
108
- this.subBesluit = firstAncestor;
109
- this.subSubBesluit = besluitType;
110
- } else if (firstAncestor) {
111
- this.besluit = firstAncestor;
112
- this.subBesluit = besluitType;
113
- this.subSubBesluit = undefined;
114
- } else {
115
- this.besluit = besluitType;
116
- this.subBesluit = undefined;
117
- this.subSubBesluit = undefined;
118
- }
119
- this.cardExpanded = false;
120
- } else {
121
- this.cardExpanded = true;
122
- this.besluit = undefined;
123
- this.subBesluit = undefined;
124
- this.subSubBesluit = undefined;
125
- }
126
- }
127
-
128
- @action
129
- updateBesluitType(selected: BesluitType) {
130
- this.besluit = selected;
131
- this.besluitType = selected;
132
- this.subBesluit = undefined;
133
- this.subSubBesluit = undefined;
134
- if (!selected.subTypes || !selected.subTypes.length) this.insert();
135
- }
136
-
137
- @action
138
- updateBesluitSubType(selected: BesluitType) {
139
- this.subBesluit = selected;
140
- this.besluitType = selected;
141
- this.subSubBesluit = undefined;
142
- if (!selected.subTypes || !selected.subTypes.length) this.insert();
143
- }
144
-
145
- @action
146
- updateBesluitSubSubType(selected: BesluitType) {
147
- this.subSubBesluit = selected;
148
- this.besluitType = selected;
149
- if (!selected.subTypes || !selected.subTypes.length) this.insert();
150
- }
151
-
152
- findBesluitTypeParent(
153
- besluitType?: BesluitType,
154
- array: BesluitType[] | null = this.types.value,
155
- parent?: BesluitType,
156
- ): BesluitType | undefined {
157
- if (!besluitType || !array) {
158
- return;
159
- }
160
- for (const type of array) {
161
- if (type == besluitType) {
162
- return parent;
163
- } else if (type.subTypes?.length) {
164
- parent = type;
165
- return this.findBesluitTypeParent(besluitType, type.subTypes, parent);
166
- }
167
- }
168
- return;
169
- }
170
-
171
- findBesluitTypeByURI(
172
- uri: string,
173
- types = this.types.value,
174
- ): BesluitType | undefined {
175
- if (uri && types) {
176
- for (const besluitType of types) {
177
- if (besluitType.uri === uri) {
178
- return besluitType;
179
- } else if (besluitType.subTypes && besluitType.subTypes.length) {
180
- const subType = this.findBesluitTypeByURI(uri, besluitType.subTypes);
181
- if (subType) {
182
- return subType;
183
- }
184
- }
185
- }
186
- }
187
- return;
188
- }
189
-
190
- insert() {
191
- const resource = this.currentBesluitURI;
192
- if (this.besluitType && resource) {
193
- this.cardExpanded = false;
194
- if (this.previousBesluitType) {
195
- this.controller.doCommand(
196
- removeProperty({
197
- resource,
198
- property: {
199
- predicate: RDF('type').full,
200
- object: sayDataFactory.namedNode(this.previousBesluitType),
201
- },
202
- }),
203
- { view: this.controller.mainEditorView },
204
- );
205
- }
206
- this.controller.doCommand(
207
- addProperty({
208
- resource,
209
- property: {
210
- predicate: RDF('type').full,
211
- object: sayDataFactory.namedNode(this.besluitType.uri),
212
- },
213
- }),
214
- { view: this.controller.mainEditorView },
215
- );
216
- }
217
- }
218
-
219
- @action
220
- toggleCard() {
221
- this.cardExpanded = !this.cardExpanded;
222
- }
223
- }