@lblod/ember-rdfa-editor-lblod-plugins 22.4.1 → 22.5.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 +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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @lblod/ember-rdfa-editor-lblod-plugins
|
|
2
2
|
|
|
3
|
+
## 22.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#475](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/475) [`9e2ef89`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/9e2ef899e5e35ed755e4af90ca15096b3957222b) Thanks [@elpoelma](https://github.com/elpoelma)! - Introduction of `auto-resizing-text-area` component
|
|
8
|
+
|
|
9
|
+
- [#475](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/475) [`a9df4e7`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/a9df4e7546a1414e2fe8551a8ca21fd5b9f64898) Thanks [@elpoelma](https://github.com/elpoelma)! - mandatee-table plugin: replace `input` element by `textarea` element for entering mandatee table titles
|
|
10
|
+
|
|
11
|
+
- [#462](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/462) [`dfb349e`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/dfb349ef83c97eac2c498eaac392dbfd6ab77a4b) Thanks [@piemonkey](https://github.com/piemonkey)! - Allow resources imported into snippet placeholders to be linked to resources in the document
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#475](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/475) [`36b0005`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/36b00054624de60a1c51f7617a83c61594f4074b) Thanks [@elpoelma](https://github.com/elpoelma)! - Support newlines in mandatee table titles (using the `white-space: pre-line` rule)
|
|
16
|
+
|
|
17
|
+
- [#475](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/475) [`127c6e2`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/127c6e256d7fb3a0e1912bfc0a56a2f4d08d1837) Thanks [@elpoelma](https://github.com/elpoelma)! - Use `h6` to represent mandatee table title
|
|
18
|
+
|
|
19
|
+
- [#473](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/473) [`1c9dd11`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/1c9dd1119670ee35f04f8a0d0677e6a4230acd84) Thanks [@piemonkey](https://github.com/piemonkey)! - Add error handling to lmb-plugin
|
|
20
|
+
|
|
3
21
|
## 22.4.1
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { action } from '@ember/object';
|
|
3
|
+
import AuTextarea, {
|
|
4
|
+
AuTextareaSignature,
|
|
5
|
+
} from '@appuniversum/ember-appuniversum/components/au-textarea';
|
|
6
|
+
import { modifier } from 'ember-modifier';
|
|
7
|
+
|
|
8
|
+
interface Sig {
|
|
9
|
+
Args: { maxHeight?: number } & AuTextareaSignature['Args'];
|
|
10
|
+
Blocks: {
|
|
11
|
+
default: [];
|
|
12
|
+
};
|
|
13
|
+
Element: HTMLTextAreaElement;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default class AutoResizingTextArea extends Component<Sig> {
|
|
17
|
+
setupAutoResize = modifier((element: HTMLTextAreaElement) => {
|
|
18
|
+
const resize = () => {
|
|
19
|
+
element.style.setProperty('height', '');
|
|
20
|
+
const height = this.args.maxHeight
|
|
21
|
+
? Math.min(element.scrollHeight, this.args.maxHeight)
|
|
22
|
+
: element.scrollHeight;
|
|
23
|
+
element.style.setProperty('height', `${height}px`);
|
|
24
|
+
};
|
|
25
|
+
element.addEventListener('input', resize);
|
|
26
|
+
resize();
|
|
27
|
+
return () => element.removeEventListener('input', resize);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
@action
|
|
31
|
+
onInput() {}
|
|
32
|
+
|
|
33
|
+
<template>
|
|
34
|
+
<AuTextarea
|
|
35
|
+
{{this.setupAutoResize}}
|
|
36
|
+
@width={{@width}}
|
|
37
|
+
@disabled={{@disabled}}
|
|
38
|
+
@error={{@error}}
|
|
39
|
+
@warning={{@warning}}
|
|
40
|
+
...attributes
|
|
41
|
+
>{{yield}}</AuTextarea>
|
|
42
|
+
</template>
|
|
43
|
+
}
|
|
@@ -36,13 +36,16 @@
|
|
|
36
36
|
</mc.sidebar>
|
|
37
37
|
<mc.content @scroll={{true}}>
|
|
38
38
|
<div class='worship-modal--list-container'>
|
|
39
|
-
|
|
40
|
-
@error={{this.error}}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
{{#if this.error}}
|
|
40
|
+
<Common::Search::AlertLoadError @error={{this.error}} />
|
|
41
|
+
{{else}}
|
|
42
|
+
<LmbPlugin::List
|
|
43
|
+
@services={{this.servicesResource}}
|
|
44
|
+
@sort={{this.sort}}
|
|
45
|
+
@setSort={{this.setSort}}
|
|
46
|
+
@insert={{@onInsert}}
|
|
47
|
+
/>
|
|
48
|
+
{{/if}}
|
|
46
49
|
</div>
|
|
47
50
|
{{#if this.servicesResource.value.totalCount}}
|
|
48
51
|
{{#let
|
|
@@ -42,10 +42,17 @@ export default class LmbPluginSearchModalComponent extends Component<Args> {
|
|
|
42
42
|
return fetchMandatees({ endpoint: this.args.config.endpoint });
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
+
// TODO Either make this a trackedFunction or do filtering on the query and correctly pass an
|
|
46
|
+
// AbortController
|
|
45
47
|
search = restartableTask(async () => {
|
|
46
48
|
// Can't do what I want, so if the user modifies the filter before resolving the query will run again
|
|
47
49
|
if (!this.fetchData.lastComplete) {
|
|
48
|
-
|
|
50
|
+
try {
|
|
51
|
+
await this.fetchData.perform();
|
|
52
|
+
} catch (err) {
|
|
53
|
+
console.error('Got an error fetching LMB data', err);
|
|
54
|
+
this.error = err;
|
|
55
|
+
}
|
|
49
56
|
}
|
|
50
57
|
|
|
51
58
|
if (!this.fetchData.lastComplete?.value) return;
|
|
@@ -4,12 +4,12 @@ import { action } from '@ember/object';
|
|
|
4
4
|
import AuCard from '@appuniversum/ember-appuniversum/components/au-card';
|
|
5
5
|
import AuHeading from '@appuniversum/ember-appuniversum/components/au-heading';
|
|
6
6
|
import AuLabel from '@appuniversum/ember-appuniversum/components/au-label';
|
|
7
|
-
import AuInput from '@appuniversum/ember-appuniversum/components/au-input';
|
|
8
7
|
import PowerSelect from 'ember-power-select/components/power-select';
|
|
9
8
|
import { findParentNodeOfType } from '@curvenote/prosemirror-utils';
|
|
10
9
|
import { on } from '@ember/modifier';
|
|
11
10
|
import AuFormRow from '@appuniversum/ember-appuniversum/components/au-form-row';
|
|
12
11
|
import t from 'ember-intl/helpers/t';
|
|
12
|
+
import AutoResizingTextArea from '../auto-resizing-text-area';
|
|
13
13
|
|
|
14
14
|
interface Sig {
|
|
15
15
|
Args: { controller: SayController; supportedTags: string[] };
|
|
@@ -105,15 +105,15 @@ export default class ConfigureMandateeTableComponent extends Component<Sig> {
|
|
|
105
105
|
<AuLabel for='mandatee-table-title-input'>
|
|
106
106
|
{{t 'mandatee-table-plugin.configure.title-input.label'}}
|
|
107
107
|
</AuLabel>
|
|
108
|
-
<
|
|
108
|
+
<AutoResizingTextArea
|
|
109
109
|
@width='block'
|
|
110
110
|
placeholder={{t
|
|
111
111
|
'mandatee-table-plugin.configure.title-input.placeholder'
|
|
112
112
|
}}
|
|
113
113
|
id='mandatee-table-title-input'
|
|
114
|
-
|
|
114
|
+
class='mandatee-table-title-input'
|
|
115
115
|
{{on 'input' this.updateNodeTitle}}
|
|
116
|
-
|
|
116
|
+
>{{this.nodeTitle}}</AutoResizingTextArea>
|
|
117
117
|
</AuFormRow>
|
|
118
118
|
</c.content>
|
|
119
119
|
</AuCard>
|
|
@@ -44,7 +44,7 @@ export default class MandateeTableNode extends Component<Sig> {
|
|
|
44
44
|
class='au-u-margin-left-tiny au-u-margin-right-tiny'
|
|
45
45
|
/>
|
|
46
46
|
<div>
|
|
47
|
-
<
|
|
47
|
+
<h6 class='say-mandatee-table__title'>{{this.title}}</h6>
|
|
48
48
|
<p>
|
|
49
49
|
{{this.warning}}
|
|
50
50
|
</p>
|
|
@@ -1,29 +1,27 @@
|
|
|
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
|
-
PNode,
|
|
13
|
+
type PNode,
|
|
13
14
|
ProseParser,
|
|
14
|
-
Selection,
|
|
15
|
+
type Selection,
|
|
15
16
|
Slice,
|
|
16
|
-
Transaction,
|
|
17
17
|
} from '@lblod/ember-rdfa-editor';
|
|
18
|
-
import {
|
|
18
|
+
import { findAncestors } from '@lblod/ember-rdfa-editor/utils/position-utils';
|
|
19
19
|
import {
|
|
20
20
|
EXT,
|
|
21
21
|
RDF,
|
|
22
22
|
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
|
|
23
|
-
import { findAncestors } from '@lblod/ember-rdfa-editor/utils/position-utils';
|
|
24
23
|
import { hasOutgoingNamedNodeTriple } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/namespace';
|
|
25
|
-
import {
|
|
26
|
-
import t from 'ember-intl/helpers/t';
|
|
24
|
+
import { createAndInsertSnippet } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin/nodes/snippet';
|
|
27
25
|
|
|
28
26
|
interface Signature {
|
|
29
27
|
Args: EmberNodeArgs;
|
|
@@ -91,7 +89,6 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
91
89
|
}
|
|
92
90
|
@action
|
|
93
91
|
onInsert(content: string, title: string) {
|
|
94
|
-
const assignedSnippetListsIds = this.node.attrs.assignedSnippetListsIds;
|
|
95
92
|
let rangeStart = 0;
|
|
96
93
|
let rangeEnd = 0;
|
|
97
94
|
if (this.args.getPos() === undefined) return;
|
|
@@ -110,28 +107,18 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
110
107
|
const documentDiv = parsed.querySelector('div[data-say-document="true"]');
|
|
111
108
|
|
|
112
109
|
this.closeModal();
|
|
113
|
-
const parser = ProseParser.fromSchema(this.controller.schema);
|
|
114
110
|
|
|
115
111
|
if (documentDiv) {
|
|
116
|
-
return
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
),
|
|
133
|
-
);
|
|
134
|
-
});
|
|
112
|
+
return createAndInsertSnippet(
|
|
113
|
+
{
|
|
114
|
+
controller: this.controller,
|
|
115
|
+
content,
|
|
116
|
+
title,
|
|
117
|
+
snippetListIds: this.node.attrs.assignedSnippetListsIds,
|
|
118
|
+
importedResources: this.node.attrs.importedResources,
|
|
119
|
+
},
|
|
120
|
+
(tr, snippet) => tr.replaceRangeWith(rangeStart, rangeEnd, snippet),
|
|
121
|
+
);
|
|
135
122
|
}
|
|
136
123
|
|
|
137
124
|
this.controller.withTransaction((tr) =>
|
|
@@ -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,109 @@
|
|
|
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
|
+
type SayController,
|
|
11
|
+
Slice,
|
|
12
|
+
} from '@lblod/ember-rdfa-editor';
|
|
13
|
+
import { SnippetPluginConfig } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
14
|
+
import { createAndInsertSnippet } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin/nodes/snippet';
|
|
15
|
+
import { type ImportedResourceMap } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
16
|
+
import SearchModal from './search-modal';
|
|
17
|
+
|
|
18
|
+
interface Sig {
|
|
19
|
+
Args: {
|
|
20
|
+
controller: SayController;
|
|
21
|
+
config: SnippetPluginConfig;
|
|
22
|
+
snippetListProperties:
|
|
23
|
+
| { listIds: string[]; importedResources: ImportedResourceMap }
|
|
24
|
+
| undefined;
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default class SnippetInsertComponent extends Component<Sig> {
|
|
30
|
+
@tracked showModal = false;
|
|
31
|
+
|
|
32
|
+
get controller() {
|
|
33
|
+
return this.args.controller;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@action
|
|
37
|
+
openModal() {
|
|
38
|
+
this.controller.focus();
|
|
39
|
+
this.showModal = true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@action
|
|
43
|
+
closeModal() {
|
|
44
|
+
this.showModal = false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
createSliceFromElement(element: Element) {
|
|
48
|
+
return new Slice(
|
|
49
|
+
ProseParser.fromSchema(this.controller.schema).parse(element, {
|
|
50
|
+
preserveWhitespace: true,
|
|
51
|
+
}).content,
|
|
52
|
+
0,
|
|
53
|
+
0,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@action
|
|
58
|
+
onInsert(content: string, title: string) {
|
|
59
|
+
const domParser = new DOMParser();
|
|
60
|
+
const parsed = domParser.parseFromString(content, 'text/html').body;
|
|
61
|
+
const documentDiv = parsed.querySelector('div[data-say-document="true"]');
|
|
62
|
+
|
|
63
|
+
this.closeModal();
|
|
64
|
+
const assignedSnippetListProperties = this.args.snippetListProperties;
|
|
65
|
+
|
|
66
|
+
if (documentDiv && assignedSnippetListProperties) {
|
|
67
|
+
return createAndInsertSnippet(
|
|
68
|
+
{
|
|
69
|
+
controller: this.controller,
|
|
70
|
+
content,
|
|
71
|
+
title,
|
|
72
|
+
snippetListIds: assignedSnippetListProperties.listIds,
|
|
73
|
+
importedResources: assignedSnippetListProperties.importedResources,
|
|
74
|
+
},
|
|
75
|
+
(tr, snippet) => tr.replaceSelectionWith(snippet),
|
|
76
|
+
);
|
|
77
|
+
} else {
|
|
78
|
+
return this.controller.withTransaction((tr) =>
|
|
79
|
+
tr.replaceSelection(this.createSliceFromElement(parsed)),
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
get disabled() {
|
|
85
|
+
return this.args.disabled ?? false;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
<template>
|
|
89
|
+
<li class='au-c-list__item'>
|
|
90
|
+
<AuButton
|
|
91
|
+
@icon={{AddIcon}}
|
|
92
|
+
@iconAlignment='left'
|
|
93
|
+
@skin='link'
|
|
94
|
+
@disabled={{this.disabled}}
|
|
95
|
+
{{on 'click' this.openModal}}
|
|
96
|
+
>
|
|
97
|
+
{{t 'snippet-plugin.insert.title'}}
|
|
98
|
+
</AuButton>
|
|
99
|
+
</li>
|
|
100
|
+
|
|
101
|
+
<SearchModal
|
|
102
|
+
@open={{this.showModal}}
|
|
103
|
+
@closeModal={{this.closeModal}}
|
|
104
|
+
@config={{@config}}
|
|
105
|
+
@onInsert={{this.onInsert}}
|
|
106
|
+
@assignedSnippetListsIds={{@snippetListProperties.listIds}}
|
|
107
|
+
/>
|
|
108
|
+
</template>
|
|
109
|
+
}
|
|
@@ -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 = [];
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
(t 'snippet-plugin.snippet-list.modal.table.select')
|
|
7
7
|
(t 'snippet-plugin.snippet-list.modal.subtitle')
|
|
8
8
|
(t 'snippet-plugin.snippet-list.modal.search.label')
|
|
9
|
-
|
|
9
|
+
(t 'snippet-plugin.snippet-list.modal.table.imported-resources')
|
|
10
|
+
as |list created select subtitle search imported|
|
|
10
11
|
}}
|
|
11
12
|
<AuDataTable
|
|
12
13
|
@content={{this.snippetLists}}
|
|
@@ -39,6 +40,7 @@
|
|
|
39
40
|
@currentSorting={{@sort}}
|
|
40
41
|
@class='data-table__header-title'
|
|
41
42
|
/>
|
|
43
|
+
<th>{{imported}}</th>
|
|
42
44
|
<AuDataTableThSortable
|
|
43
45
|
@field='createdOn'
|
|
44
46
|
@label={{created}}
|
|
@@ -55,6 +57,7 @@
|
|
|
55
57
|
/>
|
|
56
58
|
</td>
|
|
57
59
|
<td>{{row.label}}</td>
|
|
60
|
+
<td>{{row.importedResources}}</td>
|
|
58
61
|
<td class='snippet-list-table-created-column'>{{row.createdOn}}</td>
|
|
59
62
|
</c.body>
|
|
60
63
|
</t.content>
|
|
@@ -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;
|