@lblod/ember-rdfa-editor-lblod-plugins 22.4.1-dev.d49cf94f066e6920d2facf8a3cb5bbd97329a230 → 22.4.1-dev.e1219ca84efa2a05c61baa4649da5dfc38de256a
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/late-onions-glow.md +5 -0
- package/addon/components/snippet-plugin/nodes/snippet.gts +27 -54
- package/addon/components/snippet-plugin/snippet-insert.ts +8 -36
- package/addon/plugins/snippet-plugin/commands/insert-snippet.ts +74 -0
- package/addon/plugins/snippet-plugin/index.ts +0 -3
- package/addon/plugins/snippet-plugin/nodes/snippet.ts +2 -5
- package/declarations/addon/plugins/snippet-plugin/commands/insert-snippet.d.ts +12 -0
- package/declarations/addon/plugins/snippet-plugin/index.d.ts +0 -1
- package/package.json +3 -3
- package/pnpm-lock.yaml +6 -5
- package/.changeset/bright-berries-impress.md +0 -5
|
@@ -8,22 +8,18 @@ import { action } from '@ember/object';
|
|
|
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 {
|
|
12
|
-
PNode,
|
|
13
|
-
ProseParser,
|
|
14
|
-
Selection,
|
|
15
|
-
Slice,
|
|
16
|
-
Transaction,
|
|
17
|
-
} from '@lblod/ember-rdfa-editor';
|
|
18
|
-
import { htmlToDoc } from '@lblod/ember-rdfa-editor/utils/_private/html-utils';
|
|
11
|
+
import { PNode, ProseParser, Selection, Slice } from '@lblod/ember-rdfa-editor';
|
|
19
12
|
import {
|
|
20
13
|
EXT,
|
|
21
14
|
RDF,
|
|
22
15
|
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
|
|
23
16
|
import { findAncestors } from '@lblod/ember-rdfa-editor/utils/position-utils';
|
|
24
17
|
import { hasOutgoingNamedNodeTriple } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/namespace';
|
|
25
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
26
18
|
import t from 'ember-intl/helpers/t';
|
|
19
|
+
import insertSnippet from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin/commands/insert-snippet';
|
|
20
|
+
import { isNone } from '@lblod/ember-rdfa-editor/utils/_private/option';
|
|
21
|
+
import { transactionCombinator } from '@lblod/ember-rdfa-editor/utils/transaction-utils';
|
|
22
|
+
import { recalculateNumbers } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/structure-plugin/recalculate-structure-numbers';
|
|
27
23
|
|
|
28
24
|
interface Signature {
|
|
29
25
|
Args: EmberNodeArgs;
|
|
@@ -63,7 +59,10 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
63
59
|
const position = this.args.getPos();
|
|
64
60
|
if (position !== undefined) {
|
|
65
61
|
this.controller.withTransaction((tr) => {
|
|
66
|
-
return
|
|
62
|
+
return transactionCombinator(
|
|
63
|
+
this.controller.mainEditorState,
|
|
64
|
+
tr.deleteRange(position, position + this.node.nodeSize),
|
|
65
|
+
)([recalculateNumbers]).transaction;
|
|
67
66
|
});
|
|
68
67
|
}
|
|
69
68
|
}
|
|
@@ -91,57 +90,31 @@ export default class SnippetNode extends Component<Signature> {
|
|
|
91
90
|
}
|
|
92
91
|
@action
|
|
93
92
|
onInsert(content: string, title: string) {
|
|
93
|
+
this.closeModal();
|
|
94
94
|
const assignedSnippetListsIds = this.node.attrs.assignedSnippetListsIds;
|
|
95
|
-
let
|
|
96
|
-
let
|
|
97
|
-
|
|
95
|
+
let start = 0;
|
|
96
|
+
let end = 0;
|
|
97
|
+
const pos = this.args.getPos();
|
|
98
|
+
if (isNone(pos)) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
98
101
|
if (this.mode === 'add') {
|
|
99
102
|
// Add new snippet
|
|
100
|
-
|
|
101
|
-
|
|
103
|
+
start = pos + this.node.nodeSize;
|
|
104
|
+
end = pos + this.node.nodeSize;
|
|
102
105
|
} else {
|
|
103
106
|
//Replace current snippet
|
|
104
|
-
|
|
105
|
-
|
|
107
|
+
start = pos;
|
|
108
|
+
end = pos + this.node.nodeSize;
|
|
106
109
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (documentDiv) {
|
|
116
|
-
return this.controller.withTransaction((tr: Transaction) => {
|
|
117
|
-
return tr.replaceRangeWith(
|
|
118
|
-
rangeStart,
|
|
119
|
-
rangeEnd,
|
|
120
|
-
this.controller.schema.node(
|
|
121
|
-
'snippet',
|
|
122
|
-
{
|
|
123
|
-
assignedSnippetListsIds,
|
|
124
|
-
title,
|
|
125
|
-
subject: `http://data.lblod.info/snippets/${uuidv4()}`,
|
|
126
|
-
},
|
|
127
|
-
htmlToDoc(content, {
|
|
128
|
-
schema: this.controller.schema,
|
|
129
|
-
parser,
|
|
130
|
-
editorView: this.controller.mainEditorView,
|
|
131
|
-
}).content,
|
|
132
|
-
),
|
|
133
|
-
);
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
this.controller.withTransaction((tr) =>
|
|
138
|
-
tr.replaceRange(
|
|
139
|
-
rangeStart,
|
|
140
|
-
rangeEnd,
|
|
141
|
-
this.createSliceFromElement(parsed),
|
|
142
|
-
),
|
|
110
|
+
this.controller.doCommand(
|
|
111
|
+
insertSnippet({
|
|
112
|
+
content,
|
|
113
|
+
title,
|
|
114
|
+
assignedSnippetListsIds,
|
|
115
|
+
range: { start, end },
|
|
116
|
+
}),
|
|
143
117
|
);
|
|
144
|
-
this.closeModal();
|
|
145
118
|
}
|
|
146
119
|
<template>
|
|
147
120
|
<div class='say-snippet-card'>
|
|
@@ -4,15 +4,9 @@ import { AddIcon } from '@appuniversum/ember-appuniversum/components/icons/add';
|
|
|
4
4
|
import Component from '@glimmer/component';
|
|
5
5
|
import { tracked } from '@glimmer/tracking';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
ProseParser,
|
|
10
|
-
SayController,
|
|
11
|
-
Slice,
|
|
12
|
-
Transaction,
|
|
13
|
-
} from '@lblod/ember-rdfa-editor';
|
|
7
|
+
import { ProseParser, SayController, Slice } from '@lblod/ember-rdfa-editor';
|
|
14
8
|
import { SnippetPluginConfig } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
15
|
-
import
|
|
9
|
+
import insertSnippet from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin/commands/insert-snippet';
|
|
16
10
|
|
|
17
11
|
interface Args {
|
|
18
12
|
controller: SayController;
|
|
@@ -57,35 +51,13 @@ export default class SnippetInsertComponent extends Component<Args> {
|
|
|
57
51
|
|
|
58
52
|
@action
|
|
59
53
|
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
54
|
this.closeModal();
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
'snippet',
|
|
72
|
-
{
|
|
73
|
-
assignedSnippetListsIds: this.args.assignedSnippetListsIds,
|
|
74
|
-
title: title,
|
|
75
|
-
subject: `http://data.lblod.info/snippets/${uuidv4()}`,
|
|
76
|
-
},
|
|
77
|
-
htmlToDoc(content, {
|
|
78
|
-
schema: this.controller.schema,
|
|
79
|
-
parser,
|
|
80
|
-
editorView: this.controller.mainEditorView,
|
|
81
|
-
}).content,
|
|
82
|
-
),
|
|
83
|
-
);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
this.controller.withTransaction((tr) =>
|
|
88
|
-
tr.replaceSelection(this.createSliceFromElement(parsed)),
|
|
55
|
+
this.controller.doCommand(
|
|
56
|
+
insertSnippet({
|
|
57
|
+
content,
|
|
58
|
+
title,
|
|
59
|
+
assignedSnippetListsIds: this.args.assignedSnippetListsIds,
|
|
60
|
+
}),
|
|
89
61
|
);
|
|
90
62
|
}
|
|
91
63
|
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Command, ProseParser, Schema, Slice } from '@lblod/ember-rdfa-editor';
|
|
2
|
+
import { htmlToDoc } from '@lblod/ember-rdfa-editor/utils/_private/html-utils';
|
|
3
|
+
import { transactionCombinator } from '@lblod/ember-rdfa-editor/utils/transaction-utils';
|
|
4
|
+
import { recalculateNumbers } from '../../structure-plugin/recalculate-structure-numbers';
|
|
5
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
6
|
+
export interface InsertSnippetCommandArgs {
|
|
7
|
+
content: string;
|
|
8
|
+
title: string;
|
|
9
|
+
assignedSnippetListsIds: string[];
|
|
10
|
+
range?: { start: number; end: number };
|
|
11
|
+
}
|
|
12
|
+
const insertSnippet = ({
|
|
13
|
+
content,
|
|
14
|
+
title,
|
|
15
|
+
assignedSnippetListsIds,
|
|
16
|
+
range,
|
|
17
|
+
}: InsertSnippetCommandArgs): Command => {
|
|
18
|
+
return (state, dispatch) => {
|
|
19
|
+
const domParser = new DOMParser();
|
|
20
|
+
const parsed = domParser.parseFromString(content, 'text/html').body;
|
|
21
|
+
const documentDiv = parsed.querySelector('div[data-say-document="true"]');
|
|
22
|
+
|
|
23
|
+
const schema = state.schema;
|
|
24
|
+
|
|
25
|
+
const parser = ProseParser.fromSchema(schema);
|
|
26
|
+
|
|
27
|
+
let tr = state.tr;
|
|
28
|
+
const insertRange = range ?? {
|
|
29
|
+
start: state.selection.from,
|
|
30
|
+
end: state.selection.to,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
if (documentDiv) {
|
|
34
|
+
const node = schema.node(
|
|
35
|
+
'snippet',
|
|
36
|
+
{
|
|
37
|
+
assignedSnippetListsIds,
|
|
38
|
+
title: title,
|
|
39
|
+
subject: `http://data.lblod.info/snippets/${uuidv4()}`,
|
|
40
|
+
},
|
|
41
|
+
htmlToDoc(content, {
|
|
42
|
+
schema,
|
|
43
|
+
parser,
|
|
44
|
+
}).content,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
tr = transactionCombinator(
|
|
48
|
+
state,
|
|
49
|
+
tr.replaceRangeWith(insertRange.start, insertRange.end, node),
|
|
50
|
+
)([recalculateNumbers]).transaction;
|
|
51
|
+
} else {
|
|
52
|
+
const slice = createSliceFromElement(parsed, schema);
|
|
53
|
+
tr = transactionCombinator(
|
|
54
|
+
state,
|
|
55
|
+
tr.replaceRange(insertRange.start, insertRange.end, slice),
|
|
56
|
+
)([recalculateNumbers]).transaction;
|
|
57
|
+
}
|
|
58
|
+
if (dispatch) {
|
|
59
|
+
dispatch(tr);
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
function createSliceFromElement(element: Element, schema: Schema) {
|
|
66
|
+
return new Slice(
|
|
67
|
+
ProseParser.fromSchema(schema).parse(element, {
|
|
68
|
+
preserveWhitespace: true,
|
|
69
|
+
}).content,
|
|
70
|
+
0,
|
|
71
|
+
0,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
export default insertSnippet;
|
|
@@ -4,9 +4,6 @@ import { optionMapOr } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/option
|
|
|
4
4
|
import { dateValue } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/strings';
|
|
5
5
|
import { SafeString } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/types';
|
|
6
6
|
|
|
7
|
-
export const SNIPPET_CONTENT_STRING =
|
|
8
|
-
'document_title? ((block|chapter)+|(block|title)+|(block|article)+)';
|
|
9
|
-
|
|
10
7
|
export type SnippetPluginConfig = {
|
|
11
8
|
endpoint: string;
|
|
12
9
|
};
|
|
@@ -15,10 +15,7 @@ import {
|
|
|
15
15
|
RDF,
|
|
16
16
|
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
|
|
17
17
|
import { hasOutgoingNamedNodeTriple } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/namespace';
|
|
18
|
-
import {
|
|
19
|
-
SNIPPET_CONTENT_STRING,
|
|
20
|
-
SnippetPluginConfig,
|
|
21
|
-
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
18
|
+
import { SnippetPluginConfig } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/snippet-plugin';
|
|
22
19
|
|
|
23
20
|
const emberNodeConfig = (options: SnippetPluginConfig): EmberNodeConfig => ({
|
|
24
21
|
name: 'snippet',
|
|
@@ -44,7 +41,7 @@ const emberNodeConfig = (options: SnippetPluginConfig): EmberNodeConfig => ({
|
|
|
44
41
|
config: { default: options },
|
|
45
42
|
},
|
|
46
43
|
component: SnippetComponent,
|
|
47
|
-
content:
|
|
44
|
+
content: 'block+',
|
|
48
45
|
serialize(node) {
|
|
49
46
|
return renderRdfaAware({
|
|
50
47
|
renderable: node,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Command } from '@lblod/ember-rdfa-editor';
|
|
2
|
+
export interface InsertSnippetCommandArgs {
|
|
3
|
+
content: string;
|
|
4
|
+
title: string;
|
|
5
|
+
assignedSnippetListsIds: string[];
|
|
6
|
+
range?: {
|
|
7
|
+
start: number;
|
|
8
|
+
end: number;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
declare const insertSnippet: ({ content, title, assignedSnippetListsIds, range, }: InsertSnippetCommandArgs) => Command;
|
|
12
|
+
export default insertSnippet;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lblod/ember-rdfa-editor-lblod-plugins",
|
|
3
|
-
"version": "22.4.1-dev.
|
|
3
|
+
"version": "22.4.1-dev.e1219ca84efa2a05c61baa4649da5dfc38de256a",
|
|
4
4
|
"description": "Ember addon providing lblod specific plugins for the ember-rdfa-editor",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon",
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"@glint/template": "^1.4.0",
|
|
103
103
|
"@graphy/content.ttl.write": "^4.3.7",
|
|
104
104
|
"@graphy/memory.dataset.fast": "4.3.3",
|
|
105
|
-
"@lblod/ember-rdfa-editor": "10.0
|
|
105
|
+
"@lblod/ember-rdfa-editor": "10.3.0",
|
|
106
106
|
"@rdfjs/types": "^1.1.0",
|
|
107
107
|
"@release-it/keep-a-changelog": "^4.0.0",
|
|
108
108
|
"@tsconfig/ember": "^3.0.8",
|
|
@@ -189,7 +189,7 @@
|
|
|
189
189
|
"@appuniversum/ember-appuniversum": "^3.4.1",
|
|
190
190
|
"@ember/string": "3.x",
|
|
191
191
|
"@glint/template": "^1.4.0",
|
|
192
|
-
"@lblod/ember-rdfa-editor": "^10.
|
|
192
|
+
"@lblod/ember-rdfa-editor": "^10.3.0",
|
|
193
193
|
"ember-concurrency": "^3.1.0",
|
|
194
194
|
"ember-element-helper": "^0.8.6",
|
|
195
195
|
"ember-intl": "^7.0.0",
|
package/pnpm-lock.yaml
CHANGED
|
@@ -160,8 +160,8 @@ importers:
|
|
|
160
160
|
specifier: 4.3.3
|
|
161
161
|
version: 4.3.3
|
|
162
162
|
'@lblod/ember-rdfa-editor':
|
|
163
|
-
specifier: 10.0
|
|
164
|
-
version: 10.0
|
|
163
|
+
specifier: 10.3.0
|
|
164
|
+
version: 10.3.0(2ef3gpurqxbttnmniw6grhzpuy)
|
|
165
165
|
'@rdfjs/types':
|
|
166
166
|
specifier: ^1.1.0
|
|
167
167
|
version: 1.1.0
|
|
@@ -1586,8 +1586,8 @@ packages:
|
|
|
1586
1586
|
'@jridgewell/trace-mapping@0.3.25':
|
|
1587
1587
|
resolution: {integrity: sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==}
|
|
1588
1588
|
|
|
1589
|
-
'@lblod/ember-rdfa-editor@10.0
|
|
1590
|
-
resolution: {integrity: sha512-
|
|
1589
|
+
'@lblod/ember-rdfa-editor@10.3.0':
|
|
1590
|
+
resolution: {integrity: sha512-ip8e7q5inZyz6MQXBmx9MyzHRVrLkyHlntVrBmMx0z11RKfijCA+8G+LTTLo95udR/L5VNFVF+CPgkE3FEmwNA==}
|
|
1591
1591
|
engines: {node: 16.* || 18.* || >= 20}
|
|
1592
1592
|
peerDependencies:
|
|
1593
1593
|
'@appuniversum/ember-appuniversum': ^3.4.2
|
|
@@ -10718,7 +10718,7 @@ snapshots:
|
|
|
10718
10718
|
'@jridgewell/resolve-uri': 3.1.2
|
|
10719
10719
|
'@jridgewell/sourcemap-codec': 1.4.15
|
|
10720
10720
|
|
|
10721
|
-
'@lblod/ember-rdfa-editor@10.0
|
|
10721
|
+
'@lblod/ember-rdfa-editor@10.3.0(2ef3gpurqxbttnmniw6grhzpuy)':
|
|
10722
10722
|
dependencies:
|
|
10723
10723
|
'@appuniversum/ember-appuniversum': 3.4.2(yenc6o4wruytt4u2jbwlbsqcl4)
|
|
10724
10724
|
'@babel/core': 7.24.7
|
|
@@ -10778,6 +10778,7 @@ snapshots:
|
|
|
10778
10778
|
tracked-built-ins: 3.3.0
|
|
10779
10779
|
tracked-toolbox: 2.0.0(@babel/core@7.24.7)(ember-source@4.12.0(@babel/core@7.24.7)(@glimmer/component@1.1.2(@babel/core@7.24.7))(@glint/template@1.4.0)(webpack@5.92.1))
|
|
10780
10780
|
uuid: 9.0.1
|
|
10781
|
+
vm-browserify: 1.1.2
|
|
10781
10782
|
yup: 1.4.0
|
|
10782
10783
|
optionalDependencies:
|
|
10783
10784
|
'@floating-ui/dom': 1.6.7
|