@lblod/ember-rdfa-editor-lblod-plugins 24.3.0 → 24.3.1-dev.2e3c09f95db40967caaceaa791e7eefd6187c5e4
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/.changeset/four-eagles-live.md +5 -0
- package/.changeset/gentle-berries-exist.md +5 -0
- package/.changeset/hungry-trees-perform.md +5 -0
- package/CHANGELOG.md +6 -0
- package/addon/components/snippet-plugin/nodes/placeholder.gts +42 -23
- package/addon/components/snippet-plugin/nodes/snippet.gts +104 -47
- package/addon/components/snippet-plugin/search-modal.ts +3 -4
- package/addon/components/snippet-plugin/snippet-insert-placeholder.gts +4 -4
- package/addon/components/snippet-plugin/snippet-insert-rdfa.gts +14 -22
- package/addon/components/snippet-plugin/snippet-insert.gts +16 -19
- package/addon/components/snippet-plugin/snippet-list/snippet-list-modal.hbs +1 -1
- package/addon/components/snippet-plugin/snippet-list/snippet-list-modal.ts +7 -9
- package/addon/components/snippet-plugin/snippet-list/snippet-list-view.hbs +1 -1
- package/addon/components/snippet-plugin/snippet-list/snippet-list-view.ts +5 -9
- package/addon/components/snippet-plugin/snippet-list-select.gts +2 -2
- package/addon/plugins/snippet-plugin/commands/insert-snippet.ts +5 -8
- package/addon/plugins/snippet-plugin/commands/update-snippet-placeholder.ts +2 -2
- package/addon/plugins/snippet-plugin/index.ts +9 -7
- package/addon/plugins/snippet-plugin/nodes/snippet-placeholder.ts +71 -23
- package/addon/plugins/snippet-plugin/nodes/snippet.ts +50 -20
- package/addon/plugins/snippet-plugin/utils/fetch-data.ts +8 -8
- package/addon/plugins/snippet-plugin/utils/rdfa-predicate.ts +20 -3
- package/addon/utils/has-descendant.ts +19 -0
- package/app/styles/snippet-plugin.scss +59 -23
- package/declarations/addon/components/snippet-plugin/nodes/placeholder.d.ts +7 -2
- package/declarations/addon/components/snippet-plugin/nodes/snippet.d.ts +4 -1
- package/declarations/addon/components/snippet-plugin/search-modal.d.ts +1 -1
- package/declarations/addon/components/snippet-plugin/snippet-insert-rdfa.d.ts +2 -6
- package/declarations/addon/components/snippet-plugin/snippet-insert.d.ts +3 -7
- package/declarations/addon/components/snippet-plugin/snippet-list/snippet-list-modal.d.ts +3 -3
- package/declarations/addon/components/snippet-plugin/snippet-list/snippet-list-view.d.ts +2 -2
- package/declarations/addon/components/snippet-plugin/snippet-list-select.d.ts +1 -1
- package/declarations/addon/plugins/snippet-plugin/commands/insert-snippet.d.ts +3 -4
- package/declarations/addon/plugins/snippet-plugin/index.d.ts +7 -2
- package/declarations/addon/plugins/snippet-plugin/nodes/snippet-placeholder.d.ts +13 -4
- package/declarations/addon/plugins/snippet-plugin/nodes/snippet.d.ts +4 -5
- package/declarations/addon/plugins/snippet-plugin/utils/fetch-data.d.ts +1 -1
- package/declarations/addon/plugins/snippet-plugin/utils/rdfa-predicate.d.ts +9 -2
- package/declarations/addon/utils/has-descendant.d.ts +2 -0
- package/package.json +1 -1
- package/translations/en-US.yaml +1 -1
- package/translations/nl-BE.yaml +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @lblod/ember-rdfa-editor-lblod-plugins
|
|
2
2
|
|
|
3
|
+
## 24.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#494](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/494) [`3941b65`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/3941b659fbb710be0aafd34b911a42416a1124c9) Thanks [@elpoelma](https://github.com/elpoelma)! - Ensure that the event handlers of snippet actions are only triggered once
|
|
8
|
+
|
|
3
9
|
## 24.3.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
@@ -1,20 +1,31 @@
|
|
|
1
1
|
import Component from '@glimmer/component';
|
|
2
|
+
import { service } from '@ember/service';
|
|
2
3
|
import { on } from '@ember/modifier';
|
|
4
|
+
import IntlService from 'ember-intl/services/intl';
|
|
3
5
|
import t from 'ember-intl/helpers/t';
|
|
4
|
-
import AuAlert from '@appuniversum/ember-appuniversum/components/au-alert';
|
|
5
6
|
import { PlusTextIcon } from '@appuniversum/ember-appuniversum/components/icons/plus-text';
|
|
7
|
+
import AuIcon from '@appuniversum/ember-appuniversum/components/au-icon';
|
|
8
|
+
import AuButton from '@appuniversum/ember-appuniversum/components/au-button';
|
|
6
9
|
import { type EmberNodeArgs } from '@lblod/ember-rdfa-editor/utils/_private/ember-node';
|
|
7
|
-
import {
|
|
8
|
-
import IntlService from 'ember-intl/services/intl';
|
|
10
|
+
import { type SnippetPluginConfig } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
9
11
|
|
|
10
12
|
interface Signature {
|
|
11
|
-
Args: EmberNodeArgs
|
|
13
|
+
Args: Pick<EmberNodeArgs, 'node' | 'selectNode'> & {
|
|
14
|
+
insertSnippet: () => void;
|
|
15
|
+
};
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
export default class SnippetPluginPlaceholder extends Component<Signature> {
|
|
15
19
|
@service declare intl: IntlService;
|
|
20
|
+
|
|
21
|
+
get node() {
|
|
22
|
+
return this.args.node;
|
|
23
|
+
}
|
|
16
24
|
get listNames() {
|
|
17
|
-
return this.args.node.attrs.
|
|
25
|
+
return this.args.node.attrs.snippetListNames;
|
|
26
|
+
}
|
|
27
|
+
get config(): SnippetPluginConfig {
|
|
28
|
+
return this.node.attrs.config;
|
|
18
29
|
}
|
|
19
30
|
get isSingleList() {
|
|
20
31
|
return this.listNames.length === 1;
|
|
@@ -28,24 +39,32 @@ export default class SnippetPluginPlaceholder extends Component<Signature> {
|
|
|
28
39
|
return this.intl.t('snippet-plugin.placeholder.title-multiple');
|
|
29
40
|
}
|
|
30
41
|
}
|
|
42
|
+
|
|
31
43
|
<template>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
class='say-snippet-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
{{! template-lint-disable no-invalid-interactive }}
|
|
45
|
+
<div class='say-snippet-placeholder' {{on 'click' @selectNode}}>
|
|
46
|
+
<div class='say-snippet-placeholder__icon'>
|
|
47
|
+
<AuIcon @icon={{PlusTextIcon}} />
|
|
48
|
+
</div>
|
|
49
|
+
<div class='say-snippet-placeholder__content'>
|
|
50
|
+
<p class='say-snippet-placeholder__title'>{{this.alertTitle}}</p>
|
|
51
|
+
{{#unless this.isSingleList}}
|
|
52
|
+
<ul class='say-snippet-placeholder__list'>
|
|
53
|
+
{{#each this.listNames as |listName|}}
|
|
54
|
+
<li>{{listName}}</li>
|
|
55
|
+
{{/each}}
|
|
56
|
+
</ul>
|
|
57
|
+
{{/unless}}
|
|
58
|
+
{{#unless this.config.hidePlaceholderInsertButton}}
|
|
59
|
+
<AuButton
|
|
60
|
+
@skin='link'
|
|
61
|
+
class='say-snippet-placeholder__button'
|
|
62
|
+
{{on 'click' @insertSnippet}}
|
|
63
|
+
>
|
|
64
|
+
{{t 'snippet-plugin.placeholder.button'}}
|
|
65
|
+
</AuButton>
|
|
66
|
+
{{/unless}}
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
50
69
|
</template>
|
|
51
70
|
}
|
|
@@ -13,6 +13,7 @@ import { BinIcon } from '@appuniversum/ember-appuniversum/components/icons/bin';
|
|
|
13
13
|
import { AddIcon } from '@appuniversum/ember-appuniversum/components/icons/add';
|
|
14
14
|
import { type EmberNodeArgs } from '@lblod/ember-rdfa-editor/utils/_private/ember-node';
|
|
15
15
|
import {
|
|
16
|
+
NodeSelection,
|
|
16
17
|
type PNode,
|
|
17
18
|
ProseParser,
|
|
18
19
|
type Selection,
|
|
@@ -28,11 +29,14 @@ import insertSnippet from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippe
|
|
|
28
29
|
import { isNone } from '@lblod/ember-rdfa-editor/utils/_private/option';
|
|
29
30
|
import { transactionCombinator } from '@lblod/ember-rdfa-editor/utils/transaction-utils';
|
|
30
31
|
import { recalculateNumbers } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/structure-plugin/recalculate-structure-numbers';
|
|
32
|
+
import { createSnippetPlaceholder } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin/nodes/snippet-placeholder';
|
|
33
|
+
import { hasDecendant } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/has-descendant';
|
|
34
|
+
import SnippetPlaceholder from '@lblod/ember-rdfa-editor-lblod-plugins/components/snippet-plugin/nodes/placeholder';
|
|
35
|
+
import { getSnippetListIdsFromNode } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin/utils/rdfa-predicate';
|
|
31
36
|
|
|
32
37
|
interface ButtonSig {
|
|
33
38
|
Args: {
|
|
34
39
|
isActive: boolean;
|
|
35
|
-
onClick: () => void;
|
|
36
40
|
icon: AuIconSignature['Args']['icon'];
|
|
37
41
|
helpText: string;
|
|
38
42
|
};
|
|
@@ -41,13 +45,8 @@ interface ButtonSig {
|
|
|
41
45
|
|
|
42
46
|
const SnippetButton: TemplateOnlyComponent<ButtonSig> = <template>
|
|
43
47
|
{{#if @isActive}}
|
|
44
|
-
<button
|
|
45
|
-
|
|
46
|
-
type='button'
|
|
47
|
-
{{on 'click' @onClick}}
|
|
48
|
-
...attributes
|
|
49
|
-
>
|
|
50
|
-
<AuIcon @icon={{@icon}} @size='large' {{on 'click' @onClick}} />
|
|
48
|
+
<button class='say-snippet-button' type='button' ...attributes>
|
|
49
|
+
<AuIcon @icon={{@icon}} @size='large' />
|
|
51
50
|
<div class='say-snippet-button-text'>
|
|
52
51
|
{{t @helpText}}
|
|
53
52
|
</div>
|
|
@@ -68,9 +67,25 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
68
67
|
get controller() {
|
|
69
68
|
return this.args.controller;
|
|
70
69
|
}
|
|
70
|
+
get schema() {
|
|
71
|
+
return this.controller.schema;
|
|
72
|
+
}
|
|
73
|
+
get snippetOrPlaceholder() {
|
|
74
|
+
return [
|
|
75
|
+
this.schema.nodes.snippet,
|
|
76
|
+
this.schema.nodes.snippet_placeholder,
|
|
77
|
+
].filter(Boolean);
|
|
78
|
+
}
|
|
71
79
|
get node() {
|
|
72
80
|
return this.args.node;
|
|
73
81
|
}
|
|
82
|
+
get isPlaceholder() {
|
|
83
|
+
return this.node.content.size === 0;
|
|
84
|
+
}
|
|
85
|
+
get allowMultipleSnippets() {
|
|
86
|
+
return this.node.attrs.allowMultipleSnippets as boolean;
|
|
87
|
+
}
|
|
88
|
+
|
|
74
89
|
@action
|
|
75
90
|
closeModal() {
|
|
76
91
|
this.showModal = false;
|
|
@@ -80,10 +95,6 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
80
95
|
this.showModal = true;
|
|
81
96
|
}
|
|
82
97
|
|
|
83
|
-
get allowMultipleSnippets() {
|
|
84
|
-
return this.node.attrs.allowMultipleSnippets as boolean;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
98
|
@action
|
|
88
99
|
addFragment() {
|
|
89
100
|
if (this.allowMultipleSnippets) {
|
|
@@ -100,17 +111,46 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
100
111
|
deleteFragment() {
|
|
101
112
|
const position = this.args.getPos();
|
|
102
113
|
if (position !== undefined) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
114
|
+
const matchingSnippetExists = hasDecendant(
|
|
115
|
+
this.controller.mainEditorState.doc,
|
|
116
|
+
(node) =>
|
|
117
|
+
node !== this.node &&
|
|
118
|
+
this.snippetOrPlaceholder.includes(node.type) &&
|
|
119
|
+
node.attrs.placeholderId === this.node.attrs.placeholderId,
|
|
120
|
+
);
|
|
121
|
+
if (matchingSnippetExists) {
|
|
122
|
+
this.controller.withTransaction((tr) => {
|
|
123
|
+
return transactionCombinator(
|
|
124
|
+
this.controller.mainEditorState,
|
|
125
|
+
tr.deleteRange(position, position + this.node.nodeSize),
|
|
126
|
+
)([recalculateNumbers]).transaction;
|
|
127
|
+
});
|
|
128
|
+
} else {
|
|
129
|
+
const node = createSnippetPlaceholder({
|
|
130
|
+
listProperties: {
|
|
131
|
+
placeholderId: this.node.attrs.placeholderId,
|
|
132
|
+
listIds: getSnippetListIdsFromNode(this.node),
|
|
133
|
+
names: this.node.attrs.snippetListNames,
|
|
134
|
+
importedResources: this.node.attrs.importedResources,
|
|
135
|
+
},
|
|
136
|
+
schema: this.schema,
|
|
137
|
+
allowMultipleSnippets: this.allowMultipleSnippets,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
this.args.controller.withTransaction(
|
|
141
|
+
(tr) =>
|
|
142
|
+
transactionCombinator(
|
|
143
|
+
this.controller.mainEditorState,
|
|
144
|
+
tr.replaceWith(position, position + this.node.nodeSize, node),
|
|
145
|
+
)([recalculateNumbers]).transaction,
|
|
146
|
+
{ view: this.args.controller.mainEditorView },
|
|
147
|
+
);
|
|
148
|
+
}
|
|
109
149
|
}
|
|
110
150
|
}
|
|
111
151
|
createSliceFromElement(element: Element) {
|
|
112
152
|
return new Slice(
|
|
113
|
-
ProseParser.fromSchema(this.
|
|
153
|
+
ProseParser.fromSchema(this.schema).parse(element, {
|
|
114
154
|
preserveWhitespace: true,
|
|
115
155
|
}).content,
|
|
116
156
|
0,
|
|
@@ -121,6 +161,12 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
121
161
|
return this.controller.mainEditorState.selection;
|
|
122
162
|
}
|
|
123
163
|
get isActive(): boolean {
|
|
164
|
+
if (
|
|
165
|
+
this.selection instanceof NodeSelection &&
|
|
166
|
+
this.selection.node === this.node
|
|
167
|
+
) {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
124
170
|
const ancestor = findAncestors(this.selection.$from, (node: PNode) => {
|
|
125
171
|
return hasOutgoingNamedNodeTriple(
|
|
126
172
|
node.attrs,
|
|
@@ -133,7 +179,6 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
133
179
|
@action
|
|
134
180
|
onInsert(content: string, title: string) {
|
|
135
181
|
this.closeModal();
|
|
136
|
-
const assignedSnippetListsIds = this.node.attrs.assignedSnippetListsIds;
|
|
137
182
|
let start = 0;
|
|
138
183
|
let end = 0;
|
|
139
184
|
const pos = this.args.getPos();
|
|
@@ -153,8 +198,12 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
153
198
|
insertSnippet({
|
|
154
199
|
content,
|
|
155
200
|
title,
|
|
156
|
-
|
|
157
|
-
|
|
201
|
+
listProperties: {
|
|
202
|
+
placeholderId: this.node.attrs.placeholderId,
|
|
203
|
+
listIds: getSnippetListIdsFromNode(this.node),
|
|
204
|
+
names: this.node.attrs.snippetListNames,
|
|
205
|
+
importedResources: this.node.attrs.importedResources,
|
|
206
|
+
},
|
|
158
207
|
range: { start, end },
|
|
159
208
|
allowMultipleSnippets: this.allowMultipleSnippets,
|
|
160
209
|
}),
|
|
@@ -162,40 +211,48 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
162
211
|
}
|
|
163
212
|
|
|
164
213
|
<template>
|
|
165
|
-
|
|
166
|
-
<
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
<
|
|
176
|
-
@icon={{BinIcon}}
|
|
177
|
-
@helpText='snippet-plugin.snippet-node.remove-fragment'
|
|
178
|
-
@onClick={{this.deleteFragment}}
|
|
179
|
-
@isActive={{this.isActive}}
|
|
180
|
-
class='say-snippet-remove-button'
|
|
181
|
-
/>
|
|
182
|
-
{{#if this.allowMultipleSnippets}}
|
|
214
|
+
{{#if this.isPlaceholder}}
|
|
215
|
+
<SnippetPlaceholder
|
|
216
|
+
@node={{@node}}
|
|
217
|
+
@selectNode={{@selectNode}}
|
|
218
|
+
@insertSnippet={{this.editFragment}}
|
|
219
|
+
/>
|
|
220
|
+
{{else}}
|
|
221
|
+
<div class='say-snippet-card'>
|
|
222
|
+
<div class='say-snippet-title'>{{this.node.attrs.title}}</div>
|
|
223
|
+
<div class='say-snippet-content'>{{yield}}</div>
|
|
224
|
+
<div class='say-snippet-icons' contenteditable='false'>
|
|
183
225
|
<SnippetButton
|
|
184
|
-
@icon={{
|
|
185
|
-
@helpText='snippet-plugin.snippet-node.
|
|
186
|
-
|
|
226
|
+
@icon={{SynchronizeIcon}}
|
|
227
|
+
@helpText='snippet-plugin.snippet-node.change-fragment'
|
|
228
|
+
{{on 'click' this.editFragment}}
|
|
187
229
|
@isActive={{this.isActive}}
|
|
188
230
|
/>
|
|
189
|
-
|
|
190
|
-
|
|
231
|
+
<SnippetButton
|
|
232
|
+
@icon={{BinIcon}}
|
|
233
|
+
@helpText='snippet-plugin.snippet-node.remove-fragment'
|
|
234
|
+
{{on 'click' this.deleteFragment}}
|
|
235
|
+
@isActive={{this.isActive}}
|
|
236
|
+
class='say-snippet-remove-button'
|
|
237
|
+
/>
|
|
238
|
+
{{#if this.allowMultipleSnippets}}
|
|
239
|
+
<SnippetButton
|
|
240
|
+
@icon={{AddIcon}}
|
|
241
|
+
@helpText='snippet-plugin.snippet-node.add-fragment'
|
|
242
|
+
{{on 'click' this.addFragment}}
|
|
243
|
+
@isActive={{this.isActive}}
|
|
244
|
+
/>
|
|
245
|
+
{{/if}}
|
|
246
|
+
</div>
|
|
191
247
|
|
|
192
|
-
|
|
248
|
+
</div>
|
|
249
|
+
{{/if}}
|
|
193
250
|
<SearchModal
|
|
194
251
|
@open={{this.showModal}}
|
|
195
252
|
@closeModal={{this.closeModal}}
|
|
196
253
|
@config={{this.node.attrs.config}}
|
|
197
254
|
@onInsert={{this.onInsert}}
|
|
198
|
-
@
|
|
255
|
+
@snippetListIds={{getSnippetListIdsFromNode this.node}}
|
|
199
256
|
/>
|
|
200
257
|
</template>
|
|
201
258
|
}
|
|
@@ -11,7 +11,7 @@ import { SnippetPluginConfig } from '@lblod/ember-rdfa-editor-lblod-plugins/plug
|
|
|
11
11
|
|
|
12
12
|
interface Args {
|
|
13
13
|
config: SnippetPluginConfig;
|
|
14
|
-
|
|
14
|
+
snippetListIds: string[] | undefined;
|
|
15
15
|
closeModal: () => void;
|
|
16
16
|
open: boolean;
|
|
17
17
|
onInsert: (content: string, title: string) => void;
|
|
@@ -64,8 +64,7 @@ export default class SnippetPluginSearchModalComponent extends Component<Args> {
|
|
|
64
64
|
abortSignal: abortController.signal,
|
|
65
65
|
filter: {
|
|
66
66
|
name: this.inputSearchText ?? undefined,
|
|
67
|
-
|
|
68
|
-
this.args.assignedSnippetListsIds ?? undefined,
|
|
67
|
+
snippetListIds: this.args.snippetListIds ?? undefined,
|
|
69
68
|
},
|
|
70
69
|
pagination: {
|
|
71
70
|
pageNumber: this.pageNumber,
|
|
@@ -88,7 +87,7 @@ export default class SnippetPluginSearchModalComponent extends Component<Args> {
|
|
|
88
87
|
this.inputSearchText,
|
|
89
88
|
this.pageNumber,
|
|
90
89
|
this.pageSize,
|
|
91
|
-
this.args.
|
|
90
|
+
this.args.snippetListIds,
|
|
92
91
|
]);
|
|
93
92
|
|
|
94
93
|
@action
|
|
@@ -43,11 +43,11 @@ export default class SnippetPluginSnippetInsertPlaceholder extends Component<Sig
|
|
|
43
43
|
allowMultipleSnippets: boolean,
|
|
44
44
|
) {
|
|
45
45
|
if (lists) {
|
|
46
|
-
const node = createSnippetPlaceholder(
|
|
46
|
+
const node = createSnippetPlaceholder({
|
|
47
47
|
lists,
|
|
48
|
-
this.args.controller.schema,
|
|
48
|
+
schema: this.args.controller.schema,
|
|
49
49
|
allowMultipleSnippets,
|
|
50
|
-
);
|
|
50
|
+
});
|
|
51
51
|
|
|
52
52
|
this.args.controller.withTransaction(
|
|
53
53
|
(tr) => {
|
|
@@ -72,7 +72,7 @@ export default class SnippetPluginSnippetInsertPlaceholder extends Component<Sig
|
|
|
72
72
|
</li>
|
|
73
73
|
<SnippetListModal
|
|
74
74
|
@config={{@config}}
|
|
75
|
-
@
|
|
75
|
+
@snippetListIds={{empty}}
|
|
76
76
|
@allowMultipleSnippets={{false}}
|
|
77
77
|
@onSaveSnippetLists={{this.insertPlaceholder}}
|
|
78
78
|
@open={{this.isModalOpen}}
|
|
@@ -3,14 +3,11 @@ import Component from '@glimmer/component';
|
|
|
3
3
|
|
|
4
4
|
import { SayController } from '@lblod/ember-rdfa-editor';
|
|
5
5
|
import {
|
|
6
|
-
type
|
|
6
|
+
type SnippetListProperties,
|
|
7
7
|
type SnippetPluginConfig,
|
|
8
8
|
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
9
9
|
import { findParentNodeClosestToPos } from '@curvenote/prosemirror-utils';
|
|
10
|
-
import {
|
|
11
|
-
getAssignedSnippetListsIdsFromProperties,
|
|
12
|
-
getSnippetListIdsProperties,
|
|
13
|
-
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin/utils/rdfa-predicate';
|
|
10
|
+
import { getSnippetListIdsFromNode } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin/utils/rdfa-predicate';
|
|
14
11
|
import { ResolvedPNode } from '@lblod/ember-rdfa-editor/utils/_private/types';
|
|
15
12
|
import SnippetInsert from './snippet-insert';
|
|
16
13
|
|
|
@@ -23,21 +20,15 @@ interface Sig {
|
|
|
23
20
|
}
|
|
24
21
|
|
|
25
22
|
export default class SnippetInsertRdfaComponent extends Component<Sig> {
|
|
26
|
-
get
|
|
27
|
-
return (this.snippetListProperties?.listIds.length ?? 0) === 0;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get snippetListProperties():
|
|
31
|
-
| { listIds: string[]; importedResources: ImportedResourceMap }
|
|
32
|
-
| undefined {
|
|
23
|
+
get listProperties(): SnippetListProperties | undefined {
|
|
33
24
|
const activeNode = this.args.node.value;
|
|
34
|
-
const
|
|
25
|
+
const listIds = getSnippetListIdsFromNode(activeNode);
|
|
35
26
|
|
|
36
|
-
if (
|
|
27
|
+
if (listIds.length > 0) {
|
|
37
28
|
return {
|
|
38
|
-
listIds
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
listIds,
|
|
30
|
+
placeholderId: activeNode.attrs.placeholderId,
|
|
31
|
+
names: activeNode.attrs.snippetListNames,
|
|
41
32
|
importedResources: activeNode.attrs.importedResources,
|
|
42
33
|
};
|
|
43
34
|
}
|
|
@@ -53,11 +44,13 @@ export default class SnippetInsertRdfaComponent extends Component<Sig> {
|
|
|
53
44
|
isResourceNode(node),
|
|
54
45
|
);
|
|
55
46
|
while (parentNode) {
|
|
56
|
-
const
|
|
47
|
+
const listIds = getSnippetListIdsFromNode(parentNode.node);
|
|
57
48
|
|
|
58
|
-
if (
|
|
49
|
+
if (listIds.length > 0) {
|
|
59
50
|
return {
|
|
60
|
-
listIds
|
|
51
|
+
listIds,
|
|
52
|
+
placeholderId: parentNode.node.attrs.placeholderId,
|
|
53
|
+
names: parentNode.node.attrs.snippetListNames,
|
|
61
54
|
importedResources: parentNode.node.attrs.importedResources,
|
|
62
55
|
};
|
|
63
56
|
}
|
|
@@ -79,8 +72,7 @@ export default class SnippetInsertRdfaComponent extends Component<Sig> {
|
|
|
79
72
|
<SnippetInsert
|
|
80
73
|
@config={{@config}}
|
|
81
74
|
@controller={{@controller}}
|
|
82
|
-
@
|
|
83
|
-
@disabled={{this.disableInsert}}
|
|
75
|
+
@listProperties={{this.listProperties}}
|
|
84
76
|
@allowMultipleSnippets={{this.allowMultipleSnippets}}
|
|
85
77
|
/>
|
|
86
78
|
</template>
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
Slice,
|
|
12
12
|
} from '@lblod/ember-rdfa-editor';
|
|
13
13
|
import { SnippetPluginConfig } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
14
|
-
import { type
|
|
14
|
+
import { type SnippetListProperties } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
15
15
|
import insertSnippet from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin/commands/insert-snippet';
|
|
16
16
|
import SearchModal from './search-modal';
|
|
17
17
|
|
|
@@ -19,10 +19,7 @@ interface Sig {
|
|
|
19
19
|
Args: {
|
|
20
20
|
controller: SayController;
|
|
21
21
|
config: SnippetPluginConfig;
|
|
22
|
-
|
|
23
|
-
| { listIds: string[]; importedResources: ImportedResourceMap }
|
|
24
|
-
| undefined;
|
|
25
|
-
disabled?: boolean;
|
|
22
|
+
listProperties: SnippetListProperties | undefined;
|
|
26
23
|
allowMultipleSnippets?: boolean;
|
|
27
24
|
};
|
|
28
25
|
}
|
|
@@ -33,6 +30,9 @@ export default class SnippetInsertComponent extends Component<Sig> {
|
|
|
33
30
|
get controller() {
|
|
34
31
|
return this.args.controller;
|
|
35
32
|
}
|
|
33
|
+
get disabled() {
|
|
34
|
+
return (this.args.listProperties?.listIds.length ?? 0) === 0;
|
|
35
|
+
}
|
|
36
36
|
|
|
37
37
|
@action
|
|
38
38
|
openModal() {
|
|
@@ -58,19 +58,16 @@ export default class SnippetInsertComponent extends Component<Sig> {
|
|
|
58
58
|
@action
|
|
59
59
|
onInsert(content: string, title: string) {
|
|
60
60
|
this.closeModal();
|
|
61
|
-
this.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
get disabled() {
|
|
73
|
-
return this.args.disabled ?? false;
|
|
61
|
+
if (this.args.listProperties) {
|
|
62
|
+
this.controller.doCommand(
|
|
63
|
+
insertSnippet({
|
|
64
|
+
content,
|
|
65
|
+
title,
|
|
66
|
+
listProperties: this.args.listProperties,
|
|
67
|
+
allowMultipleSnippets: this.args.allowMultipleSnippets,
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
70
|
+
}
|
|
74
71
|
}
|
|
75
72
|
|
|
76
73
|
<template>
|
|
@@ -91,7 +88,7 @@ export default class SnippetInsertComponent extends Component<Sig> {
|
|
|
91
88
|
@closeModal={{this.closeModal}}
|
|
92
89
|
@config={{@config}}
|
|
93
90
|
@onInsert={{this.onInsert}}
|
|
94
|
-
@
|
|
91
|
+
@snippetListIds={{@listProperties.listIds}}
|
|
95
92
|
/>
|
|
96
93
|
</template>
|
|
97
94
|
}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
{{else}}
|
|
20
20
|
<SnippetPlugin::SnippetList::SnippetListView
|
|
21
21
|
@snippetLists={{this.snippetListResource.value}}
|
|
22
|
-
@
|
|
22
|
+
@snippetListIds={{this.snippetListIds}}
|
|
23
23
|
@listNameFilter={{this.nameFilterText}}
|
|
24
24
|
@sort={{this.sort}}
|
|
25
25
|
@onChange={{this.onChange}}
|
|
@@ -23,7 +23,7 @@ interface Signature {
|
|
|
23
23
|
lists: SnippetList[],
|
|
24
24
|
allowMultipleSnippets: boolean,
|
|
25
25
|
) => void;
|
|
26
|
-
|
|
26
|
+
snippetListIds: string[] | undefined;
|
|
27
27
|
closeModal: () => void;
|
|
28
28
|
open: boolean;
|
|
29
29
|
allowMultipleSnippets?: boolean;
|
|
@@ -40,10 +40,8 @@ export default class SnippetListModalComponent extends Component<Signature> {
|
|
|
40
40
|
// Display
|
|
41
41
|
@tracked error: unknown;
|
|
42
42
|
|
|
43
|
-
@trackedReset('args.
|
|
44
|
-
|
|
45
|
-
...(this.args.assignedSnippetListsIds ?? []),
|
|
46
|
-
];
|
|
43
|
+
@trackedReset('args.snippetListIds')
|
|
44
|
+
snippetListIds: string[] = [...(this.args.snippetListIds ?? [])];
|
|
47
45
|
|
|
48
46
|
@localCopy('args.allowMultipleSnippets') allowMultipleSnippets = false;
|
|
49
47
|
|
|
@@ -65,7 +63,7 @@ export default class SnippetListModalComponent extends Component<Signature> {
|
|
|
65
63
|
@action
|
|
66
64
|
saveAndClose() {
|
|
67
65
|
const snippetLists = this.snippetListResource.value?.filter((snippetList) =>
|
|
68
|
-
this.
|
|
66
|
+
this.snippetListIds.includes(snippetList.id),
|
|
69
67
|
);
|
|
70
68
|
this.args.onSaveSnippetLists(
|
|
71
69
|
snippetLists || [],
|
|
@@ -73,7 +71,7 @@ export default class SnippetListModalComponent extends Component<Signature> {
|
|
|
73
71
|
);
|
|
74
72
|
this.args.closeModal();
|
|
75
73
|
// Clear selection for next time
|
|
76
|
-
this.
|
|
74
|
+
this.snippetListIds = [];
|
|
77
75
|
}
|
|
78
76
|
|
|
79
77
|
snippetListSearch = restartableTask(async () => {
|
|
@@ -107,7 +105,7 @@ export default class SnippetListModalComponent extends Component<Signature> {
|
|
|
107
105
|
);
|
|
108
106
|
|
|
109
107
|
@action
|
|
110
|
-
onChange(
|
|
111
|
-
this.
|
|
108
|
+
onChange(snippetListIds: string[]) {
|
|
109
|
+
this.snippetListIds = snippetListIds;
|
|
112
110
|
}
|
|
113
111
|
}
|
|
@@ -4,25 +4,22 @@ import { SnippetList } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snip
|
|
|
4
4
|
|
|
5
5
|
interface Args {
|
|
6
6
|
snippetLists: SnippetList[];
|
|
7
|
-
|
|
7
|
+
snippetListIds: string[];
|
|
8
8
|
listNameFilter: string | null;
|
|
9
9
|
isLoading: boolean;
|
|
10
|
-
onChange: (
|
|
10
|
+
onChange: (snippetListIds: string[]) => void;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export default class SnippetListViewComponent extends Component<Args> {
|
|
14
14
|
@action
|
|
15
15
|
onChange(snippetId: string, isSelected: boolean) {
|
|
16
16
|
if (isSelected) {
|
|
17
|
-
const newSnippetListIds = [
|
|
18
|
-
...this.args.assignedSnippetListsIds,
|
|
19
|
-
snippetId,
|
|
20
|
-
];
|
|
17
|
+
const newSnippetListIds = [...this.args.snippetListIds, snippetId];
|
|
21
18
|
|
|
22
19
|
return this.args.onChange(newSnippetListIds);
|
|
23
20
|
}
|
|
24
21
|
|
|
25
|
-
const newSnippetListIds = this.args.
|
|
22
|
+
const newSnippetListIds = this.args.snippetListIds.filter(
|
|
26
23
|
(id) => id !== snippetId,
|
|
27
24
|
);
|
|
28
25
|
|
|
@@ -49,8 +46,7 @@ export default class SnippetListViewComponent extends Component<Args> {
|
|
|
49
46
|
return;
|
|
50
47
|
}
|
|
51
48
|
|
|
52
|
-
const isSelected =
|
|
53
|
-
this.args.assignedSnippetListsIds.includes(snippetListId);
|
|
49
|
+
const isSelected = this.args.snippetListIds.includes(snippetListId);
|
|
54
50
|
|
|
55
51
|
this.onChange(snippetListId, !isSelected);
|
|
56
52
|
}
|