@lblod/ember-rdfa-editor-lblod-plugins 22.2.0 → 22.2.1-dev.7a3a7c0f54fef43445cfab79cb69ee4e9615cc8e
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/mighty-guests-peel.md +5 -0
- package/CHANGELOG.md +8 -0
- package/README.md +16 -0
- package/addon/components/snippet-plugin/nodes/snippet.gts +12 -21
- 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 +110 -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-select-rdfa.gts +25 -0
- package/addon/components/snippet-plugin/snippet-list-select.gts +104 -0
- 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 +17 -9
- package/addon/plugins/snippet-plugin/nodes/snippet-placeholder.ts +27 -9
- package/addon/plugins/snippet-plugin/nodes/snippet.ts +57 -2
- package/addon/plugins/snippet-plugin/utils/collate-imported-resources.ts +22 -0
- package/addon/plugins/snippet-plugin/utils/fetch-data.ts +4 -1
- package/addon/plugins/snippet-plugin/utils/rdfa-predicate.ts +3 -15
- package/addon/utils/strings.ts +13 -0
- package/app/styles/document-title-plugin.scss +8 -6
- 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 +12 -8
- 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 +10 -6
- package/declarations/addon/plugins/snippet-plugin/nodes/snippet-placeholder.d.ts +5 -1
- package/declarations/addon/plugins/snippet-plugin/nodes/snippet.d.ts +10 -2
- package/declarations/addon/plugins/snippet-plugin/utils/collate-imported-resources.d.ts +2 -0
- package/declarations/addon/plugins/snippet-plugin/utils/rdfa-predicate.d.ts +1 -1
- package/declarations/addon/utils/strings.d.ts +2 -0
- package/package.json +3 -3
- package/pnpm-lock.yaml +26 -25
- 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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @lblod/ember-rdfa-editor-lblod-plugins
|
|
2
2
|
|
|
3
|
+
## 22.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#464](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/464) [`8401163`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/8401163ca2789e1303060fa1532cd26ce3eaa9e7) Thanks [@elpoelma](https://github.com/elpoelma)! - test-app: exclude fingerprinting on ember-leaflet related images to ensure production builds behave as expected
|
|
8
|
+
|
|
9
|
+
- [#466](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/466) [`227387b`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/227387b683b3b49314683b2c299c45c492393eb8) Thanks [@lagartoverde](https://github.com/lagartoverde)! - Don't show title annotation outside the editor
|
|
10
|
+
|
|
3
11
|
## 22.2.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -17,6 +17,22 @@ related to the LBLOD Project.
|
|
|
17
17
|
ember install ember-rdfa-editor-lblod-plugins
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
+
If you are using the location-plugin, you should also add the following configuration to your `ember-cli-build.js` file:
|
|
21
|
+
```js
|
|
22
|
+
fingerprint: {
|
|
23
|
+
exclude: [
|
|
24
|
+
'images/layers-2x.png',
|
|
25
|
+
'images/layers.png',
|
|
26
|
+
'images/marker-icon-2x.png',
|
|
27
|
+
'images/marker-icon.png',
|
|
28
|
+
'images/marker-shadow.png'
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
This ensures the map-view behaves as expected in production builds.
|
|
33
|
+
|
|
34
|
+
Check-out https://github.com/miguelcobain/ember-leaflet?tab=readme-ov-file#production-builds for more information.
|
|
35
|
+
|
|
20
36
|
## General addon information
|
|
21
37
|
|
|
22
38
|
This addon contains the following editor plugins:
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import Component from '@glimmer/component';
|
|
2
2
|
import { on } from '@ember/modifier';
|
|
3
|
-
import AuIcon from '@appuniversum/ember-appuniversum/components/au-icon';
|
|
4
|
-
import { type EmberNodeArgs } from '@lblod/ember-rdfa-editor/utils/_private/ember-node';
|
|
5
3
|
import SearchModal from '../search-modal';
|
|
6
4
|
import { tracked } from '@glimmer/tracking';
|
|
7
5
|
import { action } from '@ember/object';
|
|
6
|
+
import t from 'ember-intl/helpers/t';
|
|
7
|
+
import AuIcon from '@appuniversum/ember-appuniversum/components/au-icon';
|
|
8
8
|
import { SynchronizeIcon } from '@appuniversum/ember-appuniversum/components/icons/synchronize';
|
|
9
9
|
import { BinIcon } from '@appuniversum/ember-appuniversum/components/icons/bin';
|
|
10
10
|
import { AddIcon } from '@appuniversum/ember-appuniversum/components/icons/add';
|
|
11
|
+
import { type EmberNodeArgs } from '@lblod/ember-rdfa-editor/utils/_private/ember-node';
|
|
11
12
|
import {
|
|
12
13
|
PNode,
|
|
13
14
|
ProseParser,
|
|
@@ -15,15 +16,13 @@ import {
|
|
|
15
16
|
Slice,
|
|
16
17
|
Transaction,
|
|
17
18
|
} from '@lblod/ember-rdfa-editor';
|
|
18
|
-
import {
|
|
19
|
+
import { findAncestors } from '@lblod/ember-rdfa-editor/utils/position-utils';
|
|
19
20
|
import {
|
|
20
21
|
EXT,
|
|
21
22
|
RDF,
|
|
22
23
|
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
|
|
23
|
-
import { findAncestors } from '@lblod/ember-rdfa-editor/utils/position-utils';
|
|
24
24
|
import { hasOutgoingNamedNodeTriple } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/namespace';
|
|
25
|
-
import {
|
|
26
|
-
import t from 'ember-intl/helpers/t';
|
|
25
|
+
import { createSnippet } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin/nodes/snippet';
|
|
27
26
|
|
|
28
27
|
interface Signature {
|
|
29
28
|
Args: EmberNodeArgs;
|
|
@@ -91,7 +90,6 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
91
90
|
}
|
|
92
91
|
@action
|
|
93
92
|
onInsert(content: string, title: string) {
|
|
94
|
-
const assignedSnippetListsIds = this.node.attrs.assignedSnippetListsIds;
|
|
95
93
|
let rangeStart = 0;
|
|
96
94
|
let rangeEnd = 0;
|
|
97
95
|
if (this.args.getPos() === undefined) return;
|
|
@@ -110,26 +108,19 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
110
108
|
const documentDiv = parsed.querySelector('div[data-say-document="true"]');
|
|
111
109
|
|
|
112
110
|
this.closeModal();
|
|
113
|
-
const parser = ProseParser.fromSchema(this.controller.schema);
|
|
114
111
|
|
|
115
112
|
if (documentDiv) {
|
|
116
113
|
return this.controller.withTransaction((tr: Transaction) => {
|
|
117
114
|
return tr.replaceRangeWith(
|
|
118
115
|
rangeStart,
|
|
119
116
|
rangeEnd,
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
htmlToDoc(content, {
|
|
128
|
-
schema: this.controller.schema,
|
|
129
|
-
parser,
|
|
130
|
-
editorView: this.controller.mainEditorView,
|
|
131
|
-
}).content,
|
|
132
|
-
),
|
|
117
|
+
createSnippet({
|
|
118
|
+
controller: this.controller,
|
|
119
|
+
content,
|
|
120
|
+
title,
|
|
121
|
+
snippetListIds: this.node.attrs.assignedSnippetListsIds,
|
|
122
|
+
importedResources: this.node.attrs.importedResources,
|
|
123
|
+
}),
|
|
133
124
|
);
|
|
134
125
|
});
|
|
135
126
|
}
|
|
@@ -11,7 +11,7 @@ import { SnippetPluginConfig } from '@lblod/ember-rdfa-editor-lblod-plugins/plug
|
|
|
11
11
|
|
|
12
12
|
interface Args {
|
|
13
13
|
config: SnippetPluginConfig;
|
|
14
|
-
assignedSnippetListsIds: string[];
|
|
14
|
+
assignedSnippetListsIds: string[] | undefined;
|
|
15
15
|
closeModal: () => void;
|
|
16
16
|
open: boolean;
|
|
17
17
|
onInsert: (content: string, title: string) => void;
|
|
@@ -7,7 +7,10 @@ import not from 'ember-truth-helpers/helpers/not';
|
|
|
7
7
|
import AuButton from '@appuniversum/ember-appuniversum/components/au-button';
|
|
8
8
|
import { AddIcon } from '@appuniversum/ember-appuniversum/components/icons/add';
|
|
9
9
|
import { type NodeType, type SayController } from '@lblod/ember-rdfa-editor';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
type SnippetPluginConfig,
|
|
12
|
+
type SnippetList,
|
|
13
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
11
14
|
import { createSnippetPlaceholder } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin/nodes/snippet-placeholder';
|
|
12
15
|
import SnippetListModal from '@lblod/ember-rdfa-editor-lblod-plugins/components/snippet-plugin/snippet-list/snippet-list-modal';
|
|
13
16
|
|
|
@@ -35,19 +38,17 @@ export default class SnippetPluginSnippetInsertPlaceholder extends Component<Sig
|
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
@action
|
|
38
|
-
insertPlaceholder(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
listNames,
|
|
42
|
-
this.args.controller.schema,
|
|
43
|
-
);
|
|
41
|
+
insertPlaceholder(lists: SnippetList[] | undefined) {
|
|
42
|
+
if (lists) {
|
|
43
|
+
const node = createSnippetPlaceholder(lists, this.args.controller.schema);
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
this.args.controller.withTransaction(
|
|
46
|
+
(tr) => {
|
|
47
|
+
return tr.replaceSelectionWith(node);
|
|
48
|
+
},
|
|
49
|
+
{ view: this.args.controller.mainEditorView },
|
|
50
|
+
);
|
|
51
|
+
}
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
<template>
|
|
@@ -65,7 +66,7 @@ export default class SnippetPluginSnippetInsertPlaceholder extends Component<Sig
|
|
|
65
66
|
<SnippetListModal
|
|
66
67
|
@config={{@config}}
|
|
67
68
|
@assignedSnippetListsIds={{empty}}
|
|
68
|
-
@
|
|
69
|
+
@onSaveSnippetLists={{this.insertPlaceholder}}
|
|
69
70
|
@open={{this.isModalOpen}}
|
|
70
71
|
@closeModal={{this.closeModal}}
|
|
71
72
|
/>
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { isResourceNode } from '@lblod/ember-rdfa-editor/utils/node-utils';
|
|
2
|
+
import Component from '@glimmer/component';
|
|
3
|
+
|
|
4
|
+
import { SayController } from '@lblod/ember-rdfa-editor';
|
|
5
|
+
import {
|
|
6
|
+
type ImportedResourceMap,
|
|
7
|
+
type SnippetPluginConfig,
|
|
8
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
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';
|
|
14
|
+
import { ResolvedPNode } from '@lblod/ember-rdfa-editor/utils/_private/types';
|
|
15
|
+
import SnippetInsert from './snippet-insert';
|
|
16
|
+
|
|
17
|
+
interface Sig {
|
|
18
|
+
Args: {
|
|
19
|
+
controller: SayController;
|
|
20
|
+
config: SnippetPluginConfig;
|
|
21
|
+
node: ResolvedPNode;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default class SnippetInsertRdfaComponent extends Component<Sig> {
|
|
26
|
+
get disableInsert() {
|
|
27
|
+
return (this.snippetListProperties?.listIds.length ?? 0) === 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get snippetListProperties():
|
|
31
|
+
| { listIds: string[]; importedResources: ImportedResourceMap }
|
|
32
|
+
| undefined {
|
|
33
|
+
const activeNode = this.args.node.value;
|
|
34
|
+
const activeNodeSnippetListIds = getSnippetListIdsProperties(activeNode);
|
|
35
|
+
|
|
36
|
+
if (activeNodeSnippetListIds.length > 0) {
|
|
37
|
+
return {
|
|
38
|
+
listIds: getAssignedSnippetListsIdsFromProperties(
|
|
39
|
+
activeNodeSnippetListIds,
|
|
40
|
+
),
|
|
41
|
+
importedResources: activeNode.attrs.importedResources,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (this.args.node.pos < 0) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// If active node isn't a snippet list, go up until we find one
|
|
50
|
+
const doc = this.args.controller.mainEditorState.doc;
|
|
51
|
+
const pos = doc.resolve(this.args.node.pos);
|
|
52
|
+
let parentNode = findParentNodeClosestToPos(pos, (node) =>
|
|
53
|
+
isResourceNode(node),
|
|
54
|
+
);
|
|
55
|
+
while (parentNode) {
|
|
56
|
+
const properties = getSnippetListIdsProperties(parentNode.node);
|
|
57
|
+
|
|
58
|
+
if (properties.length > 0) {
|
|
59
|
+
return {
|
|
60
|
+
listIds: getAssignedSnippetListsIdsFromProperties(properties),
|
|
61
|
+
importedResources: parentNode.node.attrs.importedResources,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
parentNode = findParentNodeClosestToPos(
|
|
66
|
+
doc.resolve(parentNode.pos),
|
|
67
|
+
(node) => isResourceNode(node),
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
<template>
|
|
75
|
+
<SnippetInsert
|
|
76
|
+
@config={{@config}}
|
|
77
|
+
@controller={{@controller}}
|
|
78
|
+
@snippetListProperties={{this.snippetListProperties}}
|
|
79
|
+
@disabled={{this.disableInsert}}
|
|
80
|
+
/>
|
|
81
|
+
</template>
|
|
82
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { action } from '@ember/object';
|
|
2
|
+
import { on } from '@ember/modifier';
|
|
3
|
+
import Component from '@glimmer/component';
|
|
4
|
+
import { tracked } from '@glimmer/tracking';
|
|
5
|
+
import t from 'ember-intl/helpers/t';
|
|
6
|
+
import { AddIcon } from '@appuniversum/ember-appuniversum/components/icons/add';
|
|
7
|
+
import AuButton from '@appuniversum/ember-appuniversum/components/au-button';
|
|
8
|
+
import {
|
|
9
|
+
ProseParser,
|
|
10
|
+
SayController,
|
|
11
|
+
Slice,
|
|
12
|
+
Transaction,
|
|
13
|
+
} from '@lblod/ember-rdfa-editor';
|
|
14
|
+
import { SnippetPluginConfig } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
15
|
+
import { createSnippet } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin/nodes/snippet';
|
|
16
|
+
import { type ImportedResourceMap } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
17
|
+
import SearchModal from './search-modal';
|
|
18
|
+
|
|
19
|
+
interface Sig {
|
|
20
|
+
Args: {
|
|
21
|
+
controller: SayController;
|
|
22
|
+
config: SnippetPluginConfig;
|
|
23
|
+
snippetListProperties:
|
|
24
|
+
| { listIds: string[]; importedResources: ImportedResourceMap }
|
|
25
|
+
| undefined;
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default class SnippetInsertComponent extends Component<Sig> {
|
|
31
|
+
@tracked showModal = false;
|
|
32
|
+
|
|
33
|
+
get controller() {
|
|
34
|
+
return this.args.controller;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@action
|
|
38
|
+
openModal() {
|
|
39
|
+
this.controller.focus();
|
|
40
|
+
this.showModal = true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@action
|
|
44
|
+
closeModal() {
|
|
45
|
+
this.showModal = false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
createSliceFromElement(element: Element) {
|
|
49
|
+
return new Slice(
|
|
50
|
+
ProseParser.fromSchema(this.controller.schema).parse(element, {
|
|
51
|
+
preserveWhitespace: true,
|
|
52
|
+
}).content,
|
|
53
|
+
0,
|
|
54
|
+
0,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@action
|
|
59
|
+
onInsert(content: string, title: string) {
|
|
60
|
+
const domParser = new DOMParser();
|
|
61
|
+
const parsed = domParser.parseFromString(content, 'text/html').body;
|
|
62
|
+
const documentDiv = parsed.querySelector('div[data-say-document="true"]');
|
|
63
|
+
|
|
64
|
+
this.closeModal();
|
|
65
|
+
const assignedSnippetListProperties = this.args.snippetListProperties;
|
|
66
|
+
|
|
67
|
+
if (documentDiv && assignedSnippetListProperties) {
|
|
68
|
+
return this.controller.withTransaction((tr: Transaction) =>
|
|
69
|
+
tr.replaceSelectionWith(
|
|
70
|
+
createSnippet({
|
|
71
|
+
controller: this.controller,
|
|
72
|
+
content,
|
|
73
|
+
title,
|
|
74
|
+
snippetListIds: assignedSnippetListProperties.listIds,
|
|
75
|
+
importedResources: assignedSnippetListProperties.importedResources,
|
|
76
|
+
}),
|
|
77
|
+
),
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
this.controller.withTransaction((tr) =>
|
|
81
|
+
tr.replaceSelection(this.createSliceFromElement(parsed)),
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get disabled() {
|
|
86
|
+
return this.args.disabled ?? false;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
<template>
|
|
90
|
+
<li class='au-c-list__item'>
|
|
91
|
+
<AuButton
|
|
92
|
+
@icon={{AddIcon}}
|
|
93
|
+
@iconAlignment='left'
|
|
94
|
+
@skin='link'
|
|
95
|
+
@disabled={{this.disabled}}
|
|
96
|
+
{{on 'click' this.openModal}}
|
|
97
|
+
>
|
|
98
|
+
{{t 'snippet-plugin.insert.title'}}
|
|
99
|
+
</AuButton>
|
|
100
|
+
</li>
|
|
101
|
+
|
|
102
|
+
<SearchModal
|
|
103
|
+
@open={{this.showModal}}
|
|
104
|
+
@closeModal={{this.closeModal}}
|
|
105
|
+
@config={{@config}}
|
|
106
|
+
@onInsert={{this.onInsert}}
|
|
107
|
+
@assignedSnippetListsIds={{@snippetListProperties.listIds}}
|
|
108
|
+
/>
|
|
109
|
+
</template>
|
|
110
|
+
}
|
|
@@ -19,8 +19,8 @@ import { trackedReset } from 'tracked-toolbox';
|
|
|
19
19
|
interface Signature {
|
|
20
20
|
Args: {
|
|
21
21
|
config: SnippetPluginConfig;
|
|
22
|
-
|
|
23
|
-
assignedSnippetListsIds: string[];
|
|
22
|
+
onSaveSnippetLists: (lists: SnippetList[]) => void;
|
|
23
|
+
assignedSnippetListsIds: string[] | undefined;
|
|
24
24
|
closeModal: () => void;
|
|
25
25
|
open: boolean;
|
|
26
26
|
};
|
|
@@ -37,7 +37,9 @@ export default class SnippetListModalComponent extends Component<Signature> {
|
|
|
37
37
|
@tracked error: unknown;
|
|
38
38
|
|
|
39
39
|
@trackedReset('args.assignedSnippetListsIds')
|
|
40
|
-
assignedSnippetListsIds: string[] = [
|
|
40
|
+
assignedSnippetListsIds: string[] = [
|
|
41
|
+
...(this.args.assignedSnippetListsIds ?? []),
|
|
42
|
+
];
|
|
41
43
|
|
|
42
44
|
get config() {
|
|
43
45
|
return this.args.config;
|
|
@@ -50,15 +52,10 @@ export default class SnippetListModalComponent extends Component<Signature> {
|
|
|
50
52
|
|
|
51
53
|
@action
|
|
52
54
|
saveAndClose() {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
this.assignedSnippetListsIds.includes(snippetList.id as string),
|
|
56
|
-
)
|
|
57
|
-
.map((snippetList) => snippetList.label) as string[];
|
|
58
|
-
this.args.onSaveSnippetListIds(
|
|
59
|
-
this.assignedSnippetListsIds,
|
|
60
|
-
snippetListNames,
|
|
55
|
+
const snippetLists = this.snippetListResource.value?.filter((snippetList) =>
|
|
56
|
+
this.assignedSnippetListsIds.includes(snippetList.id),
|
|
61
57
|
);
|
|
58
|
+
this.args.onSaveSnippetLists(snippetLists || []);
|
|
62
59
|
this.args.closeModal();
|
|
63
60
|
// Clear selection for next time
|
|
64
61
|
this.assignedSnippetListsIds = [];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TemplateOnlyComponent } from '@ember/component/template-only';
|
|
2
|
+
import { SayController } from '@lblod/ember-rdfa-editor';
|
|
3
|
+
import { type ResolvedPNode } from '@lblod/ember-rdfa-editor/utils/_private/types';
|
|
4
|
+
import { type SnippetPluginConfig } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
5
|
+
import SnippetListSelect from '@lblod/ember-rdfa-editor-lblod-plugins/components/snippet-plugin/snippet-list-select';
|
|
6
|
+
|
|
7
|
+
interface Sig {
|
|
8
|
+
Args: {
|
|
9
|
+
controller: SayController;
|
|
10
|
+
config: SnippetPluginConfig;
|
|
11
|
+
node: ResolvedPNode;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** @deprecated Use snippet-list-select directly */
|
|
16
|
+
const SnippetListSelectRdfaComponent: TemplateOnlyComponent<Sig> = <template>
|
|
17
|
+
<SnippetListSelect
|
|
18
|
+
@controller={{@controller}}
|
|
19
|
+
@config={{@config}}
|
|
20
|
+
@node={{@node}}
|
|
21
|
+
/>
|
|
22
|
+
</template>;
|
|
23
|
+
|
|
24
|
+
/** @deprecated Use snippet-list-select directly */
|
|
25
|
+
export default SnippetListSelectRdfaComponent;
|
|
@@ -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
|
+
}
|
|
@@ -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;
|