@lblod/ember-rdfa-editor-lblod-plugins 22.4.1 → 22.5.0-dev.fcb046da689838b3df38c0256efef0dce73e7cd1
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 +18 -0
- package/addon/components/auto-resizing-text-area.gts +43 -0
- package/addon/components/lmb-plugin/list.hbs +1 -1
- package/addon/components/lmb-plugin/search-modal.hbs +10 -7
- package/addon/components/lmb-plugin/search-modal.ts +8 -1
- package/addon/components/mandatee-table-plugin/configure.gts +4 -4
- package/addon/components/mandatee-table-plugin/node.gts +1 -1
- package/addon/components/snippet-plugin/nodes/snippet.gts +17 -30
- package/addon/components/snippet-plugin/search-modal.ts +1 -1
- package/addon/components/snippet-plugin/snippet-insert-placeholder.gts +15 -14
- package/addon/components/snippet-plugin/snippet-insert-rdfa.gts +82 -0
- package/addon/components/snippet-plugin/snippet-insert.gts +109 -0
- package/addon/components/snippet-plugin/snippet-list/snippet-list-modal.hbs +1 -1
- package/addon/components/snippet-plugin/snippet-list/snippet-list-modal.ts +8 -11
- package/addon/components/snippet-plugin/snippet-list/snippet-list-view.hbs +4 -1
- package/addon/components/snippet-plugin/snippet-list-select-rdfa.gts +25 -0
- package/addon/components/snippet-plugin/snippet-list-select.gts +104 -0
- package/addon/plugins/mandatee-table-plugin/node.ts +5 -1
- package/addon/plugins/snippet-plugin/commands/index.ts +1 -1
- package/addon/plugins/snippet-plugin/commands/{update-snippet-ids.ts → update-snippet-placeholder.ts} +23 -12
- package/addon/plugins/snippet-plugin/index.ts +19 -11
- package/addon/plugins/snippet-plugin/nodes/snippet-placeholder.ts +27 -9
- package/addon/plugins/snippet-plugin/nodes/snippet.ts +160 -2
- package/addon/plugins/snippet-plugin/utils/collate-imported-resources.ts +22 -0
- package/addon/plugins/snippet-plugin/utils/fetch-data.ts +52 -36
- package/addon/plugins/snippet-plugin/utils/rdfa-predicate.ts +3 -15
- package/addon/utils/sparql-helpers.ts +3 -4
- package/addon/utils/strings.ts +13 -0
- package/app/styles/mandatee-table-plugin.scss +5 -0
- package/declarations/addon/components/auto-resizing-text-area.d.ts +22 -0
- package/declarations/addon/components/snippet-plugin/nodes/snippet.d.ts +1 -1
- package/declarations/addon/components/snippet-plugin/search-modal.d.ts +1 -1
- package/declarations/addon/components/snippet-plugin/snippet-insert-placeholder.d.ts +2 -2
- package/declarations/addon/components/snippet-plugin/snippet-insert-rdfa.d.ts +13 -13
- package/declarations/addon/components/snippet-plugin/snippet-insert.d.ts +13 -9
- package/declarations/addon/components/snippet-plugin/snippet-list/snippet-list-modal.d.ts +2 -2
- package/declarations/addon/components/snippet-plugin/snippet-list-select-rdfa.d.ts +15 -19
- package/declarations/addon/components/snippet-plugin/snippet-list-select.d.ts +13 -5
- package/declarations/addon/plugins/snippet-plugin/commands/index.d.ts +1 -1
- package/declarations/addon/plugins/snippet-plugin/commands/update-snippet-placeholder.d.ts +11 -0
- package/declarations/addon/plugins/snippet-plugin/index.d.ts +12 -8
- package/declarations/addon/plugins/snippet-plugin/nodes/snippet-placeholder.d.ts +5 -1
- package/declarations/addon/plugins/snippet-plugin/nodes/snippet.d.ts +27 -2
- package/declarations/addon/plugins/snippet-plugin/utils/collate-imported-resources.d.ts +2 -0
- package/declarations/addon/plugins/snippet-plugin/utils/fetch-data.d.ts +0 -1
- package/declarations/addon/plugins/snippet-plugin/utils/rdfa-predicate.d.ts +1 -1
- package/declarations/addon/utils/sparql-helpers.d.ts +5 -3
- package/declarations/addon/utils/strings.d.ts +2 -0
- package/package.json +3 -3
- package/pnpm-lock.yaml +29 -29
- package/translations/en-US.yaml +1 -0
- package/translations/nl-BE.yaml +1 -0
- package/addon/components/snippet-plugin/snippet-insert-rdfa.hbs +0 -7
- package/addon/components/snippet-plugin/snippet-insert-rdfa.ts +0 -78
- package/addon/components/snippet-plugin/snippet-insert.hbs +0 -20
- package/addon/components/snippet-plugin/snippet-insert.ts +0 -95
- package/addon/components/snippet-plugin/snippet-list-select-rdfa.hbs +0 -8
- package/addon/components/snippet-plugin/snippet-list-select-rdfa.ts +0 -68
- package/addon/components/snippet-plugin/snippet-list-select.hbs +0 -17
- package/addon/components/snippet-plugin/snippet-list-select.ts +0 -29
- package/declarations/addon/plugins/snippet-plugin/commands/update-snippet-ids.d.ts +0 -11
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { action } from '@ember/object';
|
|
2
|
+
import Component from '@glimmer/component';
|
|
3
|
+
import { tracked } from '@glimmer/tracking';
|
|
4
|
+
import { on } from '@ember/modifier';
|
|
5
|
+
import t from 'ember-intl/helpers/t';
|
|
6
|
+
import { UnorderedListIcon } from '@appuniversum/ember-appuniversum/components/icons/unordered-list';
|
|
7
|
+
import AuButton from '@appuniversum/ember-appuniversum/components/au-button';
|
|
8
|
+
import { type SayController } from '@lblod/ember-rdfa-editor';
|
|
9
|
+
import { type ResolvedPNode } from '@lblod/ember-rdfa-editor/utils/_private/types';
|
|
10
|
+
import { isResourceNode } from '@lblod/ember-rdfa-editor/utils/node-utils';
|
|
11
|
+
import { type OutgoingTriple } from '@lblod/ember-rdfa-editor/core/rdfa-processor';
|
|
12
|
+
import SnippetListModal from '@lblod/ember-rdfa-editor-lblod-plugins/components/snippet-plugin/snippet-list/snippet-list-modal';
|
|
13
|
+
import {
|
|
14
|
+
type ImportedResourceMap,
|
|
15
|
+
type SnippetPluginConfig,
|
|
16
|
+
type SnippetList,
|
|
17
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
18
|
+
import {
|
|
19
|
+
getAssignedSnippetListsIdsFromProperties,
|
|
20
|
+
getSnippetListIdsProperties,
|
|
21
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin/utils/rdfa-predicate';
|
|
22
|
+
import { updateSnippetPlaceholder } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin/commands';
|
|
23
|
+
|
|
24
|
+
interface Signature {
|
|
25
|
+
Args: {
|
|
26
|
+
controller: SayController;
|
|
27
|
+
config: SnippetPluginConfig;
|
|
28
|
+
node: ResolvedPNode;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default class SnippetListSelect extends Component<Signature> {
|
|
33
|
+
@tracked showModal = false;
|
|
34
|
+
|
|
35
|
+
@action
|
|
36
|
+
openModal() {
|
|
37
|
+
this.showModal = true;
|
|
38
|
+
}
|
|
39
|
+
@action
|
|
40
|
+
closeModal() {
|
|
41
|
+
this.showModal = false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get currentResource() {
|
|
45
|
+
return this.args.node.value.attrs.subject as string | undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get isResourceNode() {
|
|
49
|
+
return isResourceNode(this.args.node.value);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
get snippetListIdsProperties(): OutgoingTriple[] {
|
|
53
|
+
return getSnippetListIdsProperties(this.args.node.value);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
get assignedSnippetListsIds(): string[] {
|
|
57
|
+
return getAssignedSnippetListsIdsFromProperties(
|
|
58
|
+
this.snippetListIdsProperties,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get imported(): ImportedResourceMap {
|
|
63
|
+
return this.args.node.value.attrs['importedResources'];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@action
|
|
67
|
+
onSaveSnippetLists(lists: SnippetList[]) {
|
|
68
|
+
if (this.currentResource) {
|
|
69
|
+
this.args.controller?.doCommand(
|
|
70
|
+
updateSnippetPlaceholder({
|
|
71
|
+
resource: this.currentResource,
|
|
72
|
+
oldSnippetProperties: this.snippetListIdsProperties ?? [],
|
|
73
|
+
newSnippetLists: lists,
|
|
74
|
+
oldImportedResources: this.imported,
|
|
75
|
+
node: this.args.node,
|
|
76
|
+
}),
|
|
77
|
+
{
|
|
78
|
+
view: this.args.controller.mainEditorView,
|
|
79
|
+
},
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
<template>
|
|
85
|
+
{{#if this.isResourceNode}}
|
|
86
|
+
<AuButton
|
|
87
|
+
@icon={{UnorderedListIcon}}
|
|
88
|
+
@skin='secondary'
|
|
89
|
+
@iconAlignment='left'
|
|
90
|
+
{{on 'click' this.openModal}}
|
|
91
|
+
>
|
|
92
|
+
{{t 'snippet-plugin.snippet-list.open-modal'}}
|
|
93
|
+
</AuButton>
|
|
94
|
+
|
|
95
|
+
<SnippetListModal
|
|
96
|
+
@config={{@config}}
|
|
97
|
+
@assignedSnippetListsIds={{this.assignedSnippetListsIds}}
|
|
98
|
+
@onSaveSnippetLists={{this.onSaveSnippetLists}}
|
|
99
|
+
@open={{this.showModal}}
|
|
100
|
+
@closeModal={{this.closeModal}}
|
|
101
|
+
/>
|
|
102
|
+
{{/if}}
|
|
103
|
+
</template>
|
|
104
|
+
}
|
|
@@ -35,7 +35,11 @@ export const emberNodeConfig: () => EmberNodeConfig = () => {
|
|
|
35
35
|
'data-say-mandatee-table-title': title,
|
|
36
36
|
class: 'say-mandatee-table-node',
|
|
37
37
|
},
|
|
38
|
-
[
|
|
38
|
+
[
|
|
39
|
+
'div',
|
|
40
|
+
{ class: 'say-mandatee-table-header' },
|
|
41
|
+
['h6', { class: 'say-mandatee-table__title' }, title],
|
|
42
|
+
],
|
|
39
43
|
[
|
|
40
44
|
'div',
|
|
41
45
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { updateSnippetPlaceholder } from './update-snippet-placeholder';
|
|
@@ -3,21 +3,26 @@ import { addProperty, removeProperty } from '@lblod/ember-rdfa-editor/commands';
|
|
|
3
3
|
import { sayDataFactory } from '@lblod/ember-rdfa-editor/core/say-data-factory';
|
|
4
4
|
import { SNIPPET_LIST_RDFA_PREDICATE } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin/utils/rdfa-predicate';
|
|
5
5
|
import { getSnippetUriFromId } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
6
|
-
import { OutgoingTriple } from '@lblod/ember-rdfa-editor/core/rdfa-processor';
|
|
7
|
-
import { ResolvedPNode } from '@lblod/ember-rdfa-editor/utils/_private/types';
|
|
6
|
+
import { type OutgoingTriple } from '@lblod/ember-rdfa-editor/core/rdfa-processor';
|
|
7
|
+
import { type ResolvedPNode } from '@lblod/ember-rdfa-editor/utils/_private/types';
|
|
8
|
+
import {
|
|
9
|
+
type ImportedResourceMap,
|
|
10
|
+
type SnippetList,
|
|
11
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
12
|
+
import { importedResourcesFromSnippetLists } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin/nodes/snippet-placeholder';
|
|
8
13
|
|
|
9
|
-
const updateSnippetPlaceholder = ({
|
|
14
|
+
export const updateSnippetPlaceholder = ({
|
|
10
15
|
resource,
|
|
11
16
|
oldSnippetProperties,
|
|
12
|
-
|
|
17
|
+
newSnippetLists,
|
|
18
|
+
oldImportedResources,
|
|
13
19
|
node,
|
|
14
|
-
snippetNames,
|
|
15
20
|
}: {
|
|
16
21
|
resource: string;
|
|
17
22
|
oldSnippetProperties: OutgoingTriple[];
|
|
18
|
-
|
|
23
|
+
newSnippetLists: SnippetList[];
|
|
24
|
+
oldImportedResources: ImportedResourceMap;
|
|
19
25
|
node: ResolvedPNode;
|
|
20
|
-
snippetNames: string[];
|
|
21
26
|
}): Command => {
|
|
22
27
|
return (state, dispatch) => {
|
|
23
28
|
if (dispatch) {
|
|
@@ -36,14 +41,14 @@ const updateSnippetPlaceholder = ({
|
|
|
36
41
|
});
|
|
37
42
|
});
|
|
38
43
|
|
|
39
|
-
|
|
44
|
+
newSnippetLists.forEach((list) => {
|
|
40
45
|
newState = state.apply(transaction);
|
|
41
46
|
|
|
42
47
|
addProperty({
|
|
43
48
|
resource,
|
|
44
49
|
property: {
|
|
45
50
|
predicate: SNIPPET_LIST_RDFA_PREDICATE.prefixed,
|
|
46
|
-
object: sayDataFactory.namedNode(getSnippetUriFromId(
|
|
51
|
+
object: sayDataFactory.namedNode(getSnippetUriFromId(list.id)),
|
|
47
52
|
},
|
|
48
53
|
transaction,
|
|
49
54
|
})(newState, (newTransaction) => {
|
|
@@ -53,7 +58,15 @@ const updateSnippetPlaceholder = ({
|
|
|
53
58
|
transaction = transaction.setNodeAttribute(
|
|
54
59
|
node.pos,
|
|
55
60
|
'listNames',
|
|
56
|
-
|
|
61
|
+
newSnippetLists.map((list) => list.label),
|
|
62
|
+
);
|
|
63
|
+
transaction = transaction.setNodeAttribute(
|
|
64
|
+
node.pos,
|
|
65
|
+
'importedResources',
|
|
66
|
+
importedResourcesFromSnippetLists(
|
|
67
|
+
newSnippetLists,
|
|
68
|
+
oldImportedResources,
|
|
69
|
+
),
|
|
57
70
|
);
|
|
58
71
|
|
|
59
72
|
dispatch(transaction);
|
|
@@ -61,5 +74,3 @@ const updateSnippetPlaceholder = ({
|
|
|
61
74
|
return true;
|
|
62
75
|
};
|
|
63
76
|
};
|
|
64
|
-
|
|
65
|
-
export default updateSnippetPlaceholder;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { htmlSafe } from '@ember/template';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type Option,
|
|
5
|
+
optionMapOr,
|
|
6
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/option';
|
|
4
7
|
import { dateValue } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/strings';
|
|
5
8
|
import { SafeString } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/types';
|
|
6
9
|
|
|
@@ -26,11 +29,14 @@ export class Snippet {
|
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
export type ImportedResourceMap = Record<string, Option<string>>;
|
|
33
|
+
|
|
34
|
+
export type SnippetListArgs = {
|
|
35
|
+
id: string;
|
|
36
|
+
label: string;
|
|
37
|
+
createdOn: string;
|
|
38
|
+
importedResources: string[];
|
|
39
|
+
};
|
|
34
40
|
|
|
35
41
|
const snippetListBase = 'http://lblod.data.gift/snippet-lists/';
|
|
36
42
|
|
|
@@ -40,13 +46,15 @@ export const getSnippetIdFromUri = (uri: string) =>
|
|
|
40
46
|
uri.replace(snippetListBase, '');
|
|
41
47
|
|
|
42
48
|
export class SnippetList {
|
|
43
|
-
id: string
|
|
44
|
-
label: string
|
|
49
|
+
id: string;
|
|
50
|
+
label: string;
|
|
45
51
|
createdOn: string | null;
|
|
52
|
+
importedResources: string[];
|
|
46
53
|
|
|
47
|
-
constructor({ id, label, createdOn }: SnippetListArgs) {
|
|
48
|
-
this.id =
|
|
54
|
+
constructor({ id, label, createdOn, importedResources }: SnippetListArgs) {
|
|
55
|
+
this.id = getSnippetIdFromUri(id);
|
|
49
56
|
this.label = label;
|
|
50
|
-
this.createdOn = dateValue(createdOn
|
|
57
|
+
this.createdOn = dateValue(createdOn);
|
|
58
|
+
this.importedResources = importedResources;
|
|
51
59
|
}
|
|
52
60
|
}
|
|
@@ -18,30 +18,43 @@ import {
|
|
|
18
18
|
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
|
|
19
19
|
import { hasOutgoingNamedNodeTriple } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/namespace';
|
|
20
20
|
import { getTranslationFunction } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/translation';
|
|
21
|
-
import {
|
|
21
|
+
import { jsonParse } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/strings';
|
|
22
|
+
import {
|
|
23
|
+
getSnippetUriFromId,
|
|
24
|
+
type ImportedResourceMap,
|
|
25
|
+
type SnippetList,
|
|
26
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
22
27
|
import { SNIPPET_LIST_RDFA_PREDICATE } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin/utils/rdfa-predicate';
|
|
23
28
|
|
|
24
|
-
export function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
schema: Schema,
|
|
29
|
+
export function importedResourcesFromSnippetLists(
|
|
30
|
+
lists: SnippetList[],
|
|
31
|
+
existing: ImportedResourceMap = {},
|
|
28
32
|
) {
|
|
29
|
-
|
|
33
|
+
return Object.fromEntries<ImportedResourceMap[string]>(
|
|
34
|
+
lists
|
|
35
|
+
.flatMap((list) => list.importedResources)
|
|
36
|
+
// Null is important (in place of undefined) in order to keep the unlinked entries
|
|
37
|
+
.map((res) => [res, existing[res] ?? null]),
|
|
38
|
+
);
|
|
39
|
+
}
|
|
30
40
|
|
|
41
|
+
export function createSnippetPlaceholder(lists: SnippetList[], schema: Schema) {
|
|
42
|
+
const mappingResource = `http://example.net/lblod-snippet-placeholder/${uuidv4()}`;
|
|
31
43
|
return schema.nodes.snippet_placeholder.create({
|
|
32
44
|
rdfaNodeType: 'resource',
|
|
33
|
-
listNames,
|
|
45
|
+
listNames: lists.map((list) => list.label),
|
|
34
46
|
subject: mappingResource,
|
|
35
47
|
properties: [
|
|
36
48
|
{
|
|
37
49
|
predicate: RDF('type').full,
|
|
38
50
|
object: sayDataFactory.namedNode(EXT('SnippetPlaceholder').full),
|
|
39
51
|
},
|
|
40
|
-
...
|
|
52
|
+
...lists.map((list) => ({
|
|
41
53
|
predicate: SNIPPET_LIST_RDFA_PREDICATE.full,
|
|
42
|
-
object: sayDataFactory.namedNode(getSnippetUriFromId(
|
|
54
|
+
object: sayDataFactory.namedNode(getSnippetUriFromId(list.id)),
|
|
43
55
|
})),
|
|
44
56
|
],
|
|
57
|
+
importedResources: importedResourcesFromSnippetLists(lists),
|
|
45
58
|
});
|
|
46
59
|
}
|
|
47
60
|
|
|
@@ -56,6 +69,7 @@ const emberNodeConfig: EmberNodeConfig = {
|
|
|
56
69
|
...rdfaAttrSpec({ rdfaAware: true }),
|
|
57
70
|
typeof: { default: EXT('SnippetPlaceholder') },
|
|
58
71
|
listNames: { default: [] },
|
|
72
|
+
importedResources: { default: {} },
|
|
59
73
|
},
|
|
60
74
|
component: SnippetPlaceholderComponent,
|
|
61
75
|
serialize(node, editorState) {
|
|
@@ -67,6 +81,7 @@ const emberNodeConfig: EmberNodeConfig = {
|
|
|
67
81
|
...node.attrs,
|
|
68
82
|
class: 'say-snippet-placeholder-node',
|
|
69
83
|
'data-list-names': (node.attrs.listNames as string[]).join(','),
|
|
84
|
+
'data-imported-resources': JSON.stringify(node.attrs.importedResources),
|
|
70
85
|
},
|
|
71
86
|
content: [
|
|
72
87
|
'text',
|
|
@@ -93,6 +108,9 @@ const emberNodeConfig: EmberNodeConfig = {
|
|
|
93
108
|
return {
|
|
94
109
|
...rdfaAttrs,
|
|
95
110
|
listNames: node.getAttribute('data-list-names')?.split(','),
|
|
111
|
+
importedResources: jsonParse(
|
|
112
|
+
node.getAttribute('data-imported-resources'),
|
|
113
|
+
),
|
|
96
114
|
};
|
|
97
115
|
}
|
|
98
116
|
return false;
|
|
@@ -1,21 +1,174 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
+
import {
|
|
3
|
+
type Attrs,
|
|
4
|
+
getRdfaAttrs,
|
|
5
|
+
type PNode,
|
|
6
|
+
ProseParser,
|
|
7
|
+
rdfaAttrSpec,
|
|
8
|
+
type SayController,
|
|
9
|
+
type Transaction,
|
|
10
|
+
} from '@lblod/ember-rdfa-editor';
|
|
2
11
|
import {
|
|
3
12
|
renderRdfaAware,
|
|
4
13
|
getRdfaContentElement,
|
|
5
14
|
} from '@lblod/ember-rdfa-editor/core/schema';
|
|
6
15
|
import { sayDataFactory } from '@lblod/ember-rdfa-editor/core/say-data-factory';
|
|
16
|
+
import {
|
|
17
|
+
type IncomingTriple,
|
|
18
|
+
type OutgoingTriple,
|
|
19
|
+
} from '@lblod/ember-rdfa-editor/core/rdfa-processor';
|
|
7
20
|
import {
|
|
8
21
|
createEmberNodeSpec,
|
|
9
22
|
createEmberNodeView,
|
|
10
23
|
type EmberNodeConfig,
|
|
11
24
|
} from '@lblod/ember-rdfa-editor/utils/ember-node';
|
|
25
|
+
import { htmlToDoc } from '@lblod/ember-rdfa-editor/utils/_private/html-utils';
|
|
26
|
+
import { transactionCombinator } from '@lblod/ember-rdfa-editor/utils/transaction-utils';
|
|
27
|
+
import { addPropertyToNode } from '@lblod/ember-rdfa-editor/utils/rdfa-utils';
|
|
12
28
|
import SnippetComponent from '@lblod/ember-rdfa-editor-lblod-plugins/components/snippet-plugin/nodes/snippet';
|
|
13
29
|
import {
|
|
14
30
|
EXT,
|
|
15
31
|
RDF,
|
|
16
32
|
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
|
|
17
33
|
import { hasOutgoingNamedNodeTriple } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/namespace';
|
|
18
|
-
import {
|
|
34
|
+
import { jsonParse } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/strings';
|
|
35
|
+
import {
|
|
36
|
+
type ImportedResourceMap,
|
|
37
|
+
type SnippetPluginConfig,
|
|
38
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
39
|
+
import {
|
|
40
|
+
isSome,
|
|
41
|
+
unwrap,
|
|
42
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/option';
|
|
43
|
+
|
|
44
|
+
function outgoingFromBacklink(
|
|
45
|
+
backlink: IncomingTriple,
|
|
46
|
+
attrs: Attrs,
|
|
47
|
+
): OutgoingTriple {
|
|
48
|
+
if (attrs.rdfaNodeType === 'resource') {
|
|
49
|
+
return {
|
|
50
|
+
predicate: backlink.predicate,
|
|
51
|
+
object: sayDataFactory.resourceNode(attrs.subject),
|
|
52
|
+
};
|
|
53
|
+
} else {
|
|
54
|
+
return {
|
|
55
|
+
predicate: backlink.predicate,
|
|
56
|
+
object: sayDataFactory.literalNode(
|
|
57
|
+
attrs.__rdfaId,
|
|
58
|
+
('language' in backlink.subject && backlink.subject.language) ||
|
|
59
|
+
('datatype' in backlink.subject && backlink.subject.datatype) ||
|
|
60
|
+
'',
|
|
61
|
+
),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface CreateSnippetArgs {
|
|
67
|
+
controller: SayController;
|
|
68
|
+
content: string;
|
|
69
|
+
title: string;
|
|
70
|
+
snippetListIds: string[];
|
|
71
|
+
importedResources: ImportedResourceMap;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Creates a Snippet node wrapping the given content while allowing for further snippets to be added
|
|
76
|
+
* or removed. Takes care of linking imported resources.
|
|
77
|
+
* @returns a tuple containing the Node and the map of imported resources to the new outgoing
|
|
78
|
+
* properties that these resources will have after the snippet is inserted into the document.
|
|
79
|
+
**/
|
|
80
|
+
export function createSnippet({
|
|
81
|
+
controller,
|
|
82
|
+
content,
|
|
83
|
+
title,
|
|
84
|
+
snippetListIds,
|
|
85
|
+
importedResources,
|
|
86
|
+
}: CreateSnippetArgs): [PNode, Map<string, OutgoingTriple[]>] {
|
|
87
|
+
// Replace instances of linked to uris with the resources that exist in the outer document.
|
|
88
|
+
let replacedContent = content;
|
|
89
|
+
for (const imported in importedResources) {
|
|
90
|
+
const linked = importedResources[imported];
|
|
91
|
+
if (linked) {
|
|
92
|
+
replacedContent = replacedContent.replaceAll(imported, linked);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Create the new node
|
|
96
|
+
const parser = ProseParser.fromSchema(controller.schema);
|
|
97
|
+
const contentAsNode = htmlToDoc(replacedContent, {
|
|
98
|
+
schema: controller.schema,
|
|
99
|
+
parser,
|
|
100
|
+
editorView: controller.mainEditorView,
|
|
101
|
+
});
|
|
102
|
+
const node = controller.schema.node(
|
|
103
|
+
'snippet',
|
|
104
|
+
{
|
|
105
|
+
assignedSnippetListsIds: snippetListIds,
|
|
106
|
+
title,
|
|
107
|
+
subject: `http://data.lblod.info/snippets/${uuidv4()}`,
|
|
108
|
+
importedResources,
|
|
109
|
+
},
|
|
110
|
+
contentAsNode.content,
|
|
111
|
+
);
|
|
112
|
+
// Find all the new backlinks that refer to imported resources and generate OutgoingLinks for them
|
|
113
|
+
const importedTriples: Map<string, OutgoingTriple[]> = new Map();
|
|
114
|
+
if (Object.keys(importedResources).length > 0) {
|
|
115
|
+
contentAsNode.descendants((node) => {
|
|
116
|
+
const backlinks = node.attrs.backlinks as IncomingTriple[] | undefined;
|
|
117
|
+
if (backlinks && backlinks.length > 0) {
|
|
118
|
+
for (const imported in importedResources) {
|
|
119
|
+
const linked = importedResources[imported];
|
|
120
|
+
if (linked) {
|
|
121
|
+
const backlink = backlinks.find(
|
|
122
|
+
(bl) => bl.subject.value === linked,
|
|
123
|
+
);
|
|
124
|
+
if (backlink) {
|
|
125
|
+
const collectedLinks = importedTriples.get(linked) || [];
|
|
126
|
+
collectedLinks.push(outgoingFromBacklink(backlink, node.attrs));
|
|
127
|
+
importedTriples.set(linked, collectedLinks);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return [node, importedTriples];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Creates a Snippet node wrapping the given content while allowing for further snippets to be added
|
|
140
|
+
* or removed.
|
|
141
|
+
* Takes the same arguments object as creating a snippet but also a generator that produces a
|
|
142
|
+
* transaction that inserts the snippet into the document, so that this can be done in a way
|
|
143
|
+
* specific to the situation.
|
|
144
|
+
**/
|
|
145
|
+
export function createAndInsertSnippet(
|
|
146
|
+
createSnippetArgs: CreateSnippetArgs,
|
|
147
|
+
insertTransactionGenerator: (tr: Transaction, snippet: PNode) => Transaction,
|
|
148
|
+
) {
|
|
149
|
+
return createSnippetArgs.controller.withTransaction((tr, state) => {
|
|
150
|
+
const [snippet, importedTriples] = createSnippet(createSnippetArgs);
|
|
151
|
+
const result = transactionCombinator<boolean>(
|
|
152
|
+
state,
|
|
153
|
+
insertTransactionGenerator(tr, snippet),
|
|
154
|
+
)(
|
|
155
|
+
Object.values(createSnippetArgs.importedResources)
|
|
156
|
+
.map((linked) => {
|
|
157
|
+
const newProperties =
|
|
158
|
+
(isSome(linked) && importedTriples.get(linked)) || [];
|
|
159
|
+
return newProperties.map((newProp) =>
|
|
160
|
+
addPropertyToNode({
|
|
161
|
+
resource: unwrap(linked),
|
|
162
|
+
property: newProp,
|
|
163
|
+
}),
|
|
164
|
+
);
|
|
165
|
+
})
|
|
166
|
+
.flat(),
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
return result.transaction;
|
|
170
|
+
});
|
|
171
|
+
}
|
|
19
172
|
|
|
20
173
|
const emberNodeConfig = (options: SnippetPluginConfig): EmberNodeConfig => ({
|
|
21
174
|
name: 'snippet',
|
|
@@ -37,6 +190,7 @@ const emberNodeConfig = (options: SnippetPluginConfig): EmberNodeConfig => ({
|
|
|
37
190
|
},
|
|
38
191
|
rdfaNodeType: { default: 'resource' },
|
|
39
192
|
assignedSnippetListsIds: { default: [] },
|
|
193
|
+
importedResources: { default: {} },
|
|
40
194
|
title: { default: '' },
|
|
41
195
|
config: { default: options },
|
|
42
196
|
},
|
|
@@ -51,6 +205,7 @@ const emberNodeConfig = (options: SnippetPluginConfig): EmberNodeConfig => ({
|
|
|
51
205
|
'data-assigned-snippet-ids': (
|
|
52
206
|
node.attrs.assignedSnippetListsIds as string[]
|
|
53
207
|
).join(','),
|
|
208
|
+
'data-imported-resources': JSON.stringify(node.attrs.importedResources),
|
|
54
209
|
'data-snippet-title': node.attrs.title,
|
|
55
210
|
},
|
|
56
211
|
content: 0,
|
|
@@ -70,6 +225,9 @@ const emberNodeConfig = (options: SnippetPluginConfig): EmberNodeConfig => ({
|
|
|
70
225
|
assignedSnippetListsIds: node
|
|
71
226
|
.getAttribute('data-assigned-snippet-ids')
|
|
72
227
|
?.split(','),
|
|
228
|
+
importedResources: jsonParse(
|
|
229
|
+
node.getAttribute('data-imported-resources'),
|
|
230
|
+
),
|
|
73
231
|
title: node.getAttribute('data-snippet-title'),
|
|
74
232
|
};
|
|
75
233
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IMPORTED_RESOURCES_ATTR } from '@lblod/ember-rdfa-editor/plugins/imported-resources';
|
|
2
|
+
import { jsonParse } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/strings';
|
|
3
|
+
import { type Snippet } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
4
|
+
|
|
5
|
+
export function collateImportedResources(snippets: Snippet[]): string[] {
|
|
6
|
+
const domParser = new DOMParser();
|
|
7
|
+
return [
|
|
8
|
+
...new Set(
|
|
9
|
+
snippets.flatMap(({ content }) => {
|
|
10
|
+
const htmlNode =
|
|
11
|
+
content && domParser.parseFromString(content.toString(), 'text/html');
|
|
12
|
+
const imports = jsonParse(
|
|
13
|
+
htmlNode
|
|
14
|
+
?.querySelector('[data-say-document]')
|
|
15
|
+
?.getAttribute(IMPORTED_RESOURCES_ATTR),
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
return Array.isArray(imports) ? (imports as string[]) : [];
|
|
19
|
+
}),
|
|
20
|
+
).values(),
|
|
21
|
+
];
|
|
22
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
+
type BindingObject,
|
|
2
3
|
executeCountQuery,
|
|
3
4
|
executeQuery,
|
|
4
5
|
sparqlEscapeString,
|
|
5
6
|
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/sparql-helpers';
|
|
6
|
-
import { Snippet, SnippetList } from '../index';
|
|
7
|
+
import { Snippet, SnippetList, SnippetListArgs } from '../index';
|
|
7
8
|
|
|
8
9
|
type Filter = { name?: string; assignedSnippetListIds?: string[] };
|
|
9
10
|
export type OrderBy =
|
|
@@ -52,21 +53,21 @@ const buildSnippetCountQuery = ({ name, assignedSnippetListIds }: Filter) => {
|
|
|
52
53
|
`;
|
|
53
54
|
};
|
|
54
55
|
|
|
55
|
-
const buildSnippetListCountQuery = ({ name }: Filter) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
};
|
|
56
|
+
// const buildSnippetListCountQuery = ({ name }: Filter) => {
|
|
57
|
+
// return `
|
|
58
|
+
// PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>
|
|
59
|
+
// SELECT (COUNT(?snippetLists) AS ?count)
|
|
60
|
+
// WHERE {
|
|
61
|
+
// ?snippetLists a ext:SnippetList;
|
|
62
|
+
// skos:prefLabel ?label.
|
|
63
|
+
// ${
|
|
64
|
+
// name
|
|
65
|
+
// ? `FILTER (CONTAINS(LCASE(?label), "${name.toLowerCase()}"))`
|
|
66
|
+
// : ''
|
|
67
|
+
// }
|
|
68
|
+
// }
|
|
69
|
+
// `;
|
|
70
|
+
// };
|
|
70
71
|
|
|
71
72
|
const buildSnippetFetchQuery = ({
|
|
72
73
|
filter: { name, assignedSnippetListIds },
|
|
@@ -141,11 +142,13 @@ const buildSnippetListFetchQuery = ({
|
|
|
141
142
|
PREFIX pav: <http://purl.org/pav/>
|
|
142
143
|
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
|
|
143
144
|
PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>
|
|
145
|
+
PREFIX say: <https://say.data.gift/ns/>
|
|
144
146
|
|
|
145
|
-
SELECT (?snippetLists as ?id) ?label ?createdOn WHERE {
|
|
147
|
+
SELECT (?snippetLists as ?id) ?label ?createdOn ?importedResources WHERE {
|
|
146
148
|
?snippetLists a ext:SnippetList;
|
|
147
149
|
skos:prefLabel ?label;
|
|
148
150
|
pav:createdOn ?createdOn.
|
|
151
|
+
OPTIONAL { ?snippetLists say:snippetImportedResource ?importedResources . }
|
|
149
152
|
${
|
|
150
153
|
name
|
|
151
154
|
? `FILTER (CONTAINS(LCASE(?label), "${name.toLowerCase()}"))`
|
|
@@ -214,34 +217,47 @@ export const fetchSnippetLists = async ({
|
|
|
214
217
|
filter: Filter;
|
|
215
218
|
orderBy: OrderBy;
|
|
216
219
|
}) => {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
// We don't currently use this count, so skip the query, but we'll need it if we make pagination
|
|
221
|
+
// work for the snippet list selector
|
|
222
|
+
// const totalCount = await executeCountQuery({
|
|
223
|
+
// endpoint,
|
|
224
|
+
// query: buildSnippetListCountQuery(filter),
|
|
225
|
+
// abortSignal,
|
|
226
|
+
// });
|
|
222
227
|
|
|
223
|
-
if (totalCount === 0) {
|
|
224
|
-
|
|
225
|
-
}
|
|
228
|
+
// if (totalCount === 0) {
|
|
229
|
+
// return { totalCount, results: [] };
|
|
230
|
+
// }
|
|
226
231
|
|
|
227
|
-
const queryResult = await executeQuery<{
|
|
228
|
-
id: { value: string };
|
|
229
|
-
label: { value: string };
|
|
230
|
-
createdOn: { value: string };
|
|
231
|
-
}>({
|
|
232
|
+
const queryResult = await executeQuery<BindingObject<SnippetListArgs>>({
|
|
232
233
|
endpoint,
|
|
233
234
|
query: buildSnippetListFetchQuery({ filter, orderBy }),
|
|
234
235
|
abortSignal,
|
|
235
236
|
});
|
|
236
237
|
|
|
237
|
-
const results =
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
const results = [
|
|
239
|
+
...queryResult.results.bindings
|
|
240
|
+
.map((binding) => ({
|
|
240
241
|
id: binding.id?.value,
|
|
241
242
|
label: binding.label?.value,
|
|
242
243
|
createdOn: binding.createdOn?.value,
|
|
243
|
-
|
|
244
|
-
|
|
244
|
+
importedResources: binding.importedResources?.value,
|
|
245
|
+
}))
|
|
246
|
+
.reduce((mappedResults, bindings) => {
|
|
247
|
+
const existing = mappedResults.get(bindings.id) ?? {
|
|
248
|
+
...bindings,
|
|
249
|
+
importedResources: [],
|
|
250
|
+
};
|
|
251
|
+
if (bindings.importedResources) {
|
|
252
|
+
existing.importedResources = [
|
|
253
|
+
...existing.importedResources,
|
|
254
|
+
bindings.importedResources,
|
|
255
|
+
];
|
|
256
|
+
}
|
|
257
|
+
return mappedResults.set(bindings.id, existing);
|
|
258
|
+
}, new Map<string, SnippetListArgs>())
|
|
259
|
+
.values(),
|
|
260
|
+
].map((slArgs) => new SnippetList(slArgs));
|
|
245
261
|
|
|
246
|
-
return {
|
|
262
|
+
return { results };
|
|
247
263
|
};
|