@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
|
@@ -0,0 +1,84 @@
|
|
|
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 {
|
|
6
|
+
CodeList,
|
|
7
|
+
fetchCodeListsByPublisher,
|
|
8
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/fetch-data';
|
|
9
|
+
import { service } from '@ember/service';
|
|
10
|
+
import IntlService from 'ember-intl/services/intl';
|
|
11
|
+
import { trackedFunction } from 'ember-resources/util/function';
|
|
12
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
13
|
+
|
|
14
|
+
export type CodelistInsertOptions = {
|
|
15
|
+
publisher?: string;
|
|
16
|
+
endpoint: string;
|
|
17
|
+
};
|
|
18
|
+
type Args = {
|
|
19
|
+
controller: SayController;
|
|
20
|
+
options: CodelistInsertOptions;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default class CodelistInsertComponent extends Component<Args> {
|
|
24
|
+
@tracked selectedSubtype?: CodeList;
|
|
25
|
+
@tracked label?: string;
|
|
26
|
+
|
|
27
|
+
@service declare intl: IntlService;
|
|
28
|
+
|
|
29
|
+
get controller() {
|
|
30
|
+
return this.args.controller;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get schema() {
|
|
34
|
+
return this.args.controller.schema;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get publisher() {
|
|
38
|
+
return this.args.options.publisher;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get endpoint() {
|
|
42
|
+
return this.args.options.endpoint;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
subtypes = trackedFunction(this, async () => {
|
|
46
|
+
return fetchCodeListsByPublisher(this.endpoint, this.publisher);
|
|
47
|
+
});
|
|
48
|
+
@action
|
|
49
|
+
updateLabel(event: InputEvent) {
|
|
50
|
+
this.label = (event.target as HTMLInputElement).value;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@action
|
|
54
|
+
insert() {
|
|
55
|
+
const mappingResource = `http://data.lblod.info/mappings/${uuidv4()}`;
|
|
56
|
+
const variableInstance = `http://data.lblod.info/variables/${uuidv4()}`;
|
|
57
|
+
const node = this.schema.nodes.codelist.create(
|
|
58
|
+
{
|
|
59
|
+
mappingResource,
|
|
60
|
+
variableInstance,
|
|
61
|
+
codelistResource: this.selectedSubtype?.uri,
|
|
62
|
+
label: this.label ?? this.selectedSubtype?.label,
|
|
63
|
+
source: this.endpoint,
|
|
64
|
+
},
|
|
65
|
+
this.schema.node('placeholder', {
|
|
66
|
+
placeholderText: this.selectedSubtype?.label,
|
|
67
|
+
}),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
this.label = undefined;
|
|
71
|
+
|
|
72
|
+
this.controller.withTransaction(
|
|
73
|
+
(tr) => {
|
|
74
|
+
return tr.replaceSelectionWith(node);
|
|
75
|
+
},
|
|
76
|
+
{ view: this.controller.mainEditorView },
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@action
|
|
81
|
+
updateSubtype(subtype: CodeList) {
|
|
82
|
+
this.selectedSubtype = subtype;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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 DateVariableInsertComponent 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 node = this.schema.nodes.date.create({
|
|
31
|
+
label: this.label,
|
|
32
|
+
value: null,
|
|
33
|
+
mappingResource,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
this.label = undefined;
|
|
37
|
+
|
|
38
|
+
this.controller.withTransaction(
|
|
39
|
+
(tr) => {
|
|
40
|
+
return tr.replaceSelectionWith(node);
|
|
41
|
+
},
|
|
42
|
+
{ view: this.controller.mainEditorView },
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -17,53 +17,20 @@
|
|
|
17
17
|
<PowerSelect
|
|
18
18
|
@allowClear={{false}}
|
|
19
19
|
@searchEnabled={{false}}
|
|
20
|
-
@options={{
|
|
20
|
+
@options={{@variableTypes}}
|
|
21
21
|
@selected={{this.selectedVariable}}
|
|
22
22
|
@onChange={{this.updateSelectedVariable}}
|
|
23
23
|
as |variable|
|
|
24
24
|
>
|
|
25
25
|
{{variable.label}}
|
|
26
26
|
</PowerSelect>
|
|
27
|
-
{{#if this.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
@selected={{this.selectedSubtype}}
|
|
33
|
-
@onChange={{this.updateSubtype}}
|
|
34
|
-
as |subtype|
|
|
35
|
-
>
|
|
36
|
-
{{subtype.label}}
|
|
37
|
-
</PowerSelect>
|
|
38
|
-
{{/if}}
|
|
39
|
-
<AuFormRow>
|
|
40
|
-
<AuLabel for='label'>
|
|
41
|
-
{{t 'variable-plugin.label'}}
|
|
42
|
-
</AuLabel>
|
|
43
|
-
<AuInput
|
|
44
|
-
id="label"
|
|
45
|
-
placeholder={{t 'variable-plugin.labelPlaceholder'}}
|
|
46
|
-
@type="text"
|
|
47
|
-
@width="block"
|
|
48
|
-
@value={{this.variableLabel}}
|
|
49
|
-
{{on "input" this.updateVariableLabel}}
|
|
50
|
-
/>
|
|
51
|
-
</AuFormRow>
|
|
52
|
-
{{#if (eq this.type 'number')}}
|
|
53
|
-
<VariablePlugin::NumberSettings
|
|
54
|
-
@minimumValue={{this.extraAttributes.minimumValue}}
|
|
55
|
-
@maximumValue={{this.extraAttributes.maximumValue}}
|
|
56
|
-
@error={{this.numberVariableError}}
|
|
57
|
-
/>
|
|
58
|
-
{{/if}}
|
|
59
|
-
<AuButton
|
|
60
|
-
{{on 'click' this.insert}}
|
|
61
|
-
@disabled={{or
|
|
62
|
-
(not this.selectedVariable)
|
|
63
|
-
(and this.hasSubtype (not this.selectedSubtype))
|
|
64
|
-
this.numberVariableError
|
|
27
|
+
{{#if this.selectedVariable}}
|
|
28
|
+
{{component
|
|
29
|
+
this.selectedVariable.component.path
|
|
30
|
+
controller=this.controller
|
|
31
|
+
options=this.selectedVariable.component.options
|
|
65
32
|
}}
|
|
66
|
-
|
|
33
|
+
{{/if}}
|
|
67
34
|
</c.content>
|
|
68
35
|
</AuCard>
|
|
69
36
|
{{/if}}
|
|
@@ -1,193 +1,45 @@
|
|
|
1
1
|
import Component from '@glimmer/component';
|
|
2
2
|
import { tracked } from '@glimmer/tracking';
|
|
3
3
|
import { action } from '@ember/object';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
DEFAULT_VARIABLE_TYPES,
|
|
8
|
-
VariableType,
|
|
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';
|
|
4
|
+
import { NodeSelection, SayController } from '@lblod/ember-rdfa-editor';
|
|
5
|
+
import { hasGroups } from '@lblod/ember-rdfa-editor/utils/node-utils';
|
|
13
6
|
import { service } from '@ember/service';
|
|
14
7
|
import IntlService from 'ember-intl/services/intl';
|
|
15
|
-
import { isNumber } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/strings';
|
|
16
8
|
|
|
17
|
-
type
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
defaultEndpoint: string;
|
|
9
|
+
export type VariableConfig = {
|
|
10
|
+
label: string;
|
|
11
|
+
component: {
|
|
12
|
+
path: string;
|
|
13
|
+
options?: unknown;
|
|
23
14
|
};
|
|
24
15
|
};
|
|
25
16
|
|
|
26
|
-
type
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
asObject(): minMaxObj {
|
|
32
|
-
const obj: minMaxObj = {};
|
|
33
|
-
if (isNumber(this.minimumValue)) {
|
|
34
|
-
obj.minimumValue = Number(this.minimumValue);
|
|
35
|
-
}
|
|
36
|
-
if (isNumber(this.maximumValue)) {
|
|
37
|
-
obj.maximumValue = Number(this.maximumValue);
|
|
38
|
-
}
|
|
39
|
-
return obj;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
reset() {
|
|
43
|
-
this.minimumValue = '';
|
|
44
|
-
this.maximumValue = '';
|
|
45
|
-
}
|
|
46
|
-
}
|
|
17
|
+
type Args = {
|
|
18
|
+
controller: SayController;
|
|
19
|
+
variableTypes: VariableConfig[];
|
|
20
|
+
};
|
|
47
21
|
|
|
48
22
|
export default class EditorPluginsInsertCodelistCardComponent extends Component<Args> {
|
|
49
|
-
@tracked
|
|
50
|
-
@tracked selectedVariable?: VariableType;
|
|
51
|
-
@tracked hasSubtype = false;
|
|
52
|
-
@tracked selectedSubtype?: CodeList;
|
|
53
|
-
@tracked subtypes?: CodeList[];
|
|
54
|
-
@tracked variableLabel?: string;
|
|
55
|
-
@tracked extraAttributes = new ExtraAttributes();
|
|
56
|
-
publisher: string;
|
|
57
|
-
endpoint: string;
|
|
23
|
+
@tracked selectedVariable?: VariableConfig;
|
|
58
24
|
|
|
59
25
|
@service declare intl: IntlService;
|
|
60
26
|
|
|
61
|
-
constructor(parent: unknown, args: Args) {
|
|
62
|
-
super(parent, args);
|
|
63
|
-
const { publisher, variableTypes, defaultEndpoint } =
|
|
64
|
-
this.args.options || {};
|
|
65
|
-
this.publisher = publisher;
|
|
66
|
-
this.endpoint = defaultEndpoint;
|
|
67
|
-
const variableTypesSelectedByUser = variableTypes ?? [
|
|
68
|
-
'text',
|
|
69
|
-
'number',
|
|
70
|
-
'date',
|
|
71
|
-
'location',
|
|
72
|
-
'codelist',
|
|
73
|
-
];
|
|
74
|
-
|
|
75
|
-
const variablesArray: VariableType[] = [];
|
|
76
|
-
for (const type of variableTypesSelectedByUser) {
|
|
77
|
-
if (typeof type === 'string') {
|
|
78
|
-
const variableType = DEFAULT_VARIABLE_TYPES[type];
|
|
79
|
-
if (variableType) {
|
|
80
|
-
variablesArray.push(variableType);
|
|
81
|
-
} else {
|
|
82
|
-
console.warn(
|
|
83
|
-
`Template Variable Plugin: variable type ${type} not found in the default variable types`,
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
} else {
|
|
87
|
-
variablesArray.push(type);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
this.variablesArray = variablesArray;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
27
|
get controller() {
|
|
94
28
|
return this.args.controller;
|
|
95
29
|
}
|
|
96
30
|
|
|
97
|
-
get numberVariableError() {
|
|
98
|
-
const minVal = this.extraAttributes.minimumValue;
|
|
99
|
-
const maxVal = this.extraAttributes.maximumValue;
|
|
100
|
-
if (
|
|
101
|
-
isNumber(minVal) &&
|
|
102
|
-
isNumber(maxVal) &&
|
|
103
|
-
Number(minVal) > Number(maxVal)
|
|
104
|
-
) {
|
|
105
|
-
return this.intl.t('variable.number.error-min-bigger-than-max');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return '';
|
|
109
|
-
}
|
|
110
|
-
|
|
111
31
|
@action
|
|
112
|
-
|
|
113
|
-
this.variableLabel = (event.target as HTMLInputElement).value;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
@action
|
|
117
|
-
insert() {
|
|
118
|
-
if (!this.selectedVariable || this.numberVariableError) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const node = this.selectedVariable.constructor({
|
|
123
|
-
schema: this.controller.schema,
|
|
124
|
-
codelist: this.selectedSubtype,
|
|
125
|
-
label: this.variableLabel !== '' ? this.variableLabel : undefined,
|
|
126
|
-
attributes: {
|
|
127
|
-
source: this.endpoint,
|
|
128
|
-
...this.extraAttributes.asObject(),
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
this.variableLabel = '';
|
|
133
|
-
this.extraAttributes.reset();
|
|
134
|
-
|
|
135
|
-
this.controller.withTransaction(
|
|
136
|
-
(tr) => {
|
|
137
|
-
return tr.replaceSelectionWith(node);
|
|
138
|
-
},
|
|
139
|
-
{ view: this.controller.mainEditorView },
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
@action
|
|
144
|
-
updateSelectedVariable(variable: VariableType) {
|
|
32
|
+
updateSelectedVariable(variable: VariableConfig) {
|
|
145
33
|
this.selectedVariable = variable;
|
|
146
|
-
if (variable.fetchSubtypes) {
|
|
147
|
-
void this.fetchSubtypes.perform(variable.fetchSubtypes);
|
|
148
|
-
this.hasSubtype = true;
|
|
149
|
-
} else {
|
|
150
|
-
this.hasSubtype = false;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
fetchSubtypes = task(
|
|
155
|
-
async (
|
|
156
|
-
fetchFunction: (
|
|
157
|
-
endpoint: string,
|
|
158
|
-
publisher: string,
|
|
159
|
-
) => Promise<CodeList[]>,
|
|
160
|
-
) => {
|
|
161
|
-
const subtypes = await fetchFunction(this.endpoint, this.publisher);
|
|
162
|
-
this.subtypes = subtypes;
|
|
163
|
-
},
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
@action
|
|
167
|
-
updateSubtype(subtype: CodeList) {
|
|
168
|
-
this.selectedSubtype = subtype;
|
|
169
|
-
this.extraAttributes.reset();
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
get type() {
|
|
173
|
-
return this.selectedVariable?.label;
|
|
174
34
|
}
|
|
175
35
|
|
|
176
36
|
get showCard() {
|
|
177
|
-
if
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (
|
|
182
|
-
selection instanceof NodeSelection &&
|
|
183
|
-
selection.node.type === this.args.controller.schema.nodes.variable
|
|
184
|
-
) {
|
|
185
|
-
return false;
|
|
37
|
+
// Do not show the card if a variable is selected.
|
|
38
|
+
const { selection } = this.controller.mainEditorState;
|
|
39
|
+
if (selection instanceof NodeSelection) {
|
|
40
|
+
return !hasGroups(selection.node, 'variable');
|
|
186
41
|
} else {
|
|
187
|
-
|
|
188
|
-
this.args.controller.schema.nodes.variable,
|
|
189
|
-
)(selection);
|
|
190
|
-
return !variable;
|
|
42
|
+
return true;
|
|
191
43
|
}
|
|
192
44
|
}
|
|
193
45
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{{#if this.showCard}}
|
|
2
|
+
<AuCard @flex={{true}} @divided={{true}} @isOpenInitially={{true}} @expandable={{true}} @shadow={{true}} @size="small" as |c|>
|
|
3
|
+
<c.header>
|
|
4
|
+
<AuHeading @level="3" @skin="6">
|
|
5
|
+
{{t "variable-plugin.enter-variable-value"}}
|
|
6
|
+
</AuHeading>
|
|
7
|
+
</c.header>
|
|
8
|
+
<c.content>
|
|
9
|
+
<AuLabel for='location-select'>
|
|
10
|
+
{{this.label}}
|
|
11
|
+
</AuLabel>
|
|
12
|
+
{{#if this.multiSelect}}
|
|
13
|
+
<PowerSelectMultiple
|
|
14
|
+
id="location-select"
|
|
15
|
+
@allowClear={{false}}
|
|
16
|
+
@searchEnabled={{false}}
|
|
17
|
+
@options={{this.locationOptions.value.options}}
|
|
18
|
+
@selected={{this.selectedLocationOption}}
|
|
19
|
+
@onChange={{this.updateLocationOption}} as |option|
|
|
20
|
+
>
|
|
21
|
+
{{option.label}}
|
|
22
|
+
</PowerSelectMultiple>
|
|
23
|
+
{{else}}
|
|
24
|
+
<PowerSelect
|
|
25
|
+
id="location-select"
|
|
26
|
+
@allowClear={{false}}
|
|
27
|
+
@searchEnabled={{false}}
|
|
28
|
+
@options={{this.locationOptions.value.options}}
|
|
29
|
+
@selected={{this.selectedLocationOption}}
|
|
30
|
+
@onChange={{this.updateLocationOption}} as |option|
|
|
31
|
+
>
|
|
32
|
+
{{option.label}}
|
|
33
|
+
</PowerSelect>
|
|
34
|
+
{{/if}}
|
|
35
|
+
<AuButton {{on 'click' this.insert}} @disabled={{not this.selectedLocationOption}}>
|
|
36
|
+
{{t "editor-plugins.utils.insert"}}
|
|
37
|
+
</AuButton>
|
|
38
|
+
</c.content>
|
|
39
|
+
</AuCard>
|
|
40
|
+
{{/if}}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { action } from '@ember/object';
|
|
3
|
+
import { SayController } from '@lblod/ember-rdfa-editor';
|
|
4
|
+
import {
|
|
5
|
+
CodeListOption,
|
|
6
|
+
fetchCodeListOptions,
|
|
7
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/fetch-data';
|
|
8
|
+
import { MULTI_SELECT_CODELIST_TYPE } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/constants';
|
|
9
|
+
import { findParentNodeOfType } from '@curvenote/prosemirror-utils';
|
|
10
|
+
import { NodeSelection } from '@lblod/ember-rdfa-editor';
|
|
11
|
+
import { ZONAL_URI } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/roadsign-regulation-plugin/utils/constants';
|
|
12
|
+
import { unwrap } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/option';
|
|
13
|
+
import { trackedFunction } from 'ember-resources/util/function';
|
|
14
|
+
import { trackedReset } from 'tracked-toolbox';
|
|
15
|
+
import { updateCodelistVariable } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/codelist-utils';
|
|
16
|
+
|
|
17
|
+
export type LocationEditOptions = {
|
|
18
|
+
endpoint: string;
|
|
19
|
+
zonalLocationCodelistUri: string;
|
|
20
|
+
nonZonalLocationCodelistUri: string;
|
|
21
|
+
};
|
|
22
|
+
type Args = {
|
|
23
|
+
controller: SayController;
|
|
24
|
+
options: LocationEditOptions;
|
|
25
|
+
};
|
|
26
|
+
export default class LocationEditComponent extends Component<Args> {
|
|
27
|
+
@trackedReset('locationOptions.value') selectedLocationOption?:
|
|
28
|
+
| CodeListOption
|
|
29
|
+
| CodeListOption[];
|
|
30
|
+
|
|
31
|
+
get controller() {
|
|
32
|
+
return this.args.controller;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get options() {
|
|
36
|
+
return this.args.options;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@action
|
|
40
|
+
insert() {
|
|
41
|
+
if (!this.selectedLocation || !this.selectedLocationOption) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
updateCodelistVariable(
|
|
45
|
+
this.selectedLocation,
|
|
46
|
+
this.selectedLocationOption,
|
|
47
|
+
this.controller,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get selectedLocation() {
|
|
52
|
+
const { selection } = this.controller.mainEditorState;
|
|
53
|
+
if (
|
|
54
|
+
selection instanceof NodeSelection &&
|
|
55
|
+
selection.node.type === this.controller.schema.nodes.location
|
|
56
|
+
) {
|
|
57
|
+
return {
|
|
58
|
+
node: selection.node,
|
|
59
|
+
pos: selection.from,
|
|
60
|
+
};
|
|
61
|
+
} else {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
get showCard() {
|
|
67
|
+
return !!this.selectedLocation;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get source() {
|
|
71
|
+
return (
|
|
72
|
+
(this.selectedLocation?.node.attrs.source as string | undefined) ??
|
|
73
|
+
this.args.options.endpoint
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get label() {
|
|
78
|
+
return this.selectedLocation?.node.attrs.label as string | undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get isZonal() {
|
|
82
|
+
const { selection } = this.controller.mainEditorState;
|
|
83
|
+
const roadSignRegulation = findParentNodeOfType(
|
|
84
|
+
this.controller.schema.nodes.roadsign_regulation,
|
|
85
|
+
)(selection);
|
|
86
|
+
const zonalityUri = roadSignRegulation?.node.attrs.zonality as
|
|
87
|
+
| string
|
|
88
|
+
| undefined;
|
|
89
|
+
return zonalityUri === ZONAL_URI;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
locationOptions = trackedFunction(this, async () => {
|
|
93
|
+
const result = await fetchCodeListOptions(
|
|
94
|
+
this.source,
|
|
95
|
+
this.isZonal
|
|
96
|
+
? this.options.zonalLocationCodelistUri
|
|
97
|
+
: this.options.nonZonalLocationCodelistUri,
|
|
98
|
+
);
|
|
99
|
+
result.options = result.options.map((option) => ({
|
|
100
|
+
label: option.label,
|
|
101
|
+
value: this.wrapInLocation(unwrap(option.value)),
|
|
102
|
+
}));
|
|
103
|
+
return result;
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
get multiSelect() {
|
|
107
|
+
return this.locationOptions.value?.type === MULTI_SELECT_CODELIST_TYPE;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@action
|
|
111
|
+
updateLocationOption(locationOption: CodeListOption | CodeListOption[]) {
|
|
112
|
+
this.selectedLocationOption = locationOption;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
wrapInLocation(value: string) {
|
|
116
|
+
return `
|
|
117
|
+
<span property="https://data.vlaanderen.be/ns/mobiliteit#plaatsbepaling">
|
|
118
|
+
${value}
|
|
119
|
+
</span>
|
|
120
|
+
`;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 { service } from '@ember/service';
|
|
6
|
+
import IntlService from 'ember-intl/services/intl';
|
|
7
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
8
|
+
|
|
9
|
+
export type LocationInsertOptions = {
|
|
10
|
+
endpoint: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type Args = {
|
|
14
|
+
controller: SayController;
|
|
15
|
+
options: LocationInsertOptions;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default class LocationInsertComponent extends Component<Args> {
|
|
19
|
+
@tracked label?: string;
|
|
20
|
+
|
|
21
|
+
@service declare intl: IntlService;
|
|
22
|
+
|
|
23
|
+
get controller() {
|
|
24
|
+
return this.args.controller;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get schema() {
|
|
28
|
+
return this.controller.schema;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get endpoint() {
|
|
32
|
+
return this.args.options.endpoint;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@action
|
|
36
|
+
updateLabel(event: InputEvent) {
|
|
37
|
+
this.label = (event.target as HTMLInputElement).value;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@action
|
|
41
|
+
insert() {
|
|
42
|
+
const mappingResource = `http://data.lblod.info/mappings/${uuidv4()}`;
|
|
43
|
+
const variableInstance = `http://data.lblod.info/variables/${uuidv4()}`;
|
|
44
|
+
const node = this.schema.nodes.location.create(
|
|
45
|
+
{
|
|
46
|
+
mappingResource,
|
|
47
|
+
variableInstance,
|
|
48
|
+
label: this.label,
|
|
49
|
+
source: this.endpoint,
|
|
50
|
+
},
|
|
51
|
+
this.schema.node('placeholder', {
|
|
52
|
+
placeholderText: 'location',
|
|
53
|
+
}),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
this.label = undefined;
|
|
57
|
+
|
|
58
|
+
this.controller.withTransaction(
|
|
59
|
+
(tr) => {
|
|
60
|
+
return tr.replaceSelectionWith(node);
|
|
61
|
+
},
|
|
62
|
+
{ view: this.controller.mainEditorView },
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
}
|