@lblod/ember-rdfa-editor-lblod-plugins 24.3.1 → 24.3.2-dev.2ac9ceabc39305020bc2d6bbf37755c2dcb383ac
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/.changeset/tough-pugs-shave.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 +103 -39
- package/addon/components/snippet-plugin/search-modal.hbs +4 -1
- package/addon/components/snippet-plugin/search-modal.ts +8 -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 +17 -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 +53 -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 +3 -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 +2 -1
- package/pnpm-lock.yaml +11 -1
- package/translations/en-US.yaml +2 -2
- package/translations/nl-BE.yaml +2 -2
- package/types/lblod/template-uuid-instantiator.d.ts +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @lblod/ember-rdfa-editor-lblod-plugins
|
|
2
2
|
|
|
3
|
+
## 24.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#498](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/498) [`2f0c6fa`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/2f0c6fa7bb8db188849b5331892eb16d7d692f44) Thanks [@piemonkey](https://github.com/piemonkey)! - Correctly instantiate placeholder URIs in snippets when inserting
|
|
8
|
+
|
|
3
9
|
## 24.3.1
|
|
4
10
|
|
|
5
11
|
### Patch 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,6 +29,10 @@ 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: {
|
|
@@ -62,9 +67,25 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
62
67
|
get controller() {
|
|
63
68
|
return this.args.controller;
|
|
64
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
|
+
}
|
|
65
79
|
get node() {
|
|
66
80
|
return this.args.node;
|
|
67
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
|
+
|
|
68
89
|
@action
|
|
69
90
|
closeModal() {
|
|
70
91
|
this.showModal = false;
|
|
@@ -74,10 +95,6 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
74
95
|
this.showModal = true;
|
|
75
96
|
}
|
|
76
97
|
|
|
77
|
-
get allowMultipleSnippets() {
|
|
78
|
-
return this.node.attrs.allowMultipleSnippets as boolean;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
98
|
@action
|
|
82
99
|
addFragment() {
|
|
83
100
|
if (this.allowMultipleSnippets) {
|
|
@@ -94,17 +111,46 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
94
111
|
deleteFragment() {
|
|
95
112
|
const position = this.args.getPos();
|
|
96
113
|
if (position !== undefined) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
+
}
|
|
103
149
|
}
|
|
104
150
|
}
|
|
105
151
|
createSliceFromElement(element: Element) {
|
|
106
152
|
return new Slice(
|
|
107
|
-
ProseParser.fromSchema(this.
|
|
153
|
+
ProseParser.fromSchema(this.schema).parse(element, {
|
|
108
154
|
preserveWhitespace: true,
|
|
109
155
|
}).content,
|
|
110
156
|
0,
|
|
@@ -115,6 +161,12 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
115
161
|
return this.controller.mainEditorState.selection;
|
|
116
162
|
}
|
|
117
163
|
get isActive(): boolean {
|
|
164
|
+
if (
|
|
165
|
+
this.selection instanceof NodeSelection &&
|
|
166
|
+
this.selection.node === this.node
|
|
167
|
+
) {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
118
170
|
const ancestor = findAncestors(this.selection.$from, (node: PNode) => {
|
|
119
171
|
return hasOutgoingNamedNodeTriple(
|
|
120
172
|
node.attrs,
|
|
@@ -127,7 +179,6 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
127
179
|
@action
|
|
128
180
|
onInsert(content: string, title: string) {
|
|
129
181
|
this.closeModal();
|
|
130
|
-
const assignedSnippetListsIds = this.node.attrs.assignedSnippetListsIds;
|
|
131
182
|
let start = 0;
|
|
132
183
|
let end = 0;
|
|
133
184
|
const pos = this.args.getPos();
|
|
@@ -147,8 +198,12 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
147
198
|
insertSnippet({
|
|
148
199
|
content,
|
|
149
200
|
title,
|
|
150
|
-
|
|
151
|
-
|
|
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
|
+
},
|
|
152
207
|
range: { start, end },
|
|
153
208
|
allowMultipleSnippets: this.allowMultipleSnippets,
|
|
154
209
|
}),
|
|
@@ -156,40 +211,49 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
156
211
|
}
|
|
157
212
|
|
|
158
213
|
<template>
|
|
159
|
-
|
|
160
|
-
<
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
<
|
|
170
|
-
@icon={{BinIcon}}
|
|
171
|
-
@helpText='snippet-plugin.snippet-node.remove-fragment'
|
|
172
|
-
{{on 'click' this.deleteFragment}}
|
|
173
|
-
@isActive={{this.isActive}}
|
|
174
|
-
class='say-snippet-remove-button'
|
|
175
|
-
/>
|
|
176
|
-
{{#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'>
|
|
177
225
|
<SnippetButton
|
|
178
|
-
@icon={{
|
|
179
|
-
@helpText='snippet-plugin.snippet-node.
|
|
180
|
-
{{on 'click' this.
|
|
226
|
+
@icon={{SynchronizeIcon}}
|
|
227
|
+
@helpText='snippet-plugin.snippet-node.change-fragment'
|
|
228
|
+
{{on 'click' this.editFragment}}
|
|
181
229
|
@isActive={{this.isActive}}
|
|
182
230
|
/>
|
|
183
|
-
|
|
184
|
-
|
|
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>
|
|
185
247
|
|
|
186
|
-
|
|
248
|
+
</div>
|
|
249
|
+
{{/if}}
|
|
187
250
|
<SearchModal
|
|
188
251
|
@open={{this.showModal}}
|
|
189
252
|
@closeModal={{this.closeModal}}
|
|
190
253
|
@config={{this.node.attrs.config}}
|
|
191
254
|
@onInsert={{this.onInsert}}
|
|
192
|
-
@
|
|
255
|
+
@snippetListIds={{getSnippetListIdsFromNode this.node}}
|
|
256
|
+
@snippetListNames={{this.node.attrs.snippetListNames}}
|
|
193
257
|
/>
|
|
194
258
|
</template>
|
|
195
259
|
}
|
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
class='snippet-modal'
|
|
4
4
|
@modalOpen={{@open}}
|
|
5
5
|
@closeModal={{this.closeModal}}
|
|
6
|
-
@title={{t
|
|
6
|
+
@title={{t
|
|
7
|
+
'snippet-plugin.modal.title'
|
|
8
|
+
snippetListNames=this.snippetListNames
|
|
9
|
+
}}
|
|
7
10
|
@size='large'
|
|
8
11
|
@padding='none'
|
|
9
12
|
as |modal|
|
|
@@ -11,7 +11,8 @@ 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
|
+
snippetListNames: string[] | undefined;
|
|
15
16
|
closeModal: () => void;
|
|
16
17
|
open: boolean;
|
|
17
18
|
onInsert: (content: string, title: string) => void;
|
|
@@ -37,6 +38,10 @@ export default class SnippetPluginSearchModalComponent extends Component<Args> {
|
|
|
37
38
|
return this.inputSearchText;
|
|
38
39
|
}
|
|
39
40
|
|
|
41
|
+
get snippetListNames() {
|
|
42
|
+
return this.args.snippetListNames?.map((name) => `"${name}"`).join(', ');
|
|
43
|
+
}
|
|
44
|
+
|
|
40
45
|
@action
|
|
41
46
|
setInputSearchText(event: InputEvent) {
|
|
42
47
|
assert(
|
|
@@ -64,8 +69,7 @@ export default class SnippetPluginSearchModalComponent extends Component<Args> {
|
|
|
64
69
|
abortSignal: abortController.signal,
|
|
65
70
|
filter: {
|
|
66
71
|
name: this.inputSearchText ?? undefined,
|
|
67
|
-
|
|
68
|
-
this.args.assignedSnippetListsIds ?? undefined,
|
|
72
|
+
snippetListIds: this.args.snippetListIds ?? undefined,
|
|
69
73
|
},
|
|
70
74
|
pagination: {
|
|
71
75
|
pageNumber: this.pageNumber,
|
|
@@ -88,7 +92,7 @@ export default class SnippetPluginSearchModalComponent extends Component<Args> {
|
|
|
88
92
|
this.inputSearchText,
|
|
89
93
|
this.pageNumber,
|
|
90
94
|
this.pageSize,
|
|
91
|
-
this.args.
|
|
95
|
+
this.args.snippetListIds,
|
|
92
96
|
]);
|
|
93
97
|
|
|
94
98
|
@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,8 @@ 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}}
|
|
92
|
+
@snippetListNames={{@listProperties.names}}
|
|
95
93
|
/>
|
|
96
94
|
</template>
|
|
97
95
|
}
|
|
@@ -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
|
}
|