@lblod/ember-rdfa-editor-lblod-plugins 19.1.0 → 19.2.0

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 (91) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/addon/components/au-native-input.ts +12 -13
  3. package/addon/components/{worship-plugin → common/sort}/sortable-table-header.hbs +3 -9
  4. package/addon/components/{worship-plugin → common/sort}/sortable-table-header.ts +3 -6
  5. package/addon/components/lmb-plugin/insert.hbs +18 -0
  6. package/addon/components/lmb-plugin/insert.ts +121 -0
  7. package/addon/components/lmb-plugin/list.hbs +58 -0
  8. package/addon/components/lmb-plugin/search-modal.hbs +71 -0
  9. package/addon/components/lmb-plugin/search-modal.ts +173 -0
  10. package/addon/components/loading-alert.hbs +3 -1
  11. package/addon/components/location-plugin/edit.gts +380 -0
  12. package/addon/components/location-plugin/insert-variable.gts +67 -0
  13. package/addon/components/location-plugin/insert.gts +153 -0
  14. package/addon/components/location-plugin/nodeview.hbs +20 -0
  15. package/addon/components/location-plugin/nodeview.ts +49 -0
  16. package/addon/components/lpdc-plugin/lpdc-insert.hbs +19 -0
  17. package/addon/components/lpdc-plugin/lpdc-insert.ts +93 -0
  18. package/addon/components/lpdc-plugin/lpdc-modal.hbs +44 -0
  19. package/addon/components/lpdc-plugin/lpdc-modal.ts +79 -0
  20. package/addon/components/lpdc-plugin/lpdc-table-view.hbs +53 -0
  21. package/addon/components/lpdc-plugin/lpdc-table-view.ts +23 -0
  22. package/addon/components/variable-plugin/address/edit.ts +1 -1
  23. package/addon/components/variable-plugin/address/nodeview.ts +1 -1
  24. package/addon/components/worship-plugin/list.hbs +1 -1
  25. package/addon/models/mandatee.ts +35 -0
  26. package/addon/plugins/lmb-plugin/index.ts +3 -0
  27. package/addon/plugins/location-plugin/address.ts +405 -0
  28. package/addon/plugins/location-plugin/utils/address-helpers.ts +395 -0
  29. package/addon/plugins/location-plugin/utils/node-utils.ts +51 -0
  30. package/addon/plugins/lpdc-plugin/api.ts +114 -0
  31. package/addon/plugins/lpdc-plugin/index.ts +2 -0
  32. package/addon/plugins/lpdc-plugin/types.ts +5 -0
  33. package/addon/plugins/snippet-plugin/nodes/snippet-placeholder.ts +5 -3
  34. package/addon/plugins/variable-plugin/utils/address-helpers.ts +130 -12
  35. package/addon/plugins/variable-plugin/utils/dom-constructors.ts +3 -19
  36. package/addon/plugins/variable-plugin/variables/address.ts +122 -84
  37. package/addon/plugins/variable-plugin/variables/codelist.ts +1 -1
  38. package/addon/plugins/variable-plugin/variables/date.ts +1 -1
  39. package/addon/plugins/variable-plugin/variables/location.ts +2 -2
  40. package/addon/plugins/variable-plugin/variables/number.ts +1 -1
  41. package/addon/plugins/variable-plugin/variables/text.ts +1 -1
  42. package/addon/utils/constants.ts +15 -1
  43. package/addon/utils/dom-output-spec-helpers.ts +20 -3
  44. package/app/components/{worship-plugin → common/sort}/sortable-table-header.js +1 -1
  45. package/app/components/lmb-plugin/insert.js +1 -0
  46. package/app/components/lmb-plugin/list.js +1 -0
  47. package/app/components/lmb-plugin/search-modal.js +1 -0
  48. package/app/components/location-plugin/edit.js +1 -0
  49. package/app/components/location-plugin/insert-variable.js +1 -0
  50. package/app/components/location-plugin/insert.js +1 -0
  51. package/app/components/location-plugin/nodeview.js +1 -0
  52. package/app/components/lpdc-plugin/lpdc-insert.js +1 -0
  53. package/app/components/lpdc-plugin/lpdc-modal.js +1 -0
  54. package/app/components/lpdc-plugin/lpdc-table-view.js +1 -0
  55. package/app/styles/article-structure-plugin.scss +12 -6
  56. package/app/styles/snippet-plugin.scss +19 -0
  57. package/declarations/addon/components/au-native-input.d.ts +12 -10
  58. package/declarations/addon/components/{worship-plugin → common/sort}/sortable-table-header.d.ts +3 -3
  59. package/declarations/addon/components/lmb-plugin/insert.d.ts +17 -0
  60. package/declarations/addon/components/lmb-plugin/list.d.ts +1 -0
  61. package/declarations/addon/components/lmb-plugin/search-modal.d.ts +31 -0
  62. package/declarations/addon/components/location-plugin/edit.d.ts +47 -0
  63. package/declarations/addon/components/location-plugin/insert-variable.d.ts +17 -0
  64. package/declarations/addon/components/location-plugin/insert.d.ts +29 -0
  65. package/declarations/addon/components/location-plugin/nodeview.d.ts +22 -0
  66. package/declarations/addon/components/lpdc-plugin/lpdc-insert.d.ts +17 -0
  67. package/declarations/addon/components/lpdc-plugin/lpdc-modal.d.ts +42 -0
  68. package/declarations/addon/components/lpdc-plugin/lpdc-table-view.d.ts +37 -0
  69. package/declarations/addon/components/variable-plugin/address/edit.d.ts +1 -1
  70. package/declarations/addon/components/variable-plugin/address/nodeview.d.ts +1 -1
  71. package/declarations/addon/models/mandatee.d.ts +13 -0
  72. package/declarations/addon/plugins/lmb-plugin/index.d.ts +3 -0
  73. package/declarations/addon/plugins/location-plugin/address.d.ts +2 -0
  74. package/declarations/addon/plugins/location-plugin/utils/address-helpers.d.ts +65 -0
  75. package/declarations/addon/plugins/location-plugin/utils/node-utils.d.ts +2 -0
  76. package/declarations/addon/plugins/lpdc-plugin/api.d.ts +29 -0
  77. package/declarations/addon/plugins/lpdc-plugin/index.d.ts +2 -0
  78. package/declarations/addon/plugins/lpdc-plugin/types.d.ts +7 -0
  79. package/declarations/addon/plugins/variable-plugin/utils/address-helpers.d.ts +34 -1
  80. package/declarations/addon/plugins/variable-plugin/utils/dom-constructors.d.ts +5 -11
  81. package/declarations/addon/plugins/variable-plugin/variables/address.d.ts +0 -13
  82. package/declarations/addon/utils/constants.d.ts +5 -0
  83. package/declarations/addon/utils/dom-output-spec-helpers.d.ts +6 -2
  84. package/package.json +2 -2
  85. package/pnpm-lock.yaml +19 -8
  86. package/translations/en-US.yaml +41 -14
  87. package/translations/nl-BE.yaml +41 -13
  88. package/types/ember-concurrency/helpers/perform.d.ts +48 -0
  89. package/types/ember-power-select/components/power-select.d.ts +160 -0
  90. /package/addon/{plugins/variable-plugin/utils/attribute-parsers.ts → utils/variable-attribute-parsers.ts} +0 -0
  91. /package/declarations/addon/{plugins/variable-plugin/utils/attribute-parsers.d.ts → utils/variable-attribute-parsers.d.ts} +0 -0
