@lblod/ember-rdfa-editor-lblod-plugins 25.1.0 → 25.2.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 +23 -0
- package/README.md +7 -6
- package/addon/components/citation-plugin/citation-insert.ts +23 -14
- package/addon/components/snippet-plugin/nodes/placeholder.gts +41 -22
- package/addon/components/snippet-plugin/nodes/snippet.gts +52 -31
- package/addon/components/snippet-plugin/search-modal.hbs +4 -1
- package/addon/components/snippet-plugin/search-modal.ts +5 -0
- package/addon/components/snippet-plugin/snippet-insert-rdfa.gts +7 -12
- package/addon/components/snippet-plugin/snippet-insert.gts +1 -0
- package/addon/plugins/citation-plugin/index.ts +57 -24
- package/addon/plugins/snippet-plugin/index.ts +1 -0
- package/addon/plugins/snippet-plugin/nodes/snippet-placeholder.ts +12 -7
- package/addon/plugins/snippet-plugin/nodes/snippet.ts +27 -15
- package/addon/plugins/snippet-plugin/utils/rdfa-predicate.ts +3 -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 +2 -1
- package/declarations/addon/components/snippet-plugin/search-modal.d.ts +2 -0
- package/declarations/addon/plugins/citation-plugin/index.d.ts +15 -8
- package/declarations/addon/plugins/snippet-plugin/index.d.ts +1 -0
- package/declarations/addon/plugins/snippet-plugin/nodes/snippet-placeholder.d.ts +3 -3
- package/declarations/addon/plugins/snippet-plugin/nodes/snippet.d.ts +1 -1
- package/declarations/addon/plugins/snippet-plugin/utils/rdfa-predicate.d.ts +1 -0
- package/package.json +1 -1
- package/translations/en-US.yaml +2 -2
- package/translations/nl-BE.yaml +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @lblod/ember-rdfa-editor-lblod-plugins
|
|
2
2
|
|
|
3
|
+
## 25.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#496](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/496) [`2e3c09f`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/2e3c09f95db40967caaceaa791e7eefd6187c5e4) Thanks [@piemonkey](https://github.com/piemonkey)! - Redesign snippet placeholder to have more intuitive UX
|
|
8
|
+
|
|
9
|
+
- [#503](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/503) [`37ba9c3`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/37ba9c3ecd2c0452fb49ea1d0bb2704e6e716d05) Thanks [@elpoelma](https://github.com/elpoelma)! - Extension of configuration options of `citation-plugin`.
|
|
10
|
+
The `CitationPluginNodeConfig` is extended to allow for a `activeInNode` condition.
|
|
11
|
+
This allows you to specify a condition which an active/context node needs to satisfy.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
interface CitationPluginNodeConditionConfig {
|
|
15
|
+
type: 'nodes';
|
|
16
|
+
regex?: RegExp;
|
|
17
|
+
|
|
18
|
+
activeInNode(node: PNode, state?: EditorState): boolean;
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The previously expected `activeInNodeTypes` option is marked as deprecated and will be removed in a future release.
|
|
23
|
+
|
|
24
|
+
- [#501](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/501) [`997fa98`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/997fa986a7094349ad368d291cb8364e5c50a140) Thanks [@lagartoverde](https://github.com/lagartoverde)! - Add snippet list names to the modal title
|
|
25
|
+
|
|
3
26
|
## 25.1.0
|
|
4
27
|
|
|
5
28
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -335,9 +335,11 @@ Make `this.citationPlugin` a tracked reference to the plugin created with the fu
|
|
|
335
335
|
|
|
336
336
|
Configuration:
|
|
337
337
|
|
|
338
|
-
- type: it can be 'nodes' or 'ranges'
|
|
339
|
-
|
|
340
|
-
|
|
338
|
+
- type (optional): it can either be 'nodes', or 'ranges'
|
|
339
|
+
* if 'nodes' is selected, you are expected to pass the `activeInNode` function. It's a function which expects an instance of a prosemirror node and returns whether it should be active in that node. The previously expected `activeInNodeTypes` is marked as deprecated and will be removed in a future release.
|
|
340
|
+
* if 'ranges' is selected, you are expected to pass the `activeInRanges` function. It's a function that gets the state of the actual instance of the editor and returns an array of ranges for the plugin to be active in, for example `[[0,50], [70,100]]`
|
|
341
|
+
* if no type is provided, the citation plugin will be activated document-wide
|
|
342
|
+
|
|
341
343
|
- regex: you can provide your custom regex to detect citations, if not the default one will be used
|
|
342
344
|
|
|
343
345
|
A common usecase is to have the plugin active in the entire document. Here's how to do that using each configuration type:
|
|
@@ -347,9 +349,8 @@ import { citationPlugin } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/c
|
|
|
347
349
|
|
|
348
350
|
const configA = {
|
|
349
351
|
type: 'nodes',
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
return new Set([schema.nodes.doc]);
|
|
352
|
+
activeInNode(node, state) {
|
|
353
|
+
return node.type === state.schema.nodes.doc;
|
|
353
354
|
},
|
|
354
355
|
};
|
|
355
356
|
|
|
@@ -3,6 +3,7 @@ import { action } from '@ember/object';
|
|
|
3
3
|
import { tracked } from '@glimmer/tracking';
|
|
4
4
|
import {
|
|
5
5
|
Fragment,
|
|
6
|
+
PNode,
|
|
6
7
|
SayController,
|
|
7
8
|
Slice,
|
|
8
9
|
Transaction,
|
|
@@ -14,7 +15,7 @@ import {
|
|
|
14
15
|
LEGISLATION_TYPES,
|
|
15
16
|
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/citation-plugin/utils/types';
|
|
16
17
|
import { unwrap } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/option';
|
|
17
|
-
import {
|
|
18
|
+
import { findParentNode } from '@curvenote/prosemirror-utils';
|
|
18
19
|
import { Article } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/citation-plugin/utils/article';
|
|
19
20
|
import { LegalDocument } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/citation-plugin/utils/legal-documents';
|
|
20
21
|
import { AddIcon } from '@appuniversum/ember-appuniversum/components/icons/add';
|
|
@@ -62,10 +63,13 @@ export default class EditorPluginsCitationInsertComponent extends Component<Args
|
|
|
62
63
|
return true;
|
|
63
64
|
}
|
|
64
65
|
const { selection } = this.controller.mainEditorState;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
const config = this.config;
|
|
67
|
+
if (!('type' in config)) {
|
|
68
|
+
// Enable plugin document wide
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
if (config.type === 'ranges') {
|
|
72
|
+
const ranges = config.activeInRanges(this.controller.mainEditorState);
|
|
69
73
|
for (const range of ranges) {
|
|
70
74
|
if (selection.from > range[0] && selection.from < range[1]) {
|
|
71
75
|
return false;
|
|
@@ -73,17 +77,22 @@ export default class EditorPluginsCitationInsertComponent extends Component<Args
|
|
|
73
77
|
}
|
|
74
78
|
return true;
|
|
75
79
|
} else {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
let condition: (node: PNode) => boolean;
|
|
81
|
+
if ('activeInNodeTypes' in config) {
|
|
82
|
+
const nodeTypes = config.activeInNodeTypes(
|
|
83
|
+
this.controller.schema,
|
|
84
|
+
this.controller.mainEditorState,
|
|
85
|
+
);
|
|
86
|
+
condition = (node) => nodeTypes.has(node.type);
|
|
87
|
+
} else {
|
|
88
|
+
condition = (node) =>
|
|
89
|
+
config.activeInNode(node, this.controller.mainEditorState);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (condition(this.controller.mainEditorState.doc)) {
|
|
84
93
|
return false;
|
|
85
94
|
}
|
|
86
|
-
return !
|
|
95
|
+
return !findParentNode(condition)(selection);
|
|
87
96
|
}
|
|
88
97
|
}
|
|
89
98
|
|
|
@@ -1,21 +1,32 @@
|
|
|
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: Pick<EmberNodeArgs, 'node' | 'selectNode'
|
|
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
25
|
return this.args.node.attrs.snippetListNames;
|
|
18
26
|
}
|
|
27
|
+
get config(): SnippetPluginConfig {
|
|
28
|
+
return this.node.attrs.config;
|
|
29
|
+
}
|
|
19
30
|
get isSingleList() {
|
|
20
31
|
return this.listNames.length === 1;
|
|
21
32
|
}
|
|
@@ -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,
|
|
@@ -30,6 +31,8 @@ import { transactionCombinator } from '@lblod/ember-rdfa-editor/utils/transactio
|
|
|
30
31
|
import { recalculateNumbers } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/structure-plugin/recalculate-structure-numbers';
|
|
31
32
|
import { createSnippetPlaceholder } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin/nodes/snippet-placeholder';
|
|
32
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';
|
|
33
36
|
|
|
34
37
|
interface ButtonSig {
|
|
35
38
|
Args: {
|
|
@@ -76,6 +79,13 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
76
79
|
get node() {
|
|
77
80
|
return this.args.node;
|
|
78
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
|
+
|
|
79
89
|
@action
|
|
80
90
|
closeModal() {
|
|
81
91
|
this.showModal = false;
|
|
@@ -85,10 +95,6 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
85
95
|
this.showModal = true;
|
|
86
96
|
}
|
|
87
97
|
|
|
88
|
-
get allowMultipleSnippets() {
|
|
89
|
-
return this.node.attrs.allowMultipleSnippets as boolean;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
98
|
@action
|
|
93
99
|
addFragment() {
|
|
94
100
|
if (this.allowMultipleSnippets) {
|
|
@@ -123,7 +129,7 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
123
129
|
const node = createSnippetPlaceholder({
|
|
124
130
|
listProperties: {
|
|
125
131
|
placeholderId: this.node.attrs.placeholderId,
|
|
126
|
-
listIds: this.node
|
|
132
|
+
listIds: getSnippetListIdsFromNode(this.node),
|
|
127
133
|
names: this.node.attrs.snippetListNames,
|
|
128
134
|
importedResources: this.node.attrs.importedResources,
|
|
129
135
|
},
|
|
@@ -155,6 +161,12 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
155
161
|
return this.controller.mainEditorState.selection;
|
|
156
162
|
}
|
|
157
163
|
get isActive(): boolean {
|
|
164
|
+
if (
|
|
165
|
+
this.selection instanceof NodeSelection &&
|
|
166
|
+
this.selection.node === this.node
|
|
167
|
+
) {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
158
170
|
const ancestor = findAncestors(this.selection.$from, (node: PNode) => {
|
|
159
171
|
return hasOutgoingNamedNodeTriple(
|
|
160
172
|
node.attrs,
|
|
@@ -188,7 +200,7 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
188
200
|
title,
|
|
189
201
|
listProperties: {
|
|
190
202
|
placeholderId: this.node.attrs.placeholderId,
|
|
191
|
-
listIds: this.node
|
|
203
|
+
listIds: getSnippetListIdsFromNode(this.node),
|
|
192
204
|
names: this.node.attrs.snippetListNames,
|
|
193
205
|
importedResources: this.node.attrs.importedResources,
|
|
194
206
|
},
|
|
@@ -199,40 +211,49 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
199
211
|
}
|
|
200
212
|
|
|
201
213
|
<template>
|
|
202
|
-
|
|
203
|
-
<
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
<
|
|
213
|
-
@icon={{BinIcon}}
|
|
214
|
-
@helpText='snippet-plugin.snippet-node.remove-fragment'
|
|
215
|
-
{{on 'click' this.deleteFragment}}
|
|
216
|
-
@isActive={{this.isActive}}
|
|
217
|
-
class='say-snippet-remove-button'
|
|
218
|
-
/>
|
|
219
|
-
{{#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'>
|
|
220
225
|
<SnippetButton
|
|
221
|
-
@icon={{
|
|
222
|
-
@helpText='snippet-plugin.snippet-node.
|
|
223
|
-
{{on 'click' this.
|
|
226
|
+
@icon={{SynchronizeIcon}}
|
|
227
|
+
@helpText='snippet-plugin.snippet-node.change-fragment'
|
|
228
|
+
{{on 'click' this.editFragment}}
|
|
224
229
|
@isActive={{this.isActive}}
|
|
225
230
|
/>
|
|
226
|
-
|
|
227
|
-
|
|
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>
|
|
228
247
|
|
|
229
|
-
|
|
248
|
+
</div>
|
|
249
|
+
{{/if}}
|
|
230
250
|
<SearchModal
|
|
231
251
|
@open={{this.showModal}}
|
|
232
252
|
@closeModal={{this.closeModal}}
|
|
233
253
|
@config={{this.node.attrs.config}}
|
|
234
254
|
@onInsert={{this.onInsert}}
|
|
235
|
-
@snippetListIds={{this.node
|
|
255
|
+
@snippetListIds={{getSnippetListIdsFromNode this.node}}
|
|
256
|
+
@snippetListNames={{this.node.attrs.snippetListNames}}
|
|
236
257
|
/>
|
|
237
258
|
</template>
|
|
238
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|
|
|
@@ -12,6 +12,7 @@ import { SnippetPluginConfig } from '@lblod/ember-rdfa-editor-lblod-plugins/plug
|
|
|
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(
|
|
@@ -7,10 +7,7 @@ import {
|
|
|
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
|
|
|
@@ -25,13 +22,11 @@ interface Sig {
|
|
|
25
22
|
export default class SnippetInsertRdfaComponent extends Component<Sig> {
|
|
26
23
|
get listProperties(): SnippetListProperties | undefined {
|
|
27
24
|
const activeNode = this.args.node.value;
|
|
28
|
-
const
|
|
25
|
+
const listIds = getSnippetListIdsFromNode(activeNode);
|
|
29
26
|
|
|
30
|
-
if (
|
|
27
|
+
if (listIds.length > 0) {
|
|
31
28
|
return {
|
|
32
|
-
listIds
|
|
33
|
-
activeNodeSnippetListIds,
|
|
34
|
-
),
|
|
29
|
+
listIds,
|
|
35
30
|
placeholderId: activeNode.attrs.placeholderId,
|
|
36
31
|
names: activeNode.attrs.snippetListNames,
|
|
37
32
|
importedResources: activeNode.attrs.importedResources,
|
|
@@ -49,11 +44,11 @@ export default class SnippetInsertRdfaComponent extends Component<Sig> {
|
|
|
49
44
|
isResourceNode(node),
|
|
50
45
|
);
|
|
51
46
|
while (parentNode) {
|
|
52
|
-
const
|
|
47
|
+
const listIds = getSnippetListIdsFromNode(parentNode.node);
|
|
53
48
|
|
|
54
|
-
if (
|
|
49
|
+
if (listIds.length > 0) {
|
|
55
50
|
return {
|
|
56
|
-
listIds
|
|
51
|
+
listIds,
|
|
57
52
|
placeholderId: parentNode.node.attrs.placeholderId,
|
|
58
53
|
names: parentNode.node.attrs.snippetListNames,
|
|
59
54
|
importedResources: parentNode.node.attrs.importedResources,
|
|
@@ -119,21 +119,31 @@ interface CitationPluginState {
|
|
|
119
119
|
|
|
120
120
|
export type CitationPlugin = ProsePlugin<CitationPluginState>;
|
|
121
121
|
|
|
122
|
-
export
|
|
122
|
+
export type CitationPluginNodeConfig = CitationPluginBaseConfig & {
|
|
123
123
|
type: 'nodes';
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
} & (
|
|
125
|
+
| {
|
|
126
|
+
/**
|
|
127
|
+
* @deprecated use the `activeInNode` property instead
|
|
128
|
+
*/
|
|
129
|
+
activeInNodeTypes(schema: Schema, state: EditorState): Set<NodeType>;
|
|
130
|
+
}
|
|
131
|
+
| {
|
|
132
|
+
activeInNode(node: PNode, state?: EditorState): boolean;
|
|
133
|
+
}
|
|
134
|
+
);
|
|
128
135
|
|
|
129
|
-
export
|
|
136
|
+
export type CitationPluginRangeConfig = CitationPluginBaseConfig & {
|
|
130
137
|
type: 'ranges';
|
|
131
|
-
regex?: RegExp;
|
|
132
|
-
|
|
133
138
|
activeInRanges(state: EditorState): [number, number][];
|
|
134
|
-
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export type CitationPluginBaseConfig = {
|
|
142
|
+
regex?: RegExp;
|
|
143
|
+
};
|
|
135
144
|
|
|
136
145
|
export type CitationPluginConfig =
|
|
146
|
+
| CitationPluginBaseConfig
|
|
137
147
|
| CitationPluginNodeConfig
|
|
138
148
|
| CitationPluginRangeConfig;
|
|
139
149
|
|
|
@@ -176,21 +186,43 @@ function calculateCitationPluginState(
|
|
|
176
186
|
const { doc, schema } = state;
|
|
177
187
|
let activeRanges;
|
|
178
188
|
let highlights;
|
|
179
|
-
if (
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
189
|
+
if ('type' in config) {
|
|
190
|
+
if (config.type === 'ranges') {
|
|
191
|
+
activeRanges = config.activeInRanges(state);
|
|
192
|
+
const calculatedDecs = calculateDecorationsInRanges(
|
|
193
|
+
config,
|
|
194
|
+
schema,
|
|
195
|
+
doc,
|
|
196
|
+
activeRanges,
|
|
197
|
+
);
|
|
198
|
+
highlights = calculatedDecs.decorations;
|
|
199
|
+
} else {
|
|
200
|
+
let condition: (node: PNode) => boolean;
|
|
201
|
+
if ('activeInNodeTypes' in config) {
|
|
202
|
+
const nodeTypes = config.activeInNodeTypes(schema, state);
|
|
203
|
+
condition = (node) => {
|
|
204
|
+
return nodeTypes.has(node.type);
|
|
205
|
+
};
|
|
206
|
+
} else {
|
|
207
|
+
condition = (node) => config.activeInNode(node, state);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const calculatedDecs = calculateDecorationsInNodes(
|
|
211
|
+
config,
|
|
212
|
+
schema,
|
|
213
|
+
condition,
|
|
214
|
+
doc,
|
|
215
|
+
oldState?.doc,
|
|
216
|
+
oldDecs,
|
|
217
|
+
);
|
|
218
|
+
activeRanges = calculatedDecs.activeRanges;
|
|
219
|
+
highlights = calculatedDecs.decorations;
|
|
220
|
+
}
|
|
188
221
|
} else {
|
|
189
|
-
const nodes = config.activeInNodeTypes(schema, state);
|
|
190
222
|
const calculatedDecs = calculateDecorationsInNodes(
|
|
191
223
|
config,
|
|
192
224
|
schema,
|
|
193
|
-
|
|
225
|
+
() => true,
|
|
194
226
|
doc,
|
|
195
227
|
oldState?.doc,
|
|
196
228
|
oldDecs,
|
|
@@ -198,6 +230,7 @@ function calculateCitationPluginState(
|
|
|
198
230
|
activeRanges = calculatedDecs.activeRanges;
|
|
199
231
|
highlights = calculatedDecs.decorations;
|
|
200
232
|
}
|
|
233
|
+
|
|
201
234
|
return {
|
|
202
235
|
highlights,
|
|
203
236
|
activeRanges,
|
|
@@ -207,7 +240,7 @@ function calculateCitationPluginState(
|
|
|
207
240
|
function calculateDecorationsInNodes(
|
|
208
241
|
config: CitationPluginConfig,
|
|
209
242
|
schema: CitationSchema,
|
|
210
|
-
|
|
243
|
+
condition: (node: PNode) => boolean,
|
|
211
244
|
newDoc: PNode,
|
|
212
245
|
oldDoc?: PNode,
|
|
213
246
|
oldDecorations?: DecorationSet,
|
|
@@ -223,7 +256,7 @@ function calculateDecorationsInNodes(
|
|
|
223
256
|
decsToRemove,
|
|
224
257
|
oldDecorations,
|
|
225
258
|
);
|
|
226
|
-
if (
|
|
259
|
+
if (condition(newDoc)) {
|
|
227
260
|
oldDoc
|
|
228
261
|
? changedDescendants(oldDoc, newDoc, 0, collector)
|
|
229
262
|
: newDoc.descendants(collector);
|
|
@@ -236,7 +269,7 @@ function calculateDecorationsInNodes(
|
|
|
236
269
|
0,
|
|
237
270
|
|
|
238
271
|
(node, pos) => {
|
|
239
|
-
if (
|
|
272
|
+
if (condition(node)) {
|
|
240
273
|
node.nodesBetween(0, node.nodeSize - 2, collector, pos + 1);
|
|
241
274
|
activeRanges.push([pos, pos + node.nodeSize]);
|
|
242
275
|
return false;
|
|
@@ -245,7 +278,7 @@ function calculateDecorationsInNodes(
|
|
|
245
278
|
},
|
|
246
279
|
)
|
|
247
280
|
: newDoc.descendants((node, pos) => {
|
|
248
|
-
if (
|
|
281
|
+
if (condition(node)) {
|
|
249
282
|
node.nodesBetween(0, node.nodeSize - 2, collector, pos + 1);
|
|
250
283
|
activeRanges.push([pos, pos + node.nodeSize]);
|
|
251
284
|
return false;
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
createEmberNodeView,
|
|
12
12
|
type EmberNodeConfig,
|
|
13
13
|
} from '@lblod/ember-rdfa-editor/utils/ember-node';
|
|
14
|
-
import
|
|
14
|
+
import SnippetComponent from '@lblod/ember-rdfa-editor-lblod-plugins/components/snippet-plugin/nodes/snippet';
|
|
15
15
|
import {
|
|
16
16
|
EXT,
|
|
17
17
|
RDF,
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
type SnippetListProperties,
|
|
24
24
|
type ImportedResourceMap,
|
|
25
25
|
type SnippetList,
|
|
26
|
+
type SnippetPluginConfig,
|
|
26
27
|
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
27
28
|
import { tripleForSnippetListId } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin/utils/rdfa-predicate';
|
|
28
29
|
import { OutgoingTriple } from '@lblod/ember-rdfa-editor/core/rdfa-processor';
|
|
@@ -93,7 +94,7 @@ export function createSnippetPlaceholder({
|
|
|
93
94
|
});
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
const emberNodeConfig: EmberNodeConfig
|
|
97
|
+
const emberNodeConfig = (config: SnippetPluginConfig): EmberNodeConfig => ({
|
|
97
98
|
name: 'snippet_placeholder',
|
|
98
99
|
inline: false,
|
|
99
100
|
group: 'block',
|
|
@@ -107,8 +108,11 @@ const emberNodeConfig: EmberNodeConfig = {
|
|
|
107
108
|
snippetListNames: { default: [] },
|
|
108
109
|
importedResources: { default: {} },
|
|
109
110
|
allowMultipleSnippets: { default: false },
|
|
111
|
+
config: {
|
|
112
|
+
default: config,
|
|
113
|
+
},
|
|
110
114
|
},
|
|
111
|
-
component:
|
|
115
|
+
component: SnippetComponent,
|
|
112
116
|
serialize(node, editorState) {
|
|
113
117
|
const t = getTranslationFunction(editorState);
|
|
114
118
|
const listNames = node.attrs.snippetListNames as string[];
|
|
@@ -116,7 +120,6 @@ const emberNodeConfig: EmberNodeConfig = {
|
|
|
116
120
|
renderable: node,
|
|
117
121
|
tag: 'div',
|
|
118
122
|
attrs: {
|
|
119
|
-
...node.attrs,
|
|
120
123
|
class: 'say-snippet-placeholder-node',
|
|
121
124
|
'data-list-names': listNames && JSON.stringify(listNames),
|
|
122
125
|
'data-imported-resources': JSON.stringify(node.attrs.importedResources),
|
|
@@ -169,7 +172,9 @@ const emberNodeConfig: EmberNodeConfig = {
|
|
|
169
172
|
},
|
|
170
173
|
},
|
|
171
174
|
],
|
|
172
|
-
};
|
|
175
|
+
});
|
|
173
176
|
|
|
174
|
-
export const snippetPlaceholder =
|
|
175
|
-
|
|
177
|
+
export const snippetPlaceholder = (config: SnippetPluginConfig) =>
|
|
178
|
+
createEmberNodeSpec(emberNodeConfig(config));
|
|
179
|
+
export const snippetPlaceholderView = (config: SnippetPluginConfig) =>
|
|
180
|
+
createEmberNodeView(emberNodeConfig(config));
|
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
SnippetListProperties,
|
|
36
36
|
type SnippetPluginConfig,
|
|
37
37
|
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
38
|
+
import { tripleForSnippetListId } from '../utils/rdfa-predicate';
|
|
38
39
|
|
|
39
40
|
function outgoingFromBacklink(
|
|
40
41
|
backlink: IncomingTriple,
|
|
@@ -58,6 +59,13 @@ function outgoingFromBacklink(
|
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
|
|
62
|
+
const defaultProperties = [
|
|
63
|
+
{
|
|
64
|
+
predicate: RDF('type').full,
|
|
65
|
+
object: sayDataFactory.namedNode(EXT('Snippet').full),
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
|
|
61
69
|
interface CreateSnippetArgs {
|
|
62
70
|
schema: Schema;
|
|
63
71
|
allowMultipleSnippets?: boolean;
|
|
@@ -78,7 +86,7 @@ export function createSnippet({
|
|
|
78
86
|
title,
|
|
79
87
|
allowMultipleSnippets,
|
|
80
88
|
listProperties: {
|
|
81
|
-
listIds
|
|
89
|
+
listIds,
|
|
82
90
|
names: snippetListNames,
|
|
83
91
|
importedResources,
|
|
84
92
|
placeholderId,
|
|
@@ -100,11 +108,15 @@ export function createSnippet({
|
|
|
100
108
|
schema,
|
|
101
109
|
parser,
|
|
102
110
|
});
|
|
111
|
+
const properties = [
|
|
112
|
+
...defaultProperties,
|
|
113
|
+
...listIds.map(tripleForSnippetListId),
|
|
114
|
+
];
|
|
103
115
|
const node = schema.node(
|
|
104
116
|
'snippet',
|
|
105
117
|
{
|
|
106
118
|
placeholderId,
|
|
107
|
-
|
|
119
|
+
properties,
|
|
108
120
|
snippetListNames,
|
|
109
121
|
title,
|
|
110
122
|
subject: `http://data.lblod.info/snippets/${uuidv4()}`,
|
|
@@ -150,17 +162,11 @@ const emberNodeConfig = (options: SnippetPluginConfig): EmberNodeConfig => ({
|
|
|
150
162
|
attrs: {
|
|
151
163
|
...rdfaAttrSpec({ rdfaAware: true }),
|
|
152
164
|
properties: {
|
|
153
|
-
default:
|
|
154
|
-
{
|
|
155
|
-
predicate: RDF('type').full,
|
|
156
|
-
object: sayDataFactory.namedNode(EXT('Snippet').full),
|
|
157
|
-
},
|
|
158
|
-
],
|
|
165
|
+
default: defaultProperties,
|
|
159
166
|
},
|
|
160
167
|
rdfaNodeType: { default: 'resource' },
|
|
161
168
|
placeholderId: { default: '' },
|
|
162
169
|
snippetListNames: { default: [] },
|
|
163
|
-
snippetListIds: { default: [] },
|
|
164
170
|
importedResources: { default: {} },
|
|
165
171
|
title: { default: '' },
|
|
166
172
|
config: { default: options },
|
|
@@ -176,9 +182,6 @@ const emberNodeConfig = (options: SnippetPluginConfig): EmberNodeConfig => ({
|
|
|
176
182
|
attrs: {
|
|
177
183
|
...node.attrs,
|
|
178
184
|
'data-snippet-placeholder-id': node.attrs.placeholderId,
|
|
179
|
-
'data-assigned-snippet-ids': (
|
|
180
|
-
node.attrs.snippetListIds as string[]
|
|
181
|
-
)?.join(','),
|
|
182
185
|
'data-list-names': listNames && JSON.stringify(listNames),
|
|
183
186
|
'data-imported-resources': JSON.stringify(node.attrs.importedResources),
|
|
184
187
|
'data-snippet-title': node.attrs.title,
|
|
@@ -194,6 +197,8 @@ const emberNodeConfig = (options: SnippetPluginConfig): EmberNodeConfig => ({
|
|
|
194
197
|
if (typeof node === 'string') return false;
|
|
195
198
|
const rdfaAttrs = getRdfaAttrs(node, { rdfaAware: true });
|
|
196
199
|
if (
|
|
200
|
+
rdfaAttrs &&
|
|
201
|
+
rdfaAttrs.rdfaNodeType !== 'literal' &&
|
|
197
202
|
hasOutgoingNamedNodeTriple(rdfaAttrs, RDF('type'), EXT('Snippet'))
|
|
198
203
|
) {
|
|
199
204
|
// For older documents without placeholder ids, treat each inserted snippet separately.
|
|
@@ -202,12 +207,19 @@ const emberNodeConfig = (options: SnippetPluginConfig): EmberNodeConfig => ({
|
|
|
202
207
|
// risking having no ability to insert another snippet.
|
|
203
208
|
const placeholderId =
|
|
204
209
|
node.getAttribute('data-snippet-placeholder-id') || uuidv4();
|
|
210
|
+
const legacySnippetListIds = node
|
|
211
|
+
.getAttribute('data-assigned-snippet-ids')
|
|
212
|
+
?.split(',');
|
|
213
|
+
const properties = !legacySnippetListIds
|
|
214
|
+
? rdfaAttrs.properties
|
|
215
|
+
: [
|
|
216
|
+
...rdfaAttrs.properties,
|
|
217
|
+
...legacySnippetListIds.map(tripleForSnippetListId),
|
|
218
|
+
];
|
|
205
219
|
return {
|
|
206
220
|
...rdfaAttrs,
|
|
221
|
+
properties,
|
|
207
222
|
placeholderId,
|
|
208
|
-
snippetListIds: node
|
|
209
|
-
.getAttribute('data-assigned-snippet-ids')
|
|
210
|
-
?.split(','),
|
|
211
223
|
snippetListNames: jsonParse(node.getAttribute('data-list-names')),
|
|
212
224
|
importedResources: jsonParse(
|
|
213
225
|
node.getAttribute('data-imported-resources'),
|
|
@@ -33,3 +33,6 @@ export const getAssignedSnippetListsIdsFromProperties = (
|
|
|
33
33
|
.map(getSnippetIdFromUri)
|
|
34
34
|
.filter((id) => id !== undefined);
|
|
35
35
|
};
|
|
36
|
+
|
|
37
|
+
export const getSnippetListIdsFromNode = (node: PNode) =>
|
|
38
|
+
getAssignedSnippetListsIdsFromProperties(getSnippetListIdsProperties(node));
|
|
@@ -86,29 +86,6 @@
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
.ProseMirror-selectednode > .say-snippet-placeholder {
|
|
90
|
-
background-color: var(--au-blue-200);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
.say-snippet-placeholder-node {
|
|
94
|
-
background-color: var(--au-orange-200);
|
|
95
|
-
padding: 2rem;
|
|
96
|
-
|
|
97
|
-
div {
|
|
98
|
-
font-weight: var(--au-medium);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
div[typeof='besluitpublicatie:Documentonderdeel']
|
|
103
|
-
.say-snippet-placeholder-node {
|
|
104
|
-
background-color: var(--au-gray-300);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
.rdfa-annotations
|
|
108
|
-
[typeof]:not([typeof='foaf:Document']).say-snippet-placeholder-node {
|
|
109
|
-
padding-bottom: 2rem;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
89
|
.say-snippet-card {
|
|
113
90
|
border: 1px solid var(--au-blue-300);
|
|
114
91
|
.say-snippet-title {
|
|
@@ -164,3 +141,62 @@ div[typeof='besluitpublicatie:Documentonderdeel']
|
|
|
164
141
|
}
|
|
165
142
|
}
|
|
166
143
|
}
|
|
144
|
+
|
|
145
|
+
.say-snippet-placeholder {
|
|
146
|
+
display: flex;
|
|
147
|
+
flex-direction: row;
|
|
148
|
+
padding: $au-unit-small $au-unit-small * 1.5;
|
|
149
|
+
background-color: var(--au-orange-300);
|
|
150
|
+
border-radius: var(--au-radius);
|
|
151
|
+
border: 0.1rem solid var(--au-orange-500);
|
|
152
|
+
|
|
153
|
+
.say-snippet-placeholder__icon {
|
|
154
|
+
background-color: var(--au-orange-500);
|
|
155
|
+
color: black;
|
|
156
|
+
height: $au-unit - 0.1rem; // compensate for visual distortion of perfect circle
|
|
157
|
+
width: $au-unit;
|
|
158
|
+
margin-right: $au-unit * 0.5;
|
|
159
|
+
border-radius: $au-unit-large;
|
|
160
|
+
display: flex;
|
|
161
|
+
align-items: center;
|
|
162
|
+
justify-content: center;
|
|
163
|
+
flex-shrink: 0;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.say-snippet-placeholder__content {
|
|
167
|
+
margin-top: 0;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.say-snippet-placeholder__title {
|
|
171
|
+
color: var(--au-orange-700);
|
|
172
|
+
font-weight: var(--au-medium);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.say-snippet-placeholder__button {
|
|
176
|
+
margin: 0;
|
|
177
|
+
padding: 0;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.ProseMirror-selectednode > .say-snippet-placeholder {
|
|
182
|
+
background-color: var(--au-blue-200);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.say-snippet-placeholder-node {
|
|
186
|
+
background-color: var(--au-orange-200);
|
|
187
|
+
padding: 2rem;
|
|
188
|
+
|
|
189
|
+
div {
|
|
190
|
+
font-weight: var(--au-medium);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
div[typeof='besluitpublicatie:Documentonderdeel']
|
|
195
|
+
.say-snippet-placeholder-node {
|
|
196
|
+
background-color: var(--au-gray-300);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
.rdfa-annotations
|
|
200
|
+
[typeof]:not([typeof='foaf:Document']).say-snippet-placeholder-node {
|
|
201
|
+
padding-bottom: 2rem;
|
|
202
|
+
}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import Component from '@glimmer/component';
|
|
2
|
-
import { type EmberNodeArgs } from '@lblod/ember-rdfa-editor/utils/_private/ember-node';
|
|
3
2
|
import IntlService from 'ember-intl/services/intl';
|
|
3
|
+
import { type EmberNodeArgs } from '@lblod/ember-rdfa-editor/utils/_private/ember-node';
|
|
4
|
+
import { type SnippetPluginConfig } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
4
5
|
interface Signature {
|
|
5
|
-
Args: Pick<EmberNodeArgs, 'node' | 'selectNode'
|
|
6
|
+
Args: Pick<EmberNodeArgs, 'node' | 'selectNode'> & {
|
|
7
|
+
insertSnippet: () => void;
|
|
8
|
+
};
|
|
6
9
|
}
|
|
7
10
|
export default class SnippetPluginPlaceholder extends Component<Signature> {
|
|
8
11
|
intl: IntlService;
|
|
12
|
+
get node(): import("prosemirror-model").Node;
|
|
9
13
|
get listNames(): any;
|
|
14
|
+
get config(): SnippetPluginConfig;
|
|
10
15
|
get isSingleList(): boolean;
|
|
11
16
|
get alertTitle(): string;
|
|
12
17
|
}
|
|
@@ -14,9 +14,10 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
14
14
|
get schema(): import("prosemirror-model").Schema<any, any>;
|
|
15
15
|
get snippetOrPlaceholder(): import("prosemirror-model").NodeType[];
|
|
16
16
|
get node(): PNode;
|
|
17
|
+
get isPlaceholder(): boolean;
|
|
18
|
+
get allowMultipleSnippets(): boolean;
|
|
17
19
|
closeModal(): void;
|
|
18
20
|
openModal(): void;
|
|
19
|
-
get allowMultipleSnippets(): boolean;
|
|
20
21
|
addFragment(): void;
|
|
21
22
|
editFragment(): void;
|
|
22
23
|
deleteFragment(): void;
|
|
@@ -3,6 +3,7 @@ import { SnippetPluginConfig } from '@lblod/ember-rdfa-editor-lblod-plugins/plug
|
|
|
3
3
|
interface Args {
|
|
4
4
|
config: SnippetPluginConfig;
|
|
5
5
|
snippetListIds: string[] | undefined;
|
|
6
|
+
snippetListNames: string[] | undefined;
|
|
6
7
|
closeModal: () => void;
|
|
7
8
|
open: boolean;
|
|
8
9
|
onInsert: (content: string, title: string) => void;
|
|
@@ -15,6 +16,7 @@ export default class SnippetPluginSearchModalComponent extends Component<Args> {
|
|
|
15
16
|
totalCount: number;
|
|
16
17
|
get config(): SnippetPluginConfig;
|
|
17
18
|
get searchText(): string | null;
|
|
19
|
+
get snippetListNames(): string | undefined;
|
|
18
20
|
setInputSearchText(event: InputEvent): void;
|
|
19
21
|
closeModal(): Promise<void>;
|
|
20
22
|
snippetsSearch: import("ember-concurrency").TaskForAsyncTaskFunction<unknown, () => Promise<import("@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin").Snippet[]>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Decoration, DecorationSet, EditorState, InlineDecorationSpec, NodeType, ProsePlugin, Schema } from '@lblod/ember-rdfa-editor';
|
|
1
|
+
import { Decoration, DecorationSet, EditorState, InlineDecorationSpec, NodeType, PNode, ProsePlugin, Schema } from '@lblod/ember-rdfa-editor';
|
|
2
2
|
/**
|
|
3
3
|
* The monster regex that makes the citation plugin trigger to show `CitationCard`.
|
|
4
4
|
* In restructuring, I've made sure that I didn't abstract away any of the capturing groups,
|
|
@@ -20,17 +20,24 @@ interface CitationPluginState {
|
|
|
20
20
|
activeRanges: [number, number][];
|
|
21
21
|
}
|
|
22
22
|
export type CitationPlugin = ProsePlugin<CitationPluginState>;
|
|
23
|
-
export
|
|
23
|
+
export type CitationPluginNodeConfig = CitationPluginBaseConfig & {
|
|
24
24
|
type: 'nodes';
|
|
25
|
-
|
|
25
|
+
} & ({
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated use the `activeInNode` property instead
|
|
28
|
+
*/
|
|
26
29
|
activeInNodeTypes(schema: Schema, state: EditorState): Set<NodeType>;
|
|
27
|
-
}
|
|
28
|
-
|
|
30
|
+
} | {
|
|
31
|
+
activeInNode(node: PNode, state?: EditorState): boolean;
|
|
32
|
+
});
|
|
33
|
+
export type CitationPluginRangeConfig = CitationPluginBaseConfig & {
|
|
29
34
|
type: 'ranges';
|
|
30
|
-
regex?: RegExp;
|
|
31
35
|
activeInRanges(state: EditorState): [number, number][];
|
|
32
|
-
}
|
|
33
|
-
export type
|
|
36
|
+
};
|
|
37
|
+
export type CitationPluginBaseConfig = {
|
|
38
|
+
regex?: RegExp;
|
|
39
|
+
};
|
|
40
|
+
export type CitationPluginConfig = CitationPluginBaseConfig | CitationPluginNodeConfig | CitationPluginRangeConfig;
|
|
34
41
|
export type CitationPluginEmberComponentConfig = CitationPluginConfig & {
|
|
35
42
|
endpoint: string;
|
|
36
43
|
decisionsEndpoint?: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Schema } from '@lblod/ember-rdfa-editor';
|
|
2
|
-
import { type SnippetListProperties, type ImportedResourceMap, type SnippetList } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
2
|
+
import { type SnippetListProperties, type ImportedResourceMap, type SnippetList, type SnippetPluginConfig } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
3
3
|
export declare function importedResourcesFromSnippetLists(lists: SnippetList[], existing?: ImportedResourceMap): {
|
|
4
4
|
[k: string]: import("../../../utils/option").Option<string>;
|
|
5
5
|
};
|
|
@@ -12,6 +12,6 @@ type CreateSnippetPlaceholderArgs = {
|
|
|
12
12
|
lists: SnippetList[];
|
|
13
13
|
});
|
|
14
14
|
export declare function createSnippetPlaceholder({ schema, allowMultipleSnippets, ...args }: CreateSnippetPlaceholderArgs): import("prosemirror-model").Node;
|
|
15
|
-
export declare const snippetPlaceholder: import("@lblod/ember-rdfa-editor/core/say-node-spec").default;
|
|
16
|
-
export declare const snippetPlaceholderView: (controller: import("@lblod/ember-rdfa-editor").SayController) => import("@lblod/ember-rdfa-editor/utils/ember-node").SayNodeViewConstructor;
|
|
15
|
+
export declare const snippetPlaceholder: (config: SnippetPluginConfig) => import("@lblod/ember-rdfa-editor/core/say-node-spec").default;
|
|
16
|
+
export declare const snippetPlaceholderView: (config: SnippetPluginConfig) => (controller: import("@lblod/ember-rdfa-editor").SayController) => import("@lblod/ember-rdfa-editor/utils/ember-node").SayNodeViewConstructor;
|
|
17
17
|
export {};
|
|
@@ -14,7 +14,7 @@ interface CreateSnippetArgs {
|
|
|
14
14
|
* @returns a tuple containing the Node and the map of imported resources to the new outgoing
|
|
15
15
|
* properties that these resources will have after the snippet is inserted into the document.
|
|
16
16
|
**/
|
|
17
|
-
export declare function createSnippet({ schema, content, title, allowMultipleSnippets, listProperties: { listIds
|
|
17
|
+
export declare function createSnippet({ schema, content, title, allowMultipleSnippets, listProperties: { listIds, names: snippetListNames, importedResources, placeholderId, }, }: CreateSnippetArgs): [PNode, Map<string, OutgoingTriple[]>];
|
|
18
18
|
export declare const snippet: (config: SnippetPluginConfig) => import("@lblod/ember-rdfa-editor/core/say-node-spec").default;
|
|
19
19
|
export declare const snippetView: (config: SnippetPluginConfig) => (controller: import("@lblod/ember-rdfa-editor").SayController) => import("@lblod/ember-rdfa-editor/utils/ember-node").SayNodeViewConstructor;
|
|
20
20
|
export {};
|
|
@@ -9,3 +9,4 @@ export declare function tripleForSnippetListId(id: string): {
|
|
|
9
9
|
};
|
|
10
10
|
export declare const getSnippetListIdsProperties: (node: PNode) => OutgoingTriple[];
|
|
11
11
|
export declare const getAssignedSnippetListsIdsFromProperties: (snippetListIdsProperty?: OutgoingTriple[] | undefined) => string[];
|
|
12
|
+
export declare const getSnippetListIdsFromNode: (node: PNode) => string[];
|
package/package.json
CHANGED
package/translations/en-US.yaml
CHANGED
|
@@ -301,10 +301,10 @@ snippet-plugin:
|
|
|
301
301
|
placeholder:
|
|
302
302
|
title-single: Snippet from the list "{listName}"
|
|
303
303
|
title-multiple: Snippet from multiple lists
|
|
304
|
-
|
|
304
|
+
button: Select the desired snippet
|
|
305
305
|
active-lists: 'Active lists:'
|
|
306
306
|
modal:
|
|
307
|
-
title: Choose a snippet
|
|
307
|
+
title: Choose a snippet from {snippetListNames}
|
|
308
308
|
preview-button:
|
|
309
309
|
title: Show snippet preview
|
|
310
310
|
select-button:
|
package/translations/nl-BE.yaml
CHANGED
|
@@ -300,10 +300,10 @@ snippet-plugin:
|
|
|
300
300
|
placeholder:
|
|
301
301
|
title-single: Fragment uit de lijst "{listName}"
|
|
302
302
|
title-multiple: Fragment uit meerdere lijsten
|
|
303
|
-
|
|
303
|
+
button: Selecteer het gewenste fragment
|
|
304
304
|
active-lists: 'Actieve lijsten:'
|
|
305
305
|
modal:
|
|
306
|
-
title: Kies een fragment
|
|
306
|
+
title: Kies een fragment uit {snippetListNames}
|
|
307
307
|
preview-button:
|
|
308
308
|
title: Preview van fragment tonen
|
|
309
309
|
select-button:
|