@lblod/ember-rdfa-editor-lblod-plugins 23.1.0 → 24.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 +12 -0
- package/addon/components/snippet-plugin/nodes/snippet.gts +18 -8
- package/addon/components/snippet-plugin/snippet-insert-placeholder.gts +10 -2
- package/addon/components/snippet-plugin/snippet-insert-rdfa.gts +5 -0
- package/addon/components/snippet-plugin/snippet-insert.gts +2 -0
- package/addon/components/snippet-plugin/snippet-list/snippet-list-modal.hbs +23 -12
- package/addon/components/snippet-plugin/snippet-list/snippet-list-modal.ts +18 -3
- package/addon/components/snippet-plugin/snippet-list-select.gts +7 -1
- package/addon/components/variable-plugin/autofilled/edit.gts +224 -0
- package/addon/components/variable-plugin/autofilled/insert.gts +143 -0
- package/addon/components/variable-plugin/autofilled/nodeview.gts +100 -0
- package/addon/components/variable-plugin/utils/label-input.gts +28 -0
- package/addon/plugins/citation-plugin/utils/public-decisions.ts +7 -6
- package/addon/plugins/citation-plugin/utils/vlaamse-codex.ts +7 -6
- package/addon/plugins/snippet-plugin/commands/insert-snippet.ts +4 -1
- package/addon/plugins/snippet-plugin/commands/update-snippet-placeholder.ts +7 -0
- package/addon/plugins/snippet-plugin/nodes/snippet-placeholder.ts +10 -1
- package/addon/plugins/snippet-plugin/nodes/snippet.ts +7 -0
- package/addon/plugins/snippet-plugin/utils/fetch-data.ts +32 -29
- package/addon/plugins/variable-plugin/plugins/autofiller.ts +98 -0
- package/addon/plugins/variable-plugin/variables/autofilled.ts +170 -0
- package/addon/plugins/variable-plugin/variables/index.ts +1 -0
- package/addon/services/roadsign-registry.ts +2 -1
- package/app/components/variable-plugin/autofilled/edit.js +1 -0
- package/app/components/variable-plugin/autofilled/insert.js +1 -0
- package/app/components/variable-plugin/autofilled/nodeview.js +1 -0
- package/declarations/addon/components/snippet-plugin/nodes/snippet.d.ts +1 -0
- package/declarations/addon/components/snippet-plugin/snippet-insert-placeholder.d.ts +1 -1
- package/declarations/addon/components/snippet-plugin/snippet-insert-rdfa.d.ts +1 -0
- package/declarations/addon/components/snippet-plugin/snippet-insert.d.ts +1 -0
- package/declarations/addon/components/snippet-plugin/snippet-list/snippet-list-modal.d.ts +4 -1
- package/declarations/addon/components/snippet-plugin/snippet-list-select.d.ts +2 -1
- package/declarations/addon/components/variable-plugin/autofilled/edit.d.ts +28 -0
- package/declarations/addon/components/variable-plugin/autofilled/insert.d.ts +20 -0
- package/declarations/addon/components/variable-plugin/autofilled/nodeview.d.ts +22 -0
- package/declarations/addon/components/variable-plugin/utils/label-input.d.ts +11 -1
- package/declarations/addon/plugins/snippet-plugin/commands/insert-snippet.d.ts +2 -1
- package/declarations/addon/plugins/snippet-plugin/commands/update-snippet-placeholder.d.ts +2 -1
- package/declarations/addon/plugins/snippet-plugin/nodes/snippet-placeholder.d.ts +1 -1
- package/declarations/addon/plugins/snippet-plugin/nodes/snippet.d.ts +2 -1
- package/declarations/addon/plugins/variable-plugin/plugins/autofiller.d.ts +8 -0
- package/declarations/addon/plugins/variable-plugin/variables/autofilled.d.ts +2 -0
- package/declarations/addon/plugins/variable-plugin/variables/index.d.ts +1 -0
- package/package.json +1 -1
- package/translations/en-US.yaml +7 -0
- package/translations/nl-BE.yaml +7 -0
- package/addon/components/variable-plugin/utils/label-input.hbs +0 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @lblod/ember-rdfa-editor-lblod-plugins
|
|
2
2
|
|
|
3
|
+
## 24.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#482](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/482) [`8c46ded`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/8c46deddb0ab3d156b27fb555709e6489f647ced) Thanks [@elpoelma](https://github.com/elpoelma)! - Adjust snippet queries to work with new snippet data-model
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- [#472](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/472) [`a114436`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/a114436ce7b0a7a4f2fca9faf494729169554dbd) Thanks [@lagartoverde](https://github.com/lagartoverde)! - Add autofill variable
|
|
12
|
+
|
|
13
|
+
- [#484](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/484) [`14e8c57`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/14e8c5746b7674dfa3e0d968d4ce16c5855ffff3) Thanks [@elpoelma](https://github.com/elpoelma)! - Add option for enabling/disabling multi-snippet insertion
|
|
14
|
+
|
|
3
15
|
## 23.1.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -81,10 +81,17 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
81
81
|
this.controller.focus();
|
|
82
82
|
this.showModal = true;
|
|
83
83
|
}
|
|
84
|
+
|
|
85
|
+
get allowMultipleSnippets() {
|
|
86
|
+
return this.node.attrs.allowMultipleSnippets as boolean;
|
|
87
|
+
}
|
|
88
|
+
|
|
84
89
|
@action
|
|
85
90
|
addFragment() {
|
|
86
|
-
this.
|
|
87
|
-
|
|
91
|
+
if (this.allowMultipleSnippets) {
|
|
92
|
+
this.mode = 'add';
|
|
93
|
+
this.openModal();
|
|
94
|
+
}
|
|
88
95
|
}
|
|
89
96
|
@action
|
|
90
97
|
editFragment() {
|
|
@@ -151,6 +158,7 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
151
158
|
assignedSnippetListsIds,
|
|
152
159
|
importedResources: this.node.attrs.importedResources,
|
|
153
160
|
range: { start, end },
|
|
161
|
+
allowMultipleSnippets: this.allowMultipleSnippets,
|
|
154
162
|
}),
|
|
155
163
|
);
|
|
156
164
|
}
|
|
@@ -173,12 +181,14 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
173
181
|
@isActive={{this.isActive}}
|
|
174
182
|
class='say-snippet-remove-button'
|
|
175
183
|
/>
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
184
|
+
{{#if this.allowMultipleSnippets}}
|
|
185
|
+
<SnippetButton
|
|
186
|
+
@icon={{AddIcon}}
|
|
187
|
+
@helpText='snippet-plugin.snippet-node.add-fragment'
|
|
188
|
+
@onClick={{this.addFragment}}
|
|
189
|
+
@isActive={{this.isActive}}
|
|
190
|
+
/>
|
|
191
|
+
{{/if}}
|
|
182
192
|
</div>
|
|
183
193
|
|
|
184
194
|
</div>
|
|
@@ -38,9 +38,16 @@ export default class SnippetPluginSnippetInsertPlaceholder extends Component<Sig
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
@action
|
|
41
|
-
insertPlaceholder(
|
|
41
|
+
insertPlaceholder(
|
|
42
|
+
lists: SnippetList[] | undefined,
|
|
43
|
+
allowMultipleSnippets: boolean,
|
|
44
|
+
) {
|
|
42
45
|
if (lists) {
|
|
43
|
-
const node = createSnippetPlaceholder(
|
|
46
|
+
const node = createSnippetPlaceholder(
|
|
47
|
+
lists,
|
|
48
|
+
this.args.controller.schema,
|
|
49
|
+
allowMultipleSnippets,
|
|
50
|
+
);
|
|
44
51
|
|
|
45
52
|
this.args.controller.withTransaction(
|
|
46
53
|
(tr) => {
|
|
@@ -66,6 +73,7 @@ export default class SnippetPluginSnippetInsertPlaceholder extends Component<Sig
|
|
|
66
73
|
<SnippetListModal
|
|
67
74
|
@config={{@config}}
|
|
68
75
|
@assignedSnippetListsIds={{empty}}
|
|
76
|
+
@allowMultipleSnippets={{false}}
|
|
69
77
|
@onSaveSnippetLists={{this.insertPlaceholder}}
|
|
70
78
|
@open={{this.isModalOpen}}
|
|
71
79
|
@closeModal={{this.closeModal}}
|
|
@@ -71,12 +71,17 @@ export default class SnippetInsertRdfaComponent extends Component<Sig> {
|
|
|
71
71
|
return undefined;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
get allowMultipleSnippets() {
|
|
75
|
+
return this.args.node.value.attrs.allowMultipleSnippets as boolean;
|
|
76
|
+
}
|
|
77
|
+
|
|
74
78
|
<template>
|
|
75
79
|
<SnippetInsert
|
|
76
80
|
@config={{@config}}
|
|
77
81
|
@controller={{@controller}}
|
|
78
82
|
@snippetListProperties={{this.snippetListProperties}}
|
|
79
83
|
@disabled={{this.disableInsert}}
|
|
84
|
+
@allowMultipleSnippets={{this.allowMultipleSnippets}}
|
|
80
85
|
/>
|
|
81
86
|
</template>
|
|
82
87
|
}
|
|
@@ -23,6 +23,7 @@ interface Sig {
|
|
|
23
23
|
| { listIds: string[]; importedResources: ImportedResourceMap }
|
|
24
24
|
| undefined;
|
|
25
25
|
disabled?: boolean;
|
|
26
|
+
allowMultipleSnippets?: boolean;
|
|
26
27
|
};
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -63,6 +64,7 @@ export default class SnippetInsertComponent extends Component<Sig> {
|
|
|
63
64
|
title,
|
|
64
65
|
assignedSnippetListsIds: this.args.snippetListProperties?.listIds || [],
|
|
65
66
|
importedResources: this.args.snippetListProperties?.importedResources,
|
|
67
|
+
allowMultipleSnippets: this.args.allowMultipleSnippets,
|
|
66
68
|
}),
|
|
67
69
|
);
|
|
68
70
|
}
|
|
@@ -31,20 +31,31 @@
|
|
|
31
31
|
@border='top'
|
|
32
32
|
@size='large'
|
|
33
33
|
@nowrap={{true}}
|
|
34
|
-
|
|
34
|
+
class='au-u-flex--vertical-center'
|
|
35
|
+
as |Group|
|
|
35
36
|
>
|
|
36
|
-
<
|
|
37
|
-
<
|
|
38
|
-
{{
|
|
39
|
-
|
|
40
|
-
<AuButton
|
|
41
|
-
@skin='primary'
|
|
42
|
-
{{on 'click' this.saveAndClose}}
|
|
43
|
-
@disabled={{@onSaveSnippetLists.isRunning}}
|
|
37
|
+
<Group>
|
|
38
|
+
<AuCheckbox
|
|
39
|
+
@checked={{this.allowMultipleSnippets}}
|
|
40
|
+
@onChange={{this.handleMultipleSnippetsCheckbox}}
|
|
44
41
|
>
|
|
45
|
-
{{t 'snippet-plugin.snippet-list.modal.
|
|
46
|
-
</
|
|
47
|
-
</
|
|
42
|
+
{{t 'snippet-plugin.snippet-list.modal.multi-snippet-toggle'}}
|
|
43
|
+
</AuCheckbox>
|
|
44
|
+
</Group>
|
|
45
|
+
<Group>
|
|
46
|
+
<AuButtonGroup>
|
|
47
|
+
<AuButton @skin='secondary' {{on 'click' this.closeModal}}>
|
|
48
|
+
{{t 'snippet-plugin.snippet-list.modal.button.cancel'}}
|
|
49
|
+
</AuButton>
|
|
50
|
+
<AuButton
|
|
51
|
+
@skin='primary'
|
|
52
|
+
{{on 'click' this.saveAndClose}}
|
|
53
|
+
@disabled={{@onSaveSnippetLists.isRunning}}
|
|
54
|
+
>
|
|
55
|
+
{{t 'snippet-plugin.snippet-list.modal.button.update'}}
|
|
56
|
+
</AuButton>
|
|
57
|
+
</AuButtonGroup>
|
|
58
|
+
</Group>
|
|
48
59
|
</AuToolbar>
|
|
49
60
|
</mc.content>
|
|
50
61
|
</AuMainContainer>
|
|
@@ -14,15 +14,19 @@ import {
|
|
|
14
14
|
SnippetPluginConfig,
|
|
15
15
|
SnippetList,
|
|
16
16
|
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
17
|
-
import { trackedReset } from 'tracked-toolbox';
|
|
17
|
+
import { localCopy, trackedReset } from 'tracked-toolbox';
|
|
18
18
|
|
|
19
19
|
interface Signature {
|
|
20
20
|
Args: {
|
|
21
21
|
config: SnippetPluginConfig;
|
|
22
|
-
onSaveSnippetLists: (
|
|
22
|
+
onSaveSnippetLists: (
|
|
23
|
+
lists: SnippetList[],
|
|
24
|
+
allowMultipleSnippets: boolean,
|
|
25
|
+
) => void;
|
|
23
26
|
assignedSnippetListsIds: string[] | undefined;
|
|
24
27
|
closeModal: () => void;
|
|
25
28
|
open: boolean;
|
|
29
|
+
allowMultipleSnippets?: boolean;
|
|
26
30
|
};
|
|
27
31
|
}
|
|
28
32
|
|
|
@@ -41,12 +45,20 @@ export default class SnippetListModalComponent extends Component<Signature> {
|
|
|
41
45
|
...(this.args.assignedSnippetListsIds ?? []),
|
|
42
46
|
];
|
|
43
47
|
|
|
48
|
+
@localCopy('args.allowMultipleSnippets') allowMultipleSnippets = false;
|
|
49
|
+
|
|
50
|
+
@action
|
|
51
|
+
handleMultipleSnippetsCheckbox(checked: boolean) {
|
|
52
|
+
this.allowMultipleSnippets = checked;
|
|
53
|
+
}
|
|
54
|
+
|
|
44
55
|
get config() {
|
|
45
56
|
return this.args.config;
|
|
46
57
|
}
|
|
47
58
|
|
|
48
59
|
@action
|
|
49
60
|
closeModal() {
|
|
61
|
+
this.allowMultipleSnippets = this.args.allowMultipleSnippets ?? false;
|
|
50
62
|
this.args.closeModal();
|
|
51
63
|
}
|
|
52
64
|
|
|
@@ -55,7 +67,10 @@ export default class SnippetListModalComponent extends Component<Signature> {
|
|
|
55
67
|
const snippetLists = this.snippetListResource.value?.filter((snippetList) =>
|
|
56
68
|
this.assignedSnippetListsIds.includes(snippetList.id),
|
|
57
69
|
);
|
|
58
|
-
this.args.onSaveSnippetLists(
|
|
70
|
+
this.args.onSaveSnippetLists(
|
|
71
|
+
snippetLists || [],
|
|
72
|
+
this.allowMultipleSnippets,
|
|
73
|
+
);
|
|
59
74
|
this.args.closeModal();
|
|
60
75
|
// Clear selection for next time
|
|
61
76
|
this.assignedSnippetListsIds = [];
|
|
@@ -59,12 +59,16 @@ export default class SnippetListSelect extends Component<Signature> {
|
|
|
59
59
|
);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
get allowMultipleSnippets(): boolean {
|
|
63
|
+
return this.args.node.value.attrs.allowMultipleSnippets as boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
62
66
|
get imported(): ImportedResourceMap {
|
|
63
67
|
return this.args.node.value.attrs['importedResources'];
|
|
64
68
|
}
|
|
65
69
|
|
|
66
70
|
@action
|
|
67
|
-
onSaveSnippetLists(lists: SnippetList[]) {
|
|
71
|
+
onSaveSnippetLists(lists: SnippetList[], allowMultipleSnippets: boolean) {
|
|
68
72
|
if (this.currentResource) {
|
|
69
73
|
this.args.controller?.doCommand(
|
|
70
74
|
updateSnippetPlaceholder({
|
|
@@ -73,6 +77,7 @@ export default class SnippetListSelect extends Component<Signature> {
|
|
|
73
77
|
newSnippetLists: lists,
|
|
74
78
|
oldImportedResources: this.imported,
|
|
75
79
|
node: this.args.node,
|
|
80
|
+
allowMultipleSnippets,
|
|
76
81
|
}),
|
|
77
82
|
{
|
|
78
83
|
view: this.args.controller.mainEditorView,
|
|
@@ -96,6 +101,7 @@ export default class SnippetListSelect extends Component<Signature> {
|
|
|
96
101
|
@config={{@config}}
|
|
97
102
|
@assignedSnippetListsIds={{this.assignedSnippetListsIds}}
|
|
98
103
|
@onSaveSnippetLists={{this.onSaveSnippetLists}}
|
|
104
|
+
@allowMultipleSnippets={{this.allowMultipleSnippets}}
|
|
99
105
|
@open={{this.showModal}}
|
|
100
106
|
@closeModal={{this.closeModal}}
|
|
101
107
|
/>
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { action } from '@ember/object';
|
|
3
|
+
import { service } from '@ember/service';
|
|
4
|
+
import { NodeSelection, type SayController } from '@lblod/ember-rdfa-editor';
|
|
5
|
+
import IntlService from 'ember-intl/services/intl';
|
|
6
|
+
import AuFormRow from '@appuniversum/ember-appuniversum/components/au-form-row';
|
|
7
|
+
import AuLabel from '@appuniversum/ember-appuniversum/components/au-label';
|
|
8
|
+
import AuButton from '@appuniversum/ember-appuniversum/components/au-button';
|
|
9
|
+
import AuCheckbox from '@appuniversum/ember-appuniversum/components/au-checkbox';
|
|
10
|
+
import AuNativeInput from '@lblod/ember-rdfa-editor-lblod-plugins/components/au-native-input';
|
|
11
|
+
import AuCard from '@appuniversum/ember-appuniversum/components/au-card';
|
|
12
|
+
import AuHeading from '@appuniversum/ember-appuniversum/components/au-heading';
|
|
13
|
+
import t from 'ember-intl/helpers/t';
|
|
14
|
+
import { on } from '@ember/modifier';
|
|
15
|
+
import { trackedReset } from 'tracked-toolbox';
|
|
16
|
+
import { EXT } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
|
|
17
|
+
import { sayDataFactory } from '@lblod/ember-rdfa-editor/core/say-data-factory/data-factory';
|
|
18
|
+
import { getOutgoingTriple } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/namespace';
|
|
19
|
+
import LabelInput from '../utils/label-input';
|
|
20
|
+
import {
|
|
21
|
+
ContentLiteralTerm,
|
|
22
|
+
SayLiteral,
|
|
23
|
+
SayNamedNode,
|
|
24
|
+
} from '@lblod/ember-rdfa-editor/core/say-data-factory';
|
|
25
|
+
type Args = {
|
|
26
|
+
controller: SayController;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type nodeProperty =
|
|
30
|
+
| {
|
|
31
|
+
predicate: string;
|
|
32
|
+
object: SayNamedNode<string>;
|
|
33
|
+
}
|
|
34
|
+
| {
|
|
35
|
+
predicate: string;
|
|
36
|
+
object: SayLiteral;
|
|
37
|
+
}
|
|
38
|
+
| {
|
|
39
|
+
predicate: string;
|
|
40
|
+
object: ContentLiteralTerm;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export default class AutoFilledVariableInsertComponent extends Component<Args> {
|
|
44
|
+
@service declare intl: IntlService;
|
|
45
|
+
|
|
46
|
+
// memo is the path to the trigger, which calls update
|
|
47
|
+
// see https://github.com/tracked-tools/tracked-toolbox?tab=readme-ov-file#trackedreset
|
|
48
|
+
// it's sort of badly explained in the docs, but it's a more generic version
|
|
49
|
+
// of localCopy, which we can't use here cause our derived state from the args
|
|
50
|
+
// is too complex to express as a string path
|
|
51
|
+
@trackedReset({
|
|
52
|
+
memo: 'args.controller.mainEditorState',
|
|
53
|
+
// using this as the first arg is special typescript syntax
|
|
54
|
+
// which allows you to explicitly type the this context, cause
|
|
55
|
+
// ts is not smart enough to know that
|
|
56
|
+
update(this: AutoFilledVariableInsertComponent) {
|
|
57
|
+
return this.convertToStringAttr;
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
convertToString: boolean = false;
|
|
61
|
+
|
|
62
|
+
@trackedReset({
|
|
63
|
+
memo: 'args.controller.mainEditorState',
|
|
64
|
+
update(this: AutoFilledVariableInsertComponent) {
|
|
65
|
+
return this.autofillKeyAttr;
|
|
66
|
+
},
|
|
67
|
+
})
|
|
68
|
+
autofillKey?: string;
|
|
69
|
+
|
|
70
|
+
@trackedReset({
|
|
71
|
+
memo: 'args.controller.mainEditorState',
|
|
72
|
+
update(this: AutoFilledVariableInsertComponent) {
|
|
73
|
+
return this.labelAttr;
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
label!: string;
|
|
77
|
+
|
|
78
|
+
get selectedVariable() {
|
|
79
|
+
const { selection } = this.controller.mainEditorState;
|
|
80
|
+
if (
|
|
81
|
+
selection instanceof NodeSelection &&
|
|
82
|
+
selection.node.type === this.controller.schema.nodes.autofilled_variable
|
|
83
|
+
) {
|
|
84
|
+
return {
|
|
85
|
+
node: selection.node,
|
|
86
|
+
pos: selection.from,
|
|
87
|
+
};
|
|
88
|
+
} else {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
get autofillKeyAttr() {
|
|
93
|
+
return this.selectedVariable?.node.attrs.autofillKey;
|
|
94
|
+
}
|
|
95
|
+
get convertToStringAttr() {
|
|
96
|
+
return this.selectedVariable?.node.attrs.convertToString;
|
|
97
|
+
}
|
|
98
|
+
get labelAttr() {
|
|
99
|
+
if (!this.selectedVariable) return '';
|
|
100
|
+
return getOutgoingTriple(this.selectedVariable.node.attrs, EXT('label'))
|
|
101
|
+
?.object.value;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
get showCard() {
|
|
105
|
+
return !!this.selectedVariable;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
get controller() {
|
|
109
|
+
return this.args.controller;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
get schema() {
|
|
113
|
+
return this.args.controller.schema;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
get documentLanguage() {
|
|
117
|
+
return this.controller.documentLanguage;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@action
|
|
121
|
+
updateLabel(event: InputEvent) {
|
|
122
|
+
this.label = (event.target as HTMLInputElement).value;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@action
|
|
126
|
+
updateAutofillKey(event: InputEvent) {
|
|
127
|
+
this.autofillKey = (event.target as HTMLInputElement).value;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
@action
|
|
131
|
+
updateConvertToString(value: boolean) {
|
|
132
|
+
this.convertToString = value;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
@action
|
|
136
|
+
edit() {
|
|
137
|
+
if (this.selectedVariable) {
|
|
138
|
+
this.controller.withTransaction(
|
|
139
|
+
(tr) => {
|
|
140
|
+
const position = this.selectedVariable?.pos as number;
|
|
141
|
+
tr.setNodeAttribute(position, 'autofillKey', this.autofillKey);
|
|
142
|
+
tr.setNodeAttribute(
|
|
143
|
+
position,
|
|
144
|
+
'convertToString',
|
|
145
|
+
this.convertToString,
|
|
146
|
+
);
|
|
147
|
+
const oldProperties = this.selectedVariable?.node.attrs.properties;
|
|
148
|
+
const newProperties = oldProperties.filter(
|
|
149
|
+
(property: nodeProperty) =>
|
|
150
|
+
property.predicate !== EXT('label').full,
|
|
151
|
+
);
|
|
152
|
+
newProperties.push({
|
|
153
|
+
predicate: EXT('label').full,
|
|
154
|
+
object: sayDataFactory.literal(this.label || ''),
|
|
155
|
+
});
|
|
156
|
+
tr.setNodeAttribute(position, 'properties', newProperties);
|
|
157
|
+
return tr;
|
|
158
|
+
},
|
|
159
|
+
// because the variable pill contains a nested editor, when it's
|
|
160
|
+
// selected, the currentEditorView is the nested one. When you run
|
|
161
|
+
// withTransaction without the optional second argument, it defaults to using
|
|
162
|
+
// the current view.
|
|
163
|
+
//
|
|
164
|
+
// Here, we don't want that, cause we want to edit the outside node, not
|
|
165
|
+
// any node in the nested editor.
|
|
166
|
+
{ view: this.controller.mainEditorView },
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
<template>
|
|
171
|
+
{{#if this.showCard}}
|
|
172
|
+
<AuCard
|
|
173
|
+
@flex={{true}}
|
|
174
|
+
@divided={{true}}
|
|
175
|
+
@isOpenInitially={{true}}
|
|
176
|
+
@expandable={{true}}
|
|
177
|
+
@shadow={{true}}
|
|
178
|
+
@size='small'
|
|
179
|
+
as |c|
|
|
180
|
+
>
|
|
181
|
+
<c.header>
|
|
182
|
+
<AuHeading @level='3' @skin='6'>
|
|
183
|
+
{{t 'variable-plugin.enter-variable-value'}}
|
|
184
|
+
</AuHeading>
|
|
185
|
+
</c.header>
|
|
186
|
+
<c.content>
|
|
187
|
+
<AuFormRow>
|
|
188
|
+
<LabelInput
|
|
189
|
+
@label={{this.label}}
|
|
190
|
+
@updateLabel={{this.updateLabel}}
|
|
191
|
+
/>
|
|
192
|
+
</AuFormRow>
|
|
193
|
+
<AuFormRow>
|
|
194
|
+
<AuLabel for='autofill_key'>
|
|
195
|
+
{{t 'variable-plugin.autofill.autofillKey'}}
|
|
196
|
+
</AuLabel>
|
|
197
|
+
<AuNativeInput
|
|
198
|
+
id='autofill_key'
|
|
199
|
+
placeholder={{t
|
|
200
|
+
'variable-plugin.autofill.autofillKeyPlaceholder'
|
|
201
|
+
}}
|
|
202
|
+
@type='text'
|
|
203
|
+
@width='block'
|
|
204
|
+
value={{this.autofillKey}}
|
|
205
|
+
{{on 'input' this.updateAutofillKey}}
|
|
206
|
+
/>
|
|
207
|
+
</AuFormRow>
|
|
208
|
+
<AuFormRow>
|
|
209
|
+
<AuCheckbox
|
|
210
|
+
id='convert_to_string'
|
|
211
|
+
@checked={{this.convertToString}}
|
|
212
|
+
@onChange={{this.updateConvertToString}}
|
|
213
|
+
>
|
|
214
|
+
{{t 'variable-plugin.autofill.convertToString'}}
|
|
215
|
+
</AuCheckbox>
|
|
216
|
+
</AuFormRow>
|
|
217
|
+
<AuButton {{on 'click' this.edit}}>
|
|
218
|
+
{{t 'variable-plugin.button'}}
|
|
219
|
+
</AuButton>
|
|
220
|
+
</c.content>
|
|
221
|
+
</AuCard>
|
|
222
|
+
{{/if}}
|
|
223
|
+
</template>
|
|
224
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { tracked } from '@glimmer/tracking';
|
|
3
|
+
import { action } from '@ember/object';
|
|
4
|
+
import { service } from '@ember/service';
|
|
5
|
+
import { type SayController } from '@lblod/ember-rdfa-editor';
|
|
6
|
+
import { sayDataFactory } from '@lblod/ember-rdfa-editor/core/say-data-factory';
|
|
7
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
8
|
+
import IntlService from 'ember-intl/services/intl';
|
|
9
|
+
import {
|
|
10
|
+
DCT,
|
|
11
|
+
EXT,
|
|
12
|
+
RDF,
|
|
13
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
|
|
14
|
+
import { replaceSelectionWithAndSelectNode } from '@lblod/ember-rdfa-editor-lblod-plugins/commands';
|
|
15
|
+
import AuFormRow from '@appuniversum/ember-appuniversum/components/au-form-row';
|
|
16
|
+
import AuLabel from '@appuniversum/ember-appuniversum/components/au-label';
|
|
17
|
+
import AuButton from '@appuniversum/ember-appuniversum/components/au-button';
|
|
18
|
+
import AuCheckbox from '@appuniversum/ember-appuniversum/components/au-checkbox';
|
|
19
|
+
import AuNativeInput from '@lblod/ember-rdfa-editor-lblod-plugins/components/au-native-input';
|
|
20
|
+
import t from 'ember-intl/helpers/t';
|
|
21
|
+
import { on } from '@ember/modifier';
|
|
22
|
+
import LabelInput from '@lblod/ember-rdfa-editor-lblod-plugins/components/variable-plugin/utils/label-input';
|
|
23
|
+
|
|
24
|
+
type Args = {
|
|
25
|
+
controller: SayController;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default class AutoFilledVariableInsertComponent extends Component<Args> {
|
|
29
|
+
@service declare intl: IntlService;
|
|
30
|
+
@tracked label: string = '';
|
|
31
|
+
@tracked autofillKey?: string;
|
|
32
|
+
@tracked convertToString?: boolean;
|
|
33
|
+
|
|
34
|
+
get controller() {
|
|
35
|
+
return this.args.controller;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get schema() {
|
|
39
|
+
return this.args.controller.schema;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get documentLanguage() {
|
|
43
|
+
return this.controller.documentLanguage;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@action
|
|
47
|
+
updateLabel(event: InputEvent) {
|
|
48
|
+
this.label = (event.target as HTMLInputElement).value;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@action
|
|
52
|
+
updateAutofillKey(event: InputEvent) {
|
|
53
|
+
this.autofillKey = (event.target as HTMLInputElement).value;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@action
|
|
57
|
+
updateConvertToString(value: boolean) {
|
|
58
|
+
this.convertToString = value;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@action
|
|
62
|
+
insert() {
|
|
63
|
+
const mappingSubject = `http://data.lblod.info/mappings/${uuidv4()}`;
|
|
64
|
+
const variableInstance = `http://data.lblod.info/variables/${uuidv4()}`;
|
|
65
|
+
const variableId = uuidv4();
|
|
66
|
+
|
|
67
|
+
const placeholder = this.intl.t('variable.autofilled.label', {
|
|
68
|
+
locale: this.documentLanguage,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const label = this.label != '' ? this.label : placeholder;
|
|
72
|
+
const node = this.schema.nodes.autofilled_variable.create(
|
|
73
|
+
{
|
|
74
|
+
subject: mappingSubject,
|
|
75
|
+
rdfaNodeType: 'resource',
|
|
76
|
+
__rdfaId: variableId,
|
|
77
|
+
properties: [
|
|
78
|
+
{
|
|
79
|
+
predicate: RDF('type').full,
|
|
80
|
+
object: sayDataFactory.namedNode(EXT('Mapping').full),
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
predicate: EXT('instance').full,
|
|
84
|
+
object: sayDataFactory.namedNode(variableInstance),
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
predicate: EXT('label').full,
|
|
88
|
+
object: sayDataFactory.literal(label),
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
predicate: DCT('type').full,
|
|
92
|
+
object: sayDataFactory.literal('autofilled'),
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
predicate: EXT('content').full,
|
|
96
|
+
object: sayDataFactory.contentLiteral(),
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
autofillKey: this.autofillKey,
|
|
100
|
+
convertToString: this.convertToString,
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
this.schema.node('placeholder', {
|
|
104
|
+
placeholderText: `Autofill ${this.autofillKey}`,
|
|
105
|
+
}),
|
|
106
|
+
);
|
|
107
|
+
this.label = '';
|
|
108
|
+
|
|
109
|
+
this.controller.doCommand(replaceSelectionWithAndSelectNode(node), {
|
|
110
|
+
view: this.controller.mainEditorView,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
<template>
|
|
114
|
+
<AuFormRow>
|
|
115
|
+
<LabelInput @label={{this.label}} @updateLabel={{this.updateLabel}} />
|
|
116
|
+
</AuFormRow>
|
|
117
|
+
<AuFormRow>
|
|
118
|
+
<AuLabel for='autofill_key'>
|
|
119
|
+
{{t 'variable-plugin.autofill.autofillKey'}}
|
|
120
|
+
</AuLabel>
|
|
121
|
+
<AuNativeInput
|
|
122
|
+
id='autofill_key'
|
|
123
|
+
placeholder={{t 'variable-plugin.autofill.autofillKeyPlaceholder'}}
|
|
124
|
+
@type='text'
|
|
125
|
+
@width='block'
|
|
126
|
+
value={{this.autofillKey}}
|
|
127
|
+
{{on 'input' this.updateAutofillKey}}
|
|
128
|
+
/>
|
|
129
|
+
</AuFormRow>
|
|
130
|
+
<AuFormRow>
|
|
131
|
+
<AuCheckbox
|
|
132
|
+
id='convert_to_string'
|
|
133
|
+
@checked={{this.convertToString}}
|
|
134
|
+
@onChange={{this.updateConvertToString}}
|
|
135
|
+
>
|
|
136
|
+
{{t 'variable-plugin.autofill.convertToString'}}
|
|
137
|
+
</AuCheckbox>
|
|
138
|
+
</AuFormRow>
|
|
139
|
+
<AuButton {{on 'click' this.insert}}>
|
|
140
|
+
{{t 'variable-plugin.button'}}
|
|
141
|
+
</AuButton>
|
|
142
|
+
</template>
|
|
143
|
+
}
|