@@ -0,0 +1,405 @@
1
+ import {
2
+ ADRES,
3
+ ADRES_TYPO,
4
+ DCT,
5
+ EXT,
6
+ GENERIEK,
7
+ GEOSPARQL,
8
+ LOCN,
9
+ RDF,
10
+ } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
11
+ import {
12
+ createEmberNodeSpec,
13
+ createEmberNodeView,
14
+ EmberNodeConfig,
15
+ } from '@lblod/ember-rdfa-editor/utils/ember-node';
16
+ import { v4 as uuidv4 } from 'uuid';
17
+ import {
18
+ DOMOutputSpec,
19
+ EditorState,
20
+ PNode,
21
+ ParseRule,
22
+ } from '@lblod/ember-rdfa-editor';
23
+ import { sayDataFactory } from '@lblod/ember-rdfa-editor/core/say-data-factory';
24
+ import {
25
+ hasRdfaVariableType,
26
+ isVariable,
27
+ parseLabel,
28
+ parseVariableInstance,
29
+ parseVariableType,
30
+ } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/variable-attribute-parsers';
31
+ import {
32
+ findChildWithRdfaAttribute,
33
+ hasOutgoingNamedNodeTriple,
34
+ hasRDFaAttribute,
35
+ } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/namespace';
36
+ import {
37
+ contentSpan,
38
+ span,
39
+ } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/dom-output-spec-helpers';
40
+ import AddressNodeviewComponent from '@lblod/ember-rdfa-editor-lblod-plugins/components/location-plugin/nodeview';
41
+ import type { ComponentLike } from '@glint/template';
42
+ import { getTranslationFunction } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/translation';
43
+ import {
44
+ getRdfaAttrs,
45
+ rdfaAttrSpec,
46
+ renderRdfaAware,
47
+ } from '@lblod/ember-rdfa-editor/core/schema';
48
+ import {
49
+ Address,
50
+ constructLambert72WKTString,
51
+ type Lambert72Coordinates,
52
+ parseLambert72GMLString,
53
+ parseLambert72WKTString,
54
+ } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/location-plugin/utils/address-helpers';
55
+
56
+ const rdfaAware = true;
57
+
58
+ const constructLocationNode = (location: Lambert72Coordinates) => {
59
+ return span(
60
+ {
61
+ property: ADRES('positie').full,
62
+ typeof: GENERIEK('GeografischePositie').full,
63
+ },
64
+ span({
65
+ property: GEOSPARQL('asWKT').full,
66
+ datatype: GEOSPARQL('wktLiteral').full,
67
+ content: constructLambert72WKTString(location),
68
+ }),
69
+ );
70
+ };
71
+
72
+ const constructAddressNode = (address: Address) => {
73
+ const housenumberNode = address.housenumber
74
+ ? [
75
+ ' ',
76
+ span(
77
+ {
78
+ property: ADRES('Adresvoorstelling.huisnummer').full,
79
+ },
80
+ address.housenumber,
81
+ ),
82
+ ]
83
+ : [];
84
+ const busnumberNode = address.busnumber
85
+ ? [
86
+ ' bus ',
87
+ span(
88
+ {
89
+ property: ADRES('Adresvoorstelling.busnummer').full,
90
+ },
91
+ address.busnumber,
92
+ ),
93
+ ]
94
+ : [];
95
+ const idNode = address.id
96
+ ? [
97
+ span({
98
+ property: ADRES('verwijstNaar').full,
99
+ content: address.id,
100
+ }),
101
+ ]
102
+ : [];
103
+ return contentSpan(
104
+ { resource: address.id, typeof: LOCN('Adres').full },
105
+ span(
106
+ {
107
+ property: DCT('spatial').full,
108
+ },
109
+ span(
110
+ {
111
+ property: LOCN('thoroughfare').full,
112
+ },
113
+ address.street,
114
+ ),
115
+ ...housenumberNode,
116
+ ...busnumberNode,
117
+ ),
118
+ ', ',
119
+ span(
120
+ {
121
+ property: LOCN('postcode').full,
122
+ },
123
+ address.zipcode,
124
+ ),
125
+ ' ',
126
+ span(
127
+ {
128
+ property: ADRES('gemeentenaam').full,
129
+ language: 'nl',
130
+ },
131
+ address.municipality,
132
+ ),
133
+ ...idNode,
134
+ constructLocationNode(address.location),
135
+ );
136
+ };
137
+
138
+ const parseOldAddressNode = (addressNode: Element): Address | undefined => {
139
+ const id = addressNode.getAttribute('resource');
140
+ const street = findChildWithRdfaAttribute(
141
+ addressNode,
142
+ 'property',
143
+ ADRES_TYPO('heeftStraatnaam'),
144
+ )?.textContent;
145
+ const housenumber = findChildWithRdfaAttribute(
146
+ addressNode,
147
+ 'property',
148
+ ADRES_TYPO('huisnummer'),
149
+ )?.textContent;
150
+ const busnumber = findChildWithRdfaAttribute(
151
+ addressNode,
152
+ 'property',
153
+ ADRES_TYPO('busnummer'),
154
+ )?.textContent;
155
+ const postInfoNode = findChildWithRdfaAttribute(
156
+ addressNode,
157
+ 'property',
158
+ ADRES_TYPO('heeftPostinfo'),
159
+ );
160
+ const zipcode =
161
+ postInfoNode &&
162
+ findChildWithRdfaAttribute(postInfoNode, 'property', ADRES_TYPO('postcode'))
163
+ ?.textContent;
164
+ const municipality = findChildWithRdfaAttribute(
165
+ addressNode,
166
+ 'property',
167
+ ADRES_TYPO('gemeentenaam'),
168
+ )?.textContent;
169
+
170
+ const locationNode = findChildWithRdfaAttribute(
171
+ addressNode,
172
+ 'property',
173
+ ADRES_TYPO('positie'),
174
+ );
175
+ const gml =
176
+ locationNode &&
177
+ findChildWithRdfaAttribute(
178
+ locationNode,
179
+ 'property',
180
+ GEOSPARQL('asGML'),
181
+ )?.getAttribute('content');
182
+
183
+ if (street && municipality && zipcode && gml) {
184
+ return new Address({
185
+ id: id ?? undefined,
186
+ street,
187
+ housenumber: housenumber ?? undefined,
188
+ zipcode,
189
+ municipality,
190
+ busnumber: busnumber ?? undefined,
191
+ location: parseLambert72GMLString(gml),
192
+ });
193
+ } else {
194
+ return;
195
+ }
196
+ };
197
+
198
+ const parseAddressNode = (addressNode: Element): Address | undefined => {
199
+ const id = findChildWithRdfaAttribute(
200
+ addressNode,
201
+ 'property',
202
+ ADRES('verwijstNaar'),
203
+ )?.getAttribute('content');
204
+ const spatialNode = findChildWithRdfaAttribute(
205
+ addressNode,
206
+ 'property',
207
+ DCT('spatial'),
208
+ );
209
+ const street =
210
+ spatialNode &&
211
+ findChildWithRdfaAttribute(spatialNode, 'property', LOCN('thoroughfare'))
212
+ ?.textContent;
213
+ const housenumber =
214
+ spatialNode &&
215
+ findChildWithRdfaAttribute(
216
+ spatialNode,
217
+ 'property',
218
+ ADRES('Adresvoorstelling.huisnummer'),
219
+ )?.textContent;
220
+ const busnumber =
221
+ spatialNode &&
222
+ findChildWithRdfaAttribute(
223
+ spatialNode,
224
+ 'property',
225
+ ADRES('Adresvoorstelling.busnummer'),
226
+ )?.textContent;
227
+ const zipcode = findChildWithRdfaAttribute(
228
+ addressNode,
229
+ 'property',
230
+ LOCN('postcode'),
231
+ )?.textContent;
232
+ const municipality = findChildWithRdfaAttribute(
233
+ addressNode,
234
+ 'property',
235
+ ADRES('gemeentenaam'),
236
+ )?.textContent;
237
+
238
+ const locationNode = findChildWithRdfaAttribute(
239
+ addressNode,
240
+ 'property',
241
+ ADRES('positie'),
242
+ );
243
+ const wkt =
244
+ locationNode &&
245
+ findChildWithRdfaAttribute(
246
+ locationNode,
247
+ 'property',
248
+ GEOSPARQL('asWKT'),
249
+ )?.getAttribute('content');
250
+
251
+ if (street && municipality && zipcode && wkt) {
252
+ return new Address({
253
+ id: id ?? undefined,
254
+ street,
255
+ housenumber: housenumber ?? undefined,
256
+ zipcode,
257
+ municipality,
258
+ busnumber: busnumber ?? undefined,
259
+ location: parseLambert72WKTString(wkt),
260
+ });
261
+ } else {
262
+ return;
263
+ }
264
+ };
265
+
266
+ const parseDOM: ParseRule[] = [
267
+ {
268
+ tag: 'span',
269
+ getAttrs(node: HTMLElement) {
270
+ const attrs = getRdfaAttrs(node, { rdfaAware });
271
+ if (!attrs) {
272
+ return false;
273
+ }
274
+ const dataContainer = node.querySelector(
275
+ '[data-content-container="true"]',
276
+ );
277
+ if (
278
+ hasOutgoingNamedNodeTriple(attrs, RDF('type'), EXT('Mapping')) &&
279
+ dataContainer &&
280
+ hasRdfaVariableType(attrs, 'address')
281
+ ) {
282
+ if (attrs.rdfaNodeType !== 'resource') {
283
+ return false;
284
+ }
285
+ // Filter out properties with content predicate,
286
+ // as we handle this ourselves with the `value` attribute
287
+ attrs.properties = attrs.properties.filter((prop) => {
288
+ return !EXT('content').matches(prop.predicate);
289
+ });
290
+ const addressNode = [...dataContainer.children].find((el) =>
291
+ hasRDFaAttribute(el, 'property', EXT('content')),
292
+ );
293
+ if (!addressNode) {
294
+ return false;
295
+ }
296
+ const address = parseAddressNode(addressNode);
297
+ return {
298
+ ...attrs,
299
+ value: address ?? parseOldAddressNode(addressNode),
300
+ };
301
+ }
302
+ return false;
303
+ },
304
+ },
305
+ {
306
+ tag: 'span',
307
+ getAttrs: (node: HTMLElement) => {
308
+ if (isVariable(node) && parseVariableType(node) === 'address') {
309
+ const mappingResource = node.getAttribute('resource');
310
+ if (!mappingResource) {
311
+ return false;
312
+ }
313
+ const variableInstance = parseVariableInstance(node);
314
+ const label = parseLabel(node);
315
+
316
+ const addressNode = [...node.children].find((el) =>
317
+ hasRDFaAttribute(el, 'property', EXT('content')),
318
+ );
319
+ if (!addressNode) {
320
+ return false;
321
+ }
322
+
323
+ const properties = [
324
+ {
325
+ predicate: RDF('type').full,
326
+ object: sayDataFactory.namedNode(EXT('Mapping').full),
327
+ },
328
+ {
329
+ predicate: EXT('instance').full,
330
+ object: sayDataFactory.namedNode(
331
+ variableInstance ??
332
+ `http://data.lblod.info/variables/${uuidv4()}`,
333
+ ),
334
+ },
335
+ {
336
+ predicate: DCT('type').full,
337
+ object: sayDataFactory.literal('address'),
338
+ },
339
+ ];
340
+ if (label) {
341
+ properties.push({
342
+ predicate: EXT('label').full,
343
+ object: sayDataFactory.literal(label),
344
+ });
345
+ }
346
+
347
+ return {
348
+ value: parseAddressNode(addressNode),
349
+ subject: mappingResource,
350
+ rdfaNodeType: 'resource',
351
+ __rdfaId: uuidv4(),
352
+ properties,
353
+ };
354
+ }
355
+
356
+ return false;
357
+ },
358
+ },
359
+ ];
360
+
361
+ const serialize = (node: PNode, state: EditorState): DOMOutputSpec => {
362
+ const t = getTranslationFunction(state);
363
+
364
+ const { value } = node.attrs;
365
+ let contentNode: DOMOutputSpec;
366
+ if (value) {
367
+ contentNode = constructAddressNode(value);
368
+ } else {
369
+ const placeholder = t(
370
+ 'editor-plugins.address.nodeview.placeholder',
371
+ 'Voeg adres in',
372
+ );
373
+ contentNode = contentSpan({}, placeholder);
374
+ }
375
+ return renderRdfaAware({
376
+ renderable: node,
377
+ tag: 'span',
378
+ content: contentNode,
379
+ });
380
+ };
381
+
382
+ const emberNodeConfig: EmberNodeConfig = {
383
+ name: 'address',
384
+ component: AddressNodeviewComponent as unknown as ComponentLike,
385
+ inline: true,
386
+ group: 'inline variable',
387
+ atom: true,
388
+ editable: true,
389
+ recreateUri: true,
390
+ uriAttributes: ['variableInstance'],
391
+ draggable: false,
392
+ needsFFKludge: true,
393
+ selectable: true,
394
+ attrs: {
395
+ ...rdfaAttrSpec({ rdfaAware }),
396
+ value: {
397
+ default: null,
398
+ },
399
+ },
400
+ serialize,
401
+ parseDOM,
402
+ };
403
+
404
+ export const address = createEmberNodeSpec(emberNodeConfig);
405
+ export const addressView = createEmberNodeView(emberNodeConfig);