@lblod/ember-rdfa-editor-lblod-plugins 9.1.1 → 11.0.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.
- package/CHANGELOG.md +65 -1
- package/README.md +213 -150
- package/addon/components/import-snippet-plugin/card.hbs +11 -5
- package/addon/components/rdfa-date-plugin/help-modal.hbs +12 -0
- package/addon/components/roadsign-regulation-plugin/expanded-measure.hbs +40 -10
- package/addon/components/roadsign-regulation-plugin/expanded-measure.ts +1 -0
- package/addon/components/roadsign-regulation-plugin/measure-template.ts +6 -12
- package/addon/components/roadsign-regulation-plugin/roadsign-regulation-card.hbs +1 -1
- package/addon/components/roadsign-regulation-plugin/roadsigns-modal.hbs +5 -5
- package/addon/components/roadsign-regulation-plugin/roadsigns-pagination.hbs +4 -4
- package/addon/components/roadsign-regulation-plugin/roadsigns-table.hbs +25 -9
- package/addon/components/snippet-plugin/search-modal.ts +4 -0
- package/addon/components/snippet-plugin/snippet-insert.hbs +1 -0
- package/addon/components/snippet-plugin/snippet-insert.ts +14 -11
- package/addon/components/snippet-plugin/snippet-list/snippet-list-modal.hbs +80 -0
- package/addon/components/snippet-plugin/snippet-list/snippet-list-modal.ts +98 -0
- package/addon/components/snippet-plugin/snippet-list/snippet-list-view.hbs +29 -0
- package/addon/components/snippet-plugin/snippet-list/snippet-list-view.ts +28 -0
- package/addon/components/snippet-plugin/snippet-list-select.hbs +16 -0
- package/addon/components/snippet-plugin/snippet-list-select.ts +27 -0
- package/addon/components/table-of-contents-plugin/ember-nodes/table-of-contents.hbs +1 -1
- package/addon/components/table-of-contents-plugin/ember-nodes/table-of-contents.ts +16 -55
- package/addon/components/template-comments-plugin/edit-card.hbs +7 -9
- package/addon/components/template-comments-plugin/template-comment.hbs +2 -2
- package/addon/components/template-comments-plugin/template-comment.ts +0 -36
- package/addon/components/variable-plugin/address/edit.hbs +35 -0
- package/addon/components/variable-plugin/address/edit.ts +96 -0
- package/addon/components/variable-plugin/address/insert.hbs +9 -0
- package/addon/components/variable-plugin/address/insert.ts +37 -0
- package/addon/components/variable-plugin/address/nodeview.hbs +19 -0
- package/addon/components/variable-plugin/address/nodeview.ts +31 -0
- package/addon/components/variable-plugin/{template-variable-card.hbs → codelist/edit.hbs} +14 -12
- package/addon/components/variable-plugin/codelist/edit.ts +94 -0
- package/addon/components/variable-plugin/codelist/insert.hbs +22 -0
- package/addon/components/variable-plugin/codelist/insert.ts +84 -0
- package/addon/components/variable-plugin/date/insert.hbs +9 -0
- package/addon/components/variable-plugin/date/insert.ts +45 -0
- package/addon/components/variable-plugin/insert-variable-card.hbs +7 -40
- package/addon/components/variable-plugin/insert-variable-card.ts +18 -166
- package/addon/components/variable-plugin/location/edit.hbs +40 -0
- package/addon/components/variable-plugin/location/edit.ts +122 -0
- package/addon/components/variable-plugin/location/insert.hbs +9 -0
- package/addon/components/variable-plugin/location/insert.ts +65 -0
- package/addon/components/variable-plugin/{number-settings.hbs → number/insert.hbs} +20 -9
- package/addon/components/variable-plugin/number/insert.ts +88 -0
- package/addon/components/{variable-number/number.hbs → variable-plugin/number/nodeview.hbs} +2 -2
- package/addon/components/{variable-number/number.ts → variable-plugin/number/nodeview.ts} +3 -7
- package/addon/components/variable-plugin/text/insert.hbs +9 -0
- package/addon/components/variable-plugin/text/insert.ts +49 -0
- package/addon/components/variable-plugin/utils/label-input.hbs +11 -0
- package/addon/components/variable-plugin/{variable.ts → variable/nodeview.ts} +1 -1
- package/addon/helpers/in-array.ts +13 -0
- package/addon/plugins/article-structure-plugin/structures/article-paragraph.ts +1 -1
- package/addon/plugins/rdfa-date-plugin/nodes/date.ts +48 -51
- package/addon/plugins/snippet-plugin/index.ts +20 -0
- package/addon/plugins/snippet-plugin/utils/fetch-data.ts +127 -11
- package/addon/plugins/table-of-contents-plugin/nodes/table-of-contents.ts +23 -17
- package/addon/plugins/table-of-contents-plugin/utils/index.ts +1 -1
- package/addon/plugins/template-comments-plugin/index.ts +1 -5
- package/addon/plugins/template-comments-plugin/node.ts +3 -16
- package/addon/plugins/variable-plugin/utils/address-helpers.ts +112 -0
- package/addon/plugins/variable-plugin/utils/attribute-parsers.ts +31 -0
- package/addon/plugins/variable-plugin/utils/codelist-utils.ts +56 -0
- package/addon/plugins/variable-plugin/utils/constants.ts +0 -120
- package/addon/plugins/variable-plugin/utils/dom-constructors.ts +66 -0
- package/addon/plugins/variable-plugin/utils/fetch-data.ts +2 -2
- package/addon/plugins/variable-plugin/variables/address.ts +322 -0
- package/addon/plugins/variable-plugin/variables/codelist.ts +120 -0
- package/addon/plugins/variable-plugin/variables/index.ts +5 -0
- package/addon/plugins/variable-plugin/variables/location.ts +98 -0
- package/addon/plugins/variable-plugin/variables/number.ts +145 -0
- package/addon/plugins/variable-plugin/variables/text.ts +90 -0
- package/addon/utils/constants.ts +7 -0
- package/addon/utils/dom-output-spec-helpers.ts +8 -0
- package/addon/utils/namespace.ts +11 -0
- package/app/components/snippet-plugin/snippet-list/snippet-list-modal.js +1 -0
- package/app/components/{variable-plugin/template-variable-card.js → snippet-plugin/snippet-list/snippet-list-view.js} +1 -1
- package/app/components/snippet-plugin/snippet-list-select.js +1 -0
- package/app/components/variable-plugin/{variable.js → address/edit.js} +1 -1
- package/app/components/variable-plugin/{number-settings.js → address/insert.js} +1 -1
- package/app/components/variable-plugin/address/nodeview.js +1 -0
- package/app/components/variable-plugin/codelist/edit.js +1 -0
- package/app/components/variable-plugin/codelist/insert.js +1 -0
- package/app/components/{address-plugin → variable-plugin/date}/insert.js +1 -1
- package/app/components/variable-plugin/location/edit.js +1 -0
- package/app/components/variable-plugin/location/insert.js +1 -0
- package/app/components/variable-plugin/number/insert.js +1 -0
- package/app/components/variable-plugin/number/nodeview.js +1 -0
- package/app/components/{variable-number/number.js → variable-plugin/text/insert.js} +1 -1
- package/app/components/variable-plugin/utils/label-input.js +1 -0
- package/app/components/variable-plugin/variable/nodeview.js +1 -0
- package/app/helpers/in-array.js +4 -0
- package/app/styles/snippet-plugin.scss +18 -1
- package/components/roadsign-regulation-plugin/expanded-measure.d.ts +1 -0
- package/components/roadsign-regulation-plugin/measure-template.d.ts +2 -4
- package/components/snippet-plugin/search-modal.d.ts +1 -0
- package/components/snippet-plugin/snippet-insert.d.ts +3 -1
- package/components/snippet-plugin/snippet-list/snippet-list-modal.d.ts +23 -0
- package/components/snippet-plugin/snippet-list/snippet-list-view.d.ts +10 -0
- package/components/snippet-plugin/snippet-list-select.d.ts +14 -0
- package/components/table-of-contents-plugin/ember-nodes/table-of-contents.d.ts +5 -12
- package/components/template-comments-plugin/template-comment.d.ts +0 -8
- package/components/variable-plugin/address/edit.d.ts +23 -0
- package/components/variable-plugin/address/insert.d.ts +11 -0
- package/components/variable-plugin/address/nodeview.d.ts +14 -0
- package/components/variable-plugin/codelist/edit.d.ts +27 -0
- package/components/variable-plugin/codelist/insert.d.ts +26 -0
- package/components/variable-plugin/date/insert.d.ts +13 -0
- package/components/variable-plugin/insert-variable-card.d.ts +10 -34
- package/components/variable-plugin/location/edit.d.ts +31 -0
- package/components/variable-plugin/location/insert.d.ts +20 -0
- package/components/variable-plugin/number/insert.d.ts +20 -0
- package/components/{variable-number/number.d.ts → variable-plugin/number/nodeview.d.ts} +1 -1
- package/components/variable-plugin/text/insert.d.ts +13 -0
- package/components/variable-plugin/{variable.d.ts → variable/nodeview.d.ts} +1 -1
- package/helpers/in-array.d.ts +9 -0
- package/package.json +5 -5
- package/plugins/snippet-plugin/index.d.ts +11 -0
- package/plugins/snippet-plugin/utils/fetch-data.d.ts +10 -1
- package/plugins/table-of-contents-plugin/utils/index.d.ts +1 -1
- package/plugins/template-comments-plugin/index.d.ts +1 -1
- package/plugins/template-comments-plugin/node.d.ts +0 -4
- package/plugins/variable-plugin/utils/address-helpers.d.ts +4 -0
- package/plugins/variable-plugin/utils/attribute-parsers.d.ts +5 -0
- package/plugins/variable-plugin/utils/codelist-utils.d.ts +6 -0
- package/plugins/variable-plugin/utils/constants.d.ts +0 -19
- package/plugins/variable-plugin/utils/dom-constructors.d.ts +24 -0
- package/plugins/variable-plugin/utils/fetch-data.d.ts +1 -1
- package/plugins/variable-plugin/variables/address.d.ts +23 -0
- package/plugins/variable-plugin/variables/codelist.d.ts +2 -0
- package/plugins/variable-plugin/variables/index.d.ts +5 -0
- package/plugins/variable-plugin/variables/location.d.ts +2 -0
- package/plugins/variable-plugin/variables/text.d.ts +2 -0
- package/translations/en-US.yaml +74 -2
- package/translations/nl-BE.yaml +73 -1
- package/types/global.d.ts +10 -0
- package/utils/constants.d.ts +3 -0
- package/utils/dom-output-spec-helpers.d.ts +2 -0
- package/utils/namespace.d.ts +1 -0
- package/addon/components/address-plugin/insert.hbs +0 -47
- package/addon/components/address-plugin/insert.ts +0 -100
- package/addon/components/address-plugin/types.ts +0 -26
- package/addon/components/address-plugin/utils.ts +0 -59
- package/addon/components/variable-plugin/template-variable-card.ts +0 -163
- package/addon/plugins/variable-plugin/index.ts +0 -5
- package/addon/plugins/variable-plugin/nodes.ts +0 -264
- package/addon/plugins/variable-plugin/number.ts +0 -50
- package/app/components/variable-plugin/variable-edit-modal.js +0 -1
- package/components/address-plugin/insert.d.ts +0 -21
- package/components/address-plugin/types.d.ts +0 -25
- package/components/address-plugin/utils.d.ts +0 -9
- package/components/variable-plugin/template-variable-card.d.ts +0 -29
- package/plugins/variable-plugin/index.d.ts +0 -5
- package/plugins/variable-plugin/nodes.d.ts +0 -37
- /package/addon/components/variable-plugin/{variable.hbs → variable/nodeview.hbs} +0 -0
- /package/plugins/variable-plugin/{number.d.ts → variables/number.d.ts} +0 -0
|
@@ -1,15 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
<AuFormRow>
|
|
3
|
+
<VariablePlugin::Utils::LabelInput @label={{this.label}} @updateLabel={{this.updateLabel}}/>
|
|
4
|
+
</AuFormRow>
|
|
1
5
|
<div class='number-settings'>
|
|
2
6
|
<AuFormRow>
|
|
3
7
|
{{#let (unique-id) as |id|}}
|
|
4
8
|
<AuLabel for={{id}}>
|
|
5
9
|
{{t 'variable-plugin.number.minimum'}}
|
|
6
10
|
</AuLabel>
|
|
7
|
-
<
|
|
11
|
+
<AuNativeInput
|
|
8
12
|
id={{id}}
|
|
9
|
-
|
|
13
|
+
value={{this.minimumValue}}
|
|
14
|
+
{{on 'input' this.updateMinimumValue}}
|
|
10
15
|
placeholder={{t 'variable-plugin.number.minimum-placeholder'}}
|
|
11
16
|
@width='block'
|
|
12
|
-
@type=
|
|
17
|
+
@type="number"
|
|
13
18
|
/>
|
|
14
19
|
{{/let}}
|
|
15
20
|
</AuFormRow>
|
|
@@ -19,18 +24,24 @@
|
|
|
19
24
|
<AuLabel for={{id}}>
|
|
20
25
|
{{t 'variable-plugin.number.maximum'}}
|
|
21
26
|
</AuLabel>
|
|
22
|
-
<
|
|
27
|
+
<AuNativeInput
|
|
23
28
|
id={{id}}
|
|
24
|
-
|
|
29
|
+
value={{this.maximumValue}}
|
|
30
|
+
{{on 'input' this.updateMaximumValue}}
|
|
25
31
|
placeholder={{t 'variable-plugin.number.maximum-placeholder'}}
|
|
26
32
|
@width='block'
|
|
27
|
-
@type=
|
|
33
|
+
@type="number"
|
|
28
34
|
/>
|
|
29
35
|
{{/let}}
|
|
30
36
|
</AuFormRow>
|
|
31
|
-
{{#if
|
|
37
|
+
{{#if this.numberVariableError}}
|
|
32
38
|
<AuHelpText @error={{true}}>
|
|
33
|
-
{{
|
|
39
|
+
{{this.numberVariableError}}
|
|
34
40
|
</AuHelpText>
|
|
35
41
|
{{/if}}
|
|
36
|
-
</div>
|
|
42
|
+
</div>
|
|
43
|
+
<AuButton
|
|
44
|
+
{{on 'click' this.insert}}
|
|
45
|
+
@disabled={{this.numberVariableError}}>
|
|
46
|
+
{{t 'variable-plugin.button'}}
|
|
47
|
+
</AuButton>
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { tracked } from '@glimmer/tracking';
|
|
3
|
+
import { action } from '@ember/object';
|
|
4
|
+
import { SayController } from '@lblod/ember-rdfa-editor';
|
|
5
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
6
|
+
import { isNumber } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/strings';
|
|
7
|
+
import { inject as service } from '@ember/service';
|
|
8
|
+
import IntlService from 'ember-intl/services/intl';
|
|
9
|
+
|
|
10
|
+
type Args = {
|
|
11
|
+
controller: SayController;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default class NumberInsertComponent extends Component<Args> {
|
|
15
|
+
@service declare intl: IntlService;
|
|
16
|
+
@tracked label?: string;
|
|
17
|
+
@tracked minimumValue = '';
|
|
18
|
+
@tracked maximumValue = '';
|
|
19
|
+
|
|
20
|
+
get controller() {
|
|
21
|
+
return this.args.controller;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get schema() {
|
|
25
|
+
return this.args.controller.schema;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get numberVariableError() {
|
|
29
|
+
const minVal = this.minimumValue;
|
|
30
|
+
const maxVal = this.maximumValue;
|
|
31
|
+
if (
|
|
32
|
+
isNumber(minVal) &&
|
|
33
|
+
isNumber(maxVal) &&
|
|
34
|
+
Number(minVal) > Number(maxVal)
|
|
35
|
+
) {
|
|
36
|
+
return this.intl.t('variable.number.error-min-bigger-than-max');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return '';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@action
|
|
43
|
+
updateLabel(event: InputEvent) {
|
|
44
|
+
this.label = (event.target as HTMLInputElement).value;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@action
|
|
48
|
+
updateMinimumValue(event: InputEvent) {
|
|
49
|
+
this.minimumValue = (event.target as HTMLInputElement).value;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@action
|
|
53
|
+
updateMaximumValue(event: InputEvent) {
|
|
54
|
+
this.maximumValue = (event.target as HTMLInputElement).value;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@action
|
|
58
|
+
insert() {
|
|
59
|
+
if (this.numberVariableError !== '') return;
|
|
60
|
+
|
|
61
|
+
const mappingResource = `http://data.lblod.info/mappings/${uuidv4()}`;
|
|
62
|
+
const variableInstance = `http://data.lblod.info/variables/${uuidv4()}`;
|
|
63
|
+
|
|
64
|
+
const node = this.schema.nodes.number.create({
|
|
65
|
+
label: this.label,
|
|
66
|
+
value: null,
|
|
67
|
+
mappingResource,
|
|
68
|
+
variableInstance,
|
|
69
|
+
...(isNumber(this.minimumValue) && {
|
|
70
|
+
minimumValue: Number(this.minimumValue),
|
|
71
|
+
}),
|
|
72
|
+
...(isNumber(this.maximumValue) && {
|
|
73
|
+
maximumValue: Number(this.maximumValue),
|
|
74
|
+
}),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
this.label = undefined;
|
|
78
|
+
this.minimumValue = '';
|
|
79
|
+
this.maximumValue = '';
|
|
80
|
+
|
|
81
|
+
this.controller.withTransaction(
|
|
82
|
+
(tr) => {
|
|
83
|
+
return tr.replaceSelectionWith(node);
|
|
84
|
+
},
|
|
85
|
+
{ view: this.controller.mainEditorView },
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
>
|
|
34
34
|
<card.content>
|
|
35
35
|
{{!-- template-lint-disable no-down-event-binding --}}
|
|
36
|
-
<
|
|
37
|
-
|
|
36
|
+
<AuNativeInput
|
|
37
|
+
value={{this.inputNumber}}
|
|
38
38
|
placeholder={{t 'variable.number.type-number'}}
|
|
39
39
|
{{did-insert this.focus}}
|
|
40
40
|
{{on 'input' this.onInputNumberChange}}
|
|
@@ -11,10 +11,6 @@ import { action } from '@ember/object';
|
|
|
11
11
|
import { inject as service } from '@ember/service';
|
|
12
12
|
import intlService from 'ember-intl/services/intl';
|
|
13
13
|
import { localCopy } from 'tracked-toolbox';
|
|
14
|
-
import {
|
|
15
|
-
MAXIMUM_VALUE_PNODE_KEY,
|
|
16
|
-
MINIMUM_VALUE_PNODE_KEY,
|
|
17
|
-
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/constants';
|
|
18
14
|
import { isBlank } from '@ember/utils';
|
|
19
15
|
import { isNumber } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/strings';
|
|
20
16
|
import { numberToWords } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/number-to-words';
|
|
@@ -28,7 +24,7 @@ type Args = {
|
|
|
28
24
|
selected: boolean;
|
|
29
25
|
contentDecorations?: DecorationSource;
|
|
30
26
|
};
|
|
31
|
-
export default class
|
|
27
|
+
export default class NumberNodeviewComponent extends Component<Args> {
|
|
32
28
|
@localCopy('args.node.attrs.value', '') declare inputNumber: string;
|
|
33
29
|
@localCopy('args.node.attrs.writtenNumber', false)
|
|
34
30
|
declare writtenNumber: boolean;
|
|
@@ -60,11 +56,11 @@ export default class VariableNumberPluginNumberComponent extends Component<Args>
|
|
|
60
56
|
}
|
|
61
57
|
|
|
62
58
|
get minValue() {
|
|
63
|
-
return this.node.attrs
|
|
59
|
+
return this.node.attrs.minimumValue as number;
|
|
64
60
|
}
|
|
65
61
|
|
|
66
62
|
get maxValue() {
|
|
67
|
-
return this.node.attrs
|
|
63
|
+
return this.node.attrs.maximumValue as number;
|
|
68
64
|
}
|
|
69
65
|
|
|
70
66
|
@action onInputNumberChange(event: InputEvent) {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { tracked } from '@glimmer/tracking';
|
|
3
|
+
import { action } from '@ember/object';
|
|
4
|
+
import { SayController } from '@lblod/ember-rdfa-editor';
|
|
5
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
6
|
+
|
|
7
|
+
type Args = {
|
|
8
|
+
controller: SayController;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default class TextVariableInsertComponent extends Component<Args> {
|
|
12
|
+
@tracked label?: string;
|
|
13
|
+
|
|
14
|
+
get controller() {
|
|
15
|
+
return this.args.controller;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get schema() {
|
|
19
|
+
return this.args.controller.schema;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@action
|
|
23
|
+
updateLabel(event: InputEvent) {
|
|
24
|
+
this.label = (event.target as HTMLInputElement).value;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@action
|
|
28
|
+
insert() {
|
|
29
|
+
const mappingResource = `http://data.lblod.info/mappings/${uuidv4()}`;
|
|
30
|
+
const variableInstance = `http://data.lblod.info/variables/${uuidv4()}`;
|
|
31
|
+
const node = this.schema.nodes.text_variable.create(
|
|
32
|
+
{
|
|
33
|
+
label: this.label,
|
|
34
|
+
mappingResource,
|
|
35
|
+
variableInstance,
|
|
36
|
+
},
|
|
37
|
+
this.schema.node('placeholder', { placeholderText: 'text' }),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
this.label = undefined;
|
|
41
|
+
|
|
42
|
+
this.controller.withTransaction(
|
|
43
|
+
(tr) => {
|
|
44
|
+
return tr.replaceSelectionWith(node);
|
|
45
|
+
},
|
|
46
|
+
{ view: this.controller.mainEditorView },
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { helper } from '@ember/component/helper';
|
|
2
|
+
|
|
3
|
+
type PositionalParams = [array: unknown[], needle: unknown];
|
|
4
|
+
|
|
5
|
+
function inArray([theArray, needle]: PositionalParams) {
|
|
6
|
+
if (!Array.isArray(theArray)) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return theArray.includes(needle);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default helper<PositionalParams>(inArray);
|
|
@@ -53,7 +53,7 @@ const contentSelector = `span[property~='${SAY('body').prefixed}'],
|
|
|
53
53
|
span[property~='${SAY('body').full}']`;
|
|
54
54
|
|
|
55
55
|
export const article_paragraph: NodeSpec = {
|
|
56
|
-
content: '
|
|
56
|
+
content: 'block*',
|
|
57
57
|
inline: false,
|
|
58
58
|
isolating: true,
|
|
59
59
|
defining: true,
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
EmberNodeConfig,
|
|
5
5
|
} from '@lblod/ember-rdfa-editor/utils/ember-node';
|
|
6
6
|
import {
|
|
7
|
-
DCT,
|
|
8
7
|
EXT,
|
|
9
8
|
XSD,
|
|
10
9
|
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
|
|
@@ -12,10 +11,20 @@ import { hasRDFaAttribute } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/n
|
|
|
12
11
|
import { DateOptions } from '..';
|
|
13
12
|
import { formatDate, validateDateFormat } from '../utils';
|
|
14
13
|
import { PNode } from '@lblod/ember-rdfa-editor';
|
|
14
|
+
import {
|
|
15
|
+
isVariable,
|
|
16
|
+
parseLabel,
|
|
17
|
+
parseVariableType,
|
|
18
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/attribute-parsers';
|
|
19
|
+
import {
|
|
20
|
+
mappingSpan,
|
|
21
|
+
typeSpan,
|
|
22
|
+
} from '../../variable-plugin/utils/dom-constructors';
|
|
23
|
+
import { span } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/dom-output-spec-helpers';
|
|
15
24
|
|
|
16
25
|
const emberNodeConfig = (options: DateOptions): EmberNodeConfig => ({
|
|
17
26
|
name: 'date',
|
|
18
|
-
group: 'inline',
|
|
27
|
+
group: 'inline variable',
|
|
19
28
|
componentPath: 'rdfa-date-plugin/date',
|
|
20
29
|
inline: true,
|
|
21
30
|
selectable: true,
|
|
@@ -41,7 +50,7 @@ const emberNodeConfig = (options: DateOptions): EmberNodeConfig => ({
|
|
|
41
50
|
default: false,
|
|
42
51
|
},
|
|
43
52
|
label: {
|
|
44
|
-
default: '',
|
|
53
|
+
default: 'datum',
|
|
45
54
|
},
|
|
46
55
|
},
|
|
47
56
|
leafText: (node: PNode) => {
|
|
@@ -77,19 +86,14 @@ const emberNodeConfig = (options: DateOptions): EmberNodeConfig => ({
|
|
|
77
86
|
...(!!value && { content: value as string }),
|
|
78
87
|
};
|
|
79
88
|
if (mappingResource) {
|
|
80
|
-
return
|
|
81
|
-
|
|
82
|
-
{
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
'data-label': label as string,
|
|
87
|
-
},
|
|
88
|
-
['span', { property: DCT('type').prefixed, content: 'date' }],
|
|
89
|
-
['span', dateAttrs, humanReadableDate],
|
|
90
|
-
];
|
|
89
|
+
return mappingSpan(
|
|
90
|
+
mappingResource,
|
|
91
|
+
{ class: 'date', 'data-label': label as string },
|
|
92
|
+
typeSpan('date'),
|
|
93
|
+
span(dateAttrs, humanReadableDate),
|
|
94
|
+
);
|
|
91
95
|
} else {
|
|
92
|
-
return
|
|
96
|
+
return span({ class: 'date', ...dateAttrs }, humanReadableDate);
|
|
93
97
|
}
|
|
94
98
|
},
|
|
95
99
|
parseDOM: [
|
|
@@ -114,50 +118,43 @@ const emberNodeConfig = (options: DateOptions): EmberNodeConfig => ({
|
|
|
114
118
|
{
|
|
115
119
|
tag: 'span',
|
|
116
120
|
getAttrs: (node: HTMLElement) => {
|
|
117
|
-
if (
|
|
121
|
+
if (isVariable(node) && parseVariableType(node) === 'date') {
|
|
118
122
|
const mappingResource = node.getAttribute('resource');
|
|
119
123
|
if (!mappingResource) {
|
|
120
124
|
return false;
|
|
121
125
|
}
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
) as HTMLElement | undefined;
|
|
135
|
-
let humanReadableDate: string;
|
|
136
|
-
const value = dateNode?.getAttribute('content');
|
|
137
|
-
const format = dateNode?.dataset.format;
|
|
138
|
-
if (value && format) {
|
|
139
|
-
if (validateDateFormat(format).type === 'ok') {
|
|
140
|
-
humanReadableDate = formatDate(new Date(value), format);
|
|
141
|
-
} else {
|
|
142
|
-
humanReadableDate = 'Ongeldig formaat';
|
|
143
|
-
}
|
|
126
|
+
const onlyDate = !![...node.children].find((el) =>
|
|
127
|
+
hasRDFaAttribute(el, 'datatype', XSD('date')),
|
|
128
|
+
);
|
|
129
|
+
const dateNode = [...node.children].find((el) =>
|
|
130
|
+
hasRDFaAttribute(el, 'property', EXT('content')),
|
|
131
|
+
) as HTMLElement | undefined;
|
|
132
|
+
let humanReadableDate: string;
|
|
133
|
+
const value = dateNode?.getAttribute('content');
|
|
134
|
+
const format = dateNode?.dataset.format;
|
|
135
|
+
if (value && format) {
|
|
136
|
+
if (validateDateFormat(format).type === 'ok') {
|
|
137
|
+
humanReadableDate = formatDate(new Date(value), format);
|
|
144
138
|
} else {
|
|
145
|
-
humanReadableDate =
|
|
146
|
-
? options.placeholder.insertDate
|
|
147
|
-
: options.placeholder.insertDateTime;
|
|
139
|
+
humanReadableDate = 'Ongeldig formaat';
|
|
148
140
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
humanReadableDate,
|
|
154
|
-
value: value,
|
|
155
|
-
format: format,
|
|
156
|
-
custom: dateNode?.dataset.custom === 'true',
|
|
157
|
-
label,
|
|
158
|
-
};
|
|
141
|
+
} else {
|
|
142
|
+
humanReadableDate = onlyDate
|
|
143
|
+
? options.placeholder.insertDate
|
|
144
|
+
: options.placeholder.insertDateTime;
|
|
159
145
|
}
|
|
146
|
+
const label = parseLabel(node);
|
|
147
|
+
return {
|
|
148
|
+
mappingResource,
|
|
149
|
+
onlyDate,
|
|
150
|
+
humanReadableDate,
|
|
151
|
+
value: value,
|
|
152
|
+
format: format,
|
|
153
|
+
custom: dateNode?.dataset.custom === 'true',
|
|
154
|
+
label,
|
|
155
|
+
};
|
|
160
156
|
}
|
|
157
|
+
|
|
161
158
|
return false;
|
|
162
159
|
},
|
|
163
160
|
},
|
|
@@ -25,3 +25,23 @@ export class Snippet {
|
|
|
25
25
|
this.title = title;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
interface SnippetListArgs {
|
|
30
|
+
id: string | null;
|
|
31
|
+
label: string | null;
|
|
32
|
+
createdOn: string | null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const snippetListBase = 'http://lblod.data.gift/snippet-lists/';
|
|
36
|
+
|
|
37
|
+
export class SnippetList {
|
|
38
|
+
id: string | null;
|
|
39
|
+
label: string | null;
|
|
40
|
+
createdOn: string | null;
|
|
41
|
+
|
|
42
|
+
constructor({ id, label, createdOn }: SnippetListArgs) {
|
|
43
|
+
this.id = id?.replace(snippetListBase, '') ?? null;
|
|
44
|
+
this.label = label;
|
|
45
|
+
this.createdOn = dateValue(createdOn ?? undefined);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -2,35 +2,69 @@ import {
|
|
|
2
2
|
executeCountQuery,
|
|
3
3
|
executeQuery,
|
|
4
4
|
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/sparql-helpers';
|
|
5
|
-
import { Snippet } from '../index';
|
|
5
|
+
import { Snippet, SnippetList } from '../index';
|
|
6
6
|
|
|
7
|
-
type Filter = { name?: string };
|
|
7
|
+
type Filter = { name?: string; assignedSnippetListIds?: string[] };
|
|
8
8
|
type Pagination = { pageNumber: number; pageSize: number };
|
|
9
9
|
|
|
10
|
-
const
|
|
10
|
+
const sparqlEscapeString = (value: string) =>
|
|
11
|
+
'"""' + value.replace(/[\\"]/g, (match) => '\\' + match) + '"""';
|
|
12
|
+
|
|
13
|
+
const buildSnippetCountQuery = ({ name, assignedSnippetListIds }: Filter) => {
|
|
11
14
|
return `
|
|
12
15
|
PREFIX schema: <http://schema.org/>
|
|
13
16
|
PREFIX dct: <http://purl.org/dc/terms/>
|
|
14
17
|
PREFIX pav: <http://purl.org/pav/>
|
|
15
18
|
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
|
|
16
19
|
PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>
|
|
20
|
+
PREFIX prov: <http://www.w3.org/ns/prov#>
|
|
21
|
+
PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
|
|
17
22
|
|
|
18
23
|
SELECT (COUNT(?publishedSnippetVersion) AS ?count)
|
|
19
24
|
WHERE {
|
|
20
25
|
?publishedSnippetContainer a ext:PublishedSnippetContainer ;
|
|
21
|
-
pav:hasCurrentVersion ?publishedSnippetVersion
|
|
26
|
+
pav:hasCurrentVersion ?publishedSnippetVersion ;
|
|
27
|
+
ext:fromSnippetList ?fromSnippetList .
|
|
28
|
+
?fromSnippetList mu:uuid ?fromSnippetListId .
|
|
22
29
|
?publishedSnippetVersion dct:title ?title ;
|
|
23
30
|
ext:editorDocumentContent ?content ;
|
|
24
31
|
pav:createdOn ?createdOn .
|
|
25
32
|
OPTIONAL { ?publishedSnippetVersion schema:validThrough ?validThrough. }
|
|
26
33
|
FILTER(!BOUND(?validThrough) || xsd:dateTime(?validThrough) > now())
|
|
27
|
-
${
|
|
34
|
+
${
|
|
35
|
+
name
|
|
36
|
+
? `FILTER (CONTAINS(LCASE(?title), "${name.toLowerCase()}"))`
|
|
37
|
+
: ''
|
|
38
|
+
}
|
|
39
|
+
${
|
|
40
|
+
assignedSnippetListIds && assignedSnippetListIds.length
|
|
41
|
+
? `FILTER (?fromSnippetListId IN (${assignedSnippetListIds
|
|
42
|
+
.map((from) => sparqlEscapeString(from))
|
|
43
|
+
.join(', ')}))`
|
|
44
|
+
: ''
|
|
45
|
+
}
|
|
28
46
|
}
|
|
29
47
|
`;
|
|
30
48
|
};
|
|
31
49
|
|
|
32
|
-
const
|
|
33
|
-
|
|
50
|
+
const buildSnippetListCountQuery = ({ name }: Filter) => {
|
|
51
|
+
return `
|
|
52
|
+
PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>
|
|
53
|
+
SELECT (COUNT(?snippetLists) AS ?count)
|
|
54
|
+
WHERE {
|
|
55
|
+
?snippetLists a ext:SnippetList;
|
|
56
|
+
skos:prefLabel ?label.
|
|
57
|
+
${
|
|
58
|
+
name
|
|
59
|
+
? `FILTER (CONTAINS(LCASE(?label), "${name.toLowerCase()}"))`
|
|
60
|
+
: ''
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const buildSnippetFetchQuery = ({
|
|
67
|
+
filter: { name, assignedSnippetListIds },
|
|
34
68
|
pagination: { pageSize, pageNumber },
|
|
35
69
|
}: {
|
|
36
70
|
filter: Filter;
|
|
@@ -42,15 +76,30 @@ const buildFetchQuery = ({
|
|
|
42
76
|
PREFIX pav: <http://purl.org/pav/>
|
|
43
77
|
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
|
|
44
78
|
PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>
|
|
79
|
+
PREFIX prov: <http://www.w3.org/ns/prov#>
|
|
80
|
+
PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
|
|
45
81
|
|
|
46
82
|
SELECT DISTINCT ?title ?content ?createdOn
|
|
47
83
|
WHERE {
|
|
48
84
|
?publishedSnippetContainer a ext:PublishedSnippetContainer ;
|
|
49
|
-
pav:hasCurrentVersion ?publishedSnippetVersion
|
|
85
|
+
pav:hasCurrentVersion ?publishedSnippetVersion ;
|
|
86
|
+
ext:fromSnippetList ?fromSnippetList .
|
|
87
|
+
?fromSnippetList mu:uuid ?fromSnippetListId .
|
|
50
88
|
?publishedSnippetVersion dct:title ?title ;
|
|
51
89
|
ext:editorDocumentContent ?content ;
|
|
52
90
|
pav:createdOn ?createdOn .
|
|
53
|
-
${
|
|
91
|
+
${
|
|
92
|
+
name
|
|
93
|
+
? `FILTER (CONTAINS(LCASE(?title), "${name.toLowerCase()}"))`
|
|
94
|
+
: ''
|
|
95
|
+
}
|
|
96
|
+
${
|
|
97
|
+
assignedSnippetListIds && assignedSnippetListIds.length
|
|
98
|
+
? `FILTER (?fromSnippetListId IN (${assignedSnippetListIds
|
|
99
|
+
.map((from) => sparqlEscapeString(from))
|
|
100
|
+
.join(', ')}))`
|
|
101
|
+
: ''
|
|
102
|
+
}
|
|
54
103
|
OPTIONAL { ?publishedSnippetVersion schema:validThrough ?validThrough. }
|
|
55
104
|
FILTER(!BOUND(?validThrough) || xsd:dateTime(?validThrough) > now())
|
|
56
105
|
}
|
|
@@ -60,6 +109,28 @@ const buildFetchQuery = ({
|
|
|
60
109
|
`;
|
|
61
110
|
};
|
|
62
111
|
|
|
112
|
+
const buildSnippetListFetchQuery = ({
|
|
113
|
+
filter: { name },
|
|
114
|
+
}: {
|
|
115
|
+
filter: Filter;
|
|
116
|
+
}) => {
|
|
117
|
+
return `
|
|
118
|
+
PREFIX pav: <http://purl.org/pav/>
|
|
119
|
+
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
|
|
120
|
+
PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>
|
|
121
|
+
|
|
122
|
+
SELECT (?snippetLists as ?id) ?label ?createdOn WHERE {
|
|
123
|
+
?snippetLists a ext:SnippetList;
|
|
124
|
+
skos:prefLabel ?label;
|
|
125
|
+
pav:createdOn ?createdOn.
|
|
126
|
+
${
|
|
127
|
+
name
|
|
128
|
+
? `FILTER (CONTAINS(LCASE(?label), "${name.toLowerCase()}"))`
|
|
129
|
+
: ''
|
|
130
|
+
}
|
|
131
|
+
}`;
|
|
132
|
+
};
|
|
133
|
+
|
|
63
134
|
export const fetchSnippets = async ({
|
|
64
135
|
endpoint,
|
|
65
136
|
abortSignal,
|
|
@@ -71,9 +142,13 @@ export const fetchSnippets = async ({
|
|
|
71
142
|
filter: Filter;
|
|
72
143
|
pagination: Pagination;
|
|
73
144
|
}) => {
|
|
145
|
+
if (!filter.assignedSnippetListIds?.length) {
|
|
146
|
+
return { totalCount: 0, results: [] };
|
|
147
|
+
}
|
|
148
|
+
|
|
74
149
|
const totalCount = await executeCountQuery({
|
|
75
150
|
endpoint,
|
|
76
|
-
query:
|
|
151
|
+
query: buildSnippetCountQuery(filter),
|
|
77
152
|
abortSignal,
|
|
78
153
|
});
|
|
79
154
|
|
|
@@ -87,7 +162,7 @@ export const fetchSnippets = async ({
|
|
|
87
162
|
content: { value: string };
|
|
88
163
|
}>({
|
|
89
164
|
endpoint,
|
|
90
|
-
query:
|
|
165
|
+
query: buildSnippetFetchQuery({ filter, pagination }),
|
|
91
166
|
abortSignal,
|
|
92
167
|
});
|
|
93
168
|
|
|
@@ -102,3 +177,44 @@ export const fetchSnippets = async ({
|
|
|
102
177
|
|
|
103
178
|
return { totalCount, results };
|
|
104
179
|
};
|
|
180
|
+
|
|
181
|
+
export const fetchSnippetLists = async ({
|
|
182
|
+
endpoint,
|
|
183
|
+
abortSignal,
|
|
184
|
+
filter,
|
|
185
|
+
}: {
|
|
186
|
+
endpoint: string;
|
|
187
|
+
abortSignal: AbortSignal;
|
|
188
|
+
filter: Filter;
|
|
189
|
+
}) => {
|
|
190
|
+
const totalCount = await executeCountQuery({
|
|
191
|
+
endpoint,
|
|
192
|
+
query: buildSnippetListCountQuery(filter),
|
|
193
|
+
abortSignal,
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
if (totalCount === 0) {
|
|
197
|
+
return { totalCount, results: [] };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const queryResult = await executeQuery<{
|
|
201
|
+
id: { value: string };
|
|
202
|
+
label: { value: string };
|
|
203
|
+
createdOn: { value: string };
|
|
204
|
+
}>({
|
|
205
|
+
endpoint,
|
|
206
|
+
query: buildSnippetListFetchQuery({ filter }),
|
|
207
|
+
abortSignal,
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
const results = queryResult.results.bindings.map(
|
|
211
|
+
(binding) =>
|
|
212
|
+
new SnippetList({
|
|
213
|
+
id: binding.id?.value,
|
|
214
|
+
label: binding.label?.value,
|
|
215
|
+
createdOn: binding.createdOn?.value,
|
|
216
|
+
}),
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
return { totalCount, results };
|
|
220
|
+
};
|