@lblod/ember-rdfa-editor-lblod-plugins 1.0.0-alpha.3 → 1.0.0-beta.2
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 +48 -0
- package/addon/components/article-structure-plugin/article-structure-card.hbs +3 -1
- package/addon/components/au-dropdown-pill.hbs +32 -0
- package/addon/components/au-dropdown-pill.ts +65 -0
- package/addon/components/besluit-type-plugin/toolbar-dropdown.ts +19 -12
- package/addon/components/citation-plugin/citation-card.hbs +2 -2
- package/addon/components/citation-plugin/citation-card.ts +1 -1
- package/addon/components/citation-plugin/citation-insert.hbs +3 -1
- package/addon/components/citation-plugin/citation-insert.ts +28 -2
- package/addon/components/citation-plugin/citations/search-modal.hbs +1 -1
- package/addon/components/citation-plugin/citations/search-modal.ts +3 -18
- package/addon/components/import-snippet-plugin/card.ts +8 -12
- package/addon/components/rdfa-date-plugin/card.hbs +28 -0
- package/addon/components/rdfa-date-plugin/card.ts +72 -38
- package/addon/components/rdfa-date-plugin/date-time-picker.ts +1 -0
- package/addon/components/rdfa-date-plugin/insert.hbs +2 -2
- package/addon/components/rdfa-date-plugin/insert.ts +14 -23
- package/addon/components/roadsign-regulation-plugin/roadsign-regulation-card.ts +24 -25
- package/addon/components/roadsign-regulation-plugin/roadsigns-modal.ts +37 -18
- package/addon/components/standard-template-plugin/template-provider.ts +54 -11
- package/addon/components/table-of-contents-plugin/ember-nodes/table-of-contents.ts +27 -30
- package/addon/components/table-of-contents-plugin/toolbar-button.hbs +8 -0
- package/addon/components/table-of-contents-plugin/{card.ts → toolbar-button.ts} +1 -18
- package/addon/components/{insert-variable-plugin → variable-plugin}/insert-variable-card.hbs +4 -4
- package/addon/components/{insert-variable-plugin → variable-plugin}/insert-variable-card.ts +26 -35
- package/addon/components/{template-variable-plugin → variable-plugin}/template-variable-card.hbs +6 -6
- package/addon/components/variable-plugin/template-variable-card.ts +174 -0
- package/addon/components/variable-plugin/variable.hbs +4 -0
- package/addon/components/variable-plugin/variable.ts +250 -0
- package/addon/plugins/article-structure-plugin/commands/insert-structure.ts +58 -31
- package/addon/plugins/article-structure-plugin/index.ts +1 -1
- package/addon/plugins/article-structure-plugin/structures/article-paragraph.ts +42 -6
- package/addon/plugins/article-structure-plugin/structures/article.ts +14 -4
- package/addon/plugins/article-structure-plugin/structures/chapter.ts +2 -3
- package/addon/plugins/article-structure-plugin/structures/section.ts +2 -2
- package/addon/plugins/article-structure-plugin/structures/structure-header.ts +11 -4
- package/addon/plugins/article-structure-plugin/structures/subsection.ts +2 -2
- package/addon/plugins/article-structure-plugin/structures/title.ts +2 -3
- package/addon/plugins/article-structure-plugin/utils/structure.ts +29 -9
- package/addon/plugins/citation-plugin/index.ts +184 -113
- package/addon/plugins/rdfa-date-plugin/index.ts +42 -3
- package/addon/plugins/rdfa-date-plugin/nodes/date.ts +127 -0
- package/addon/plugins/rdfa-date-plugin/nodes/index.ts +1 -0
- package/addon/plugins/rdfa-date-plugin/utils.ts +10 -0
- package/addon/plugins/roadsign-regulation-plugin/nodes.ts +107 -0
- package/addon/plugins/standard-template-plugin/index.ts +26 -0
- package/addon/plugins/standard-template-plugin/utils/nodes.ts +366 -0
- package/addon/plugins/table-of-contents-plugin/index.ts +8 -12
- package/addon/plugins/table-of-contents-plugin/nodes/table-of-contents.ts +35 -42
- package/addon/plugins/{insert-variable-plugin → variable-plugin}/index.ts +6 -1
- package/addon/plugins/variable-plugin/nodes.ts +137 -0
- package/addon/plugins/variable-plugin/utils/constants.ts +107 -0
- package/addon/plugins/{template-variable-plugin → variable-plugin}/utils/fetch-data.ts +41 -0
- package/addon/services/standard-template-plugin.ts +16 -12
- package/addon/utils/changed-descendants.ts +29 -0
- package/addon/utils/constants.ts +22 -0
- package/addon/utils/namespace.ts +60 -0
- package/app/components/{table-of-contents-plugin/card.js → au-dropdown-pill.js} +1 -1
- package/app/components/table-of-contents-plugin/toolbar-button.js +1 -0
- package/app/components/{insert-variable-plugin → variable-plugin}/insert-variable-card.js +1 -1
- package/app/components/{template-variable-plugin → variable-plugin}/template-variable-card.js +1 -1
- package/app/components/variable-plugin/variable-edit-modal.js +1 -0
- package/app/components/variable-plugin/variable.js +1 -0
- package/app/styles/date-plugin.scss +17 -0
- package/app/styles/variable-plugin.scss +65 -0
- package/components/au-dropdown-pill.d.ts +19 -0
- package/components/au-native-input.d.ts +1 -1
- package/components/citation-plugin/citation-card.d.ts +1 -1
- package/components/citation-plugin/citation-insert.d.ts +7 -0
- package/components/citation-plugin/citations/search-modal.d.ts +1 -3
- package/components/rdfa-date-plugin/card.d.ts +14 -5
- package/components/rdfa-date-plugin/insert.d.ts +1 -2
- package/components/roadsign-regulation-plugin/roadsign-regulation-card.d.ts +1 -0
- package/components/roadsign-regulation-plugin/roadsigns-modal.d.ts +3 -0
- package/components/standard-template-plugin/template-provider.d.ts +6 -1
- package/components/table-of-contents-plugin/ember-nodes/table-of-contents.d.ts +1 -1
- package/components/table-of-contents-plugin/{card.d.ts → toolbar-button.d.ts} +0 -5
- package/components/{insert-variable-plugin → variable-plugin}/insert-variable-card.d.ts +3 -4
- package/components/{template-variable-plugin → variable-plugin}/template-variable-card.d.ts +8 -5
- package/components/variable-plugin/variable.d.ts +42 -0
- package/package.json +6 -6
- package/plugins/article-structure-plugin/commands/insert-structure.d.ts +2 -2
- package/plugins/article-structure-plugin/index.d.ts +1 -1
- package/plugins/article-structure-plugin/utils/structure.d.ts +4 -3
- package/plugins/citation-plugin/index.d.ts +11 -4
- package/plugins/rdfa-date-plugin/index.d.ts +13 -1
- package/plugins/rdfa-date-plugin/nodes/date.d.ts +9 -0
- package/plugins/rdfa-date-plugin/nodes/index.d.ts +1 -0
- package/plugins/rdfa-date-plugin/utils.d.ts +1 -0
- package/plugins/roadsign-regulation-plugin/nodes.d.ts +2 -0
- package/plugins/standard-template-plugin/index.d.ts +12 -0
- package/plugins/standard-template-plugin/utils/nodes.d.ts +12 -0
- package/plugins/table-of-contents-plugin/index.d.ts +4 -2
- package/plugins/table-of-contents-plugin/nodes/table-of-contents.d.ts +4 -3
- package/plugins/{insert-variable-plugin → variable-plugin}/index.d.ts +1 -0
- package/plugins/variable-plugin/nodes.d.ts +2 -0
- package/plugins/variable-plugin/utils/constants.d.ts +9 -0
- package/plugins/{template-variable-plugin → variable-plugin}/utils/fetch-data.d.ts +5 -0
- package/services/standard-template-plugin.d.ts +9 -10
- package/translations/en-US.yaml +4 -3
- package/translations/nl-BE.yaml +8 -7
- package/utils/changed-descendants.d.ts +2 -0
- package/utils/constants.d.ts +10 -0
- package/utils/namespace.d.ts +11 -0
- package/addon/components/table-of-contents-plugin/card.hbs +0 -16
- package/addon/components/template-variable-plugin/template-variable-card.ts +0 -227
- package/addon/plugins/article-structure-plugin/constants.ts +0 -11
- package/addon/plugins/article-structure-plugin/utils/namespace.ts +0 -25
- package/addon/plugins/insert-variable-plugin/utils/constants.ts +0 -67
- package/addon/plugins/insert-variable-plugin/utils/fetch-data.ts +0 -41
- package/addon/plugins/rdfa-date-plugin/commands/index.ts +0 -1
- package/addon/plugins/rdfa-date-plugin/commands/modify-date.ts +0 -48
- package/addon/plugins/table-of-contents-plugin/utils/constants.ts +0 -17
- package/addon/plugins/template-variable-plugin/index.ts +0 -6
- package/addon/plugins/template-variable-plugin/utils/constants.ts +0 -2
- package/plugins/article-structure-plugin/constants.d.ts +0 -5
- package/plugins/article-structure-plugin/utils/namespace.d.ts +0 -6
- package/plugins/insert-variable-plugin/utils/constants.d.ts +0 -7
- package/plugins/insert-variable-plugin/utils/fetch-data.d.ts +0 -5
- package/plugins/rdfa-date-plugin/commands/index.d.ts +0 -1
- package/plugins/rdfa-date-plugin/commands/modify-date.d.ts +0 -2
- package/plugins/table-of-contents-plugin/utils/constants.d.ts +0 -7
- package/plugins/template-variable-plugin/index.d.ts +0 -2
- package/plugins/template-variable-plugin/utils/constants.d.ts +0 -1
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { tracked } from '@glimmer/tracking';
|
|
3
|
+
import { action } from '@ember/object';
|
|
4
|
+
import { getOwner } from '@ember/application';
|
|
5
|
+
import { task } from 'ember-concurrency';
|
|
6
|
+
import { ProseController } from '@lblod/ember-rdfa-editor/core/prosemirror';
|
|
7
|
+
import { unwrap } from '@lblod/ember-rdfa-editor/utils/option';
|
|
8
|
+
import {
|
|
9
|
+
CodeListOption,
|
|
10
|
+
fetchCodeListOptions,
|
|
11
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/fetch-data';
|
|
12
|
+
import { MULTI_SELECT_CODELIST_TYPE } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/constants';
|
|
13
|
+
import { findParentNodeOfType } from '@curvenote/prosemirror-utils';
|
|
14
|
+
import { NodeSelection, PNode, ProseParser } from '@lblod/ember-rdfa-editor';
|
|
15
|
+
import { ZONAL_URI } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/roadsign-regulation-plugin/utils/constants';
|
|
16
|
+
|
|
17
|
+
type Args = {
|
|
18
|
+
controller: ProseController;
|
|
19
|
+
};
|
|
20
|
+
export default class EditorPluginsTemplateVariableCardComponent extends Component<Args> {
|
|
21
|
+
@tracked variableOptions: CodeListOption[] = [];
|
|
22
|
+
@tracked selectedVariableOption?: CodeListOption | CodeListOption[];
|
|
23
|
+
@tracked selectedVariable: { pos: number; node: PNode } | undefined;
|
|
24
|
+
@tracked showCard = false;
|
|
25
|
+
@tracked multiSelect = false;
|
|
26
|
+
mappingUri?: string;
|
|
27
|
+
zonalLocationCodelistUri: string;
|
|
28
|
+
endpoint: string;
|
|
29
|
+
nonZonalLocationCodelistUri: string;
|
|
30
|
+
|
|
31
|
+
constructor(parent: unknown, args: Args) {
|
|
32
|
+
super(parent, args);
|
|
33
|
+
const config = getOwner(this)?.resolveRegistration(
|
|
34
|
+
'config:environment'
|
|
35
|
+
) as {
|
|
36
|
+
templateVariablePlugin: {
|
|
37
|
+
zonalLocationCodelistUri: string;
|
|
38
|
+
endpoint: string;
|
|
39
|
+
nonZonalLocationCodelistUri: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
const pluginConfig = config.templateVariablePlugin;
|
|
43
|
+
this.zonalLocationCodelistUri = pluginConfig.zonalLocationCodelistUri;
|
|
44
|
+
this.endpoint = pluginConfig.endpoint;
|
|
45
|
+
this.nonZonalLocationCodelistUri = pluginConfig.nonZonalLocationCodelistUri;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get controller() {
|
|
49
|
+
return this.args.controller;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@action
|
|
53
|
+
insert() {
|
|
54
|
+
if (!this.selectedVariable || !this.selectedVariableOption) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
let htmlToInsert: string;
|
|
58
|
+
if (Array.isArray(this.selectedVariableOption)) {
|
|
59
|
+
htmlToInsert = this.selectedVariableOption
|
|
60
|
+
.map((variable) => variable.value)
|
|
61
|
+
.join(', ');
|
|
62
|
+
} else {
|
|
63
|
+
htmlToInsert = unwrap(this.selectedVariableOption.value);
|
|
64
|
+
}
|
|
65
|
+
htmlToInsert = this.wrapVariableInHighlight(htmlToInsert);
|
|
66
|
+
const domParser = new DOMParser();
|
|
67
|
+
const htmlNode = domParser.parseFromString(htmlToInsert, 'text/html');
|
|
68
|
+
const contentFragment = ProseParser.fromSchema(
|
|
69
|
+
this.args.controller.schema
|
|
70
|
+
).parseSlice(htmlNode, {
|
|
71
|
+
preserveWhitespace: false,
|
|
72
|
+
}).content;
|
|
73
|
+
const range = {
|
|
74
|
+
from: this.selectedVariable.pos + 1,
|
|
75
|
+
to: this.selectedVariable.pos + this.selectedVariable.node.nodeSize - 1,
|
|
76
|
+
};
|
|
77
|
+
this.controller.withTransaction((tr) => {
|
|
78
|
+
return tr.replaceWith(range.from, range.to, contentFragment);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
wrapVariableInHighlight(text: string) {
|
|
83
|
+
return text.replace(
|
|
84
|
+
/\$\{(.+?)\}/g,
|
|
85
|
+
'<span class="mark-highlight-manual">${$1}</span>'
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@action
|
|
90
|
+
selectionChanged() {
|
|
91
|
+
this.showCard = false;
|
|
92
|
+
this.selectedVariableOption = undefined;
|
|
93
|
+
const { selection } = this.controller.state;
|
|
94
|
+
if (
|
|
95
|
+
selection instanceof NodeSelection &&
|
|
96
|
+
selection.node.type === this.controller.schema.nodes.variable
|
|
97
|
+
) {
|
|
98
|
+
const variable = {
|
|
99
|
+
node: selection.node,
|
|
100
|
+
pos: selection.from,
|
|
101
|
+
};
|
|
102
|
+
this.selectedVariable = variable;
|
|
103
|
+
if (variable) {
|
|
104
|
+
const type = variable.node.attrs.type as string;
|
|
105
|
+
if (type === 'codelist') {
|
|
106
|
+
const source =
|
|
107
|
+
(variable.node.attrs.source as string | undefined) ?? this.endpoint;
|
|
108
|
+
const codelistURI = variable.node.attrs.codelistResource as string;
|
|
109
|
+
void this.fetchCodeListOptions.perform(source, codelistURI);
|
|
110
|
+
this.showCard = true;
|
|
111
|
+
} else if (type === 'location') {
|
|
112
|
+
const source =
|
|
113
|
+
(variable.node.attrs.source as string | undefined) ?? this.endpoint;
|
|
114
|
+
const roadSignRegulation = findParentNodeOfType(
|
|
115
|
+
this.controller.schema.nodes.roadsign_regulation
|
|
116
|
+
)(selection);
|
|
117
|
+
const zonalityUri = roadSignRegulation?.node.attrs.zonality as
|
|
118
|
+
| string
|
|
119
|
+
| undefined;
|
|
120
|
+
if (zonalityUri === ZONAL_URI) {
|
|
121
|
+
void this.fetchCodeListOptions.perform(
|
|
122
|
+
source,
|
|
123
|
+
this.zonalLocationCodelistUri,
|
|
124
|
+
true
|
|
125
|
+
);
|
|
126
|
+
} else {
|
|
127
|
+
void this.fetchCodeListOptions.perform(
|
|
128
|
+
source,
|
|
129
|
+
this.nonZonalLocationCodelistUri,
|
|
130
|
+
true
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
this.showCard = true;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
@action
|
|
141
|
+
updateVariableOption(variableOption: CodeListOption | CodeListOption[]) {
|
|
142
|
+
this.selectedVariableOption = variableOption;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
fetchCodeListOptions = task(
|
|
146
|
+
async (endpoint: string, codelistUri: string, isLocation?: boolean) => {
|
|
147
|
+
const { type, options } = await fetchCodeListOptions(
|
|
148
|
+
endpoint,
|
|
149
|
+
codelistUri
|
|
150
|
+
);
|
|
151
|
+
if (isLocation) {
|
|
152
|
+
this.variableOptions = options.map((option) => ({
|
|
153
|
+
label: option.label,
|
|
154
|
+
value: this.wrapInLocation(unwrap(option.value)),
|
|
155
|
+
}));
|
|
156
|
+
} else {
|
|
157
|
+
this.variableOptions = options;
|
|
158
|
+
}
|
|
159
|
+
if (type === MULTI_SELECT_CODELIST_TYPE) {
|
|
160
|
+
this.multiSelect = true;
|
|
161
|
+
} else {
|
|
162
|
+
this.multiSelect = false;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
wrapInLocation(value: string) {
|
|
168
|
+
return `
|
|
169
|
+
<span property="https://data.vlaanderen.be/ns/mobiliteit#plaatsbepaling">
|
|
170
|
+
${value}
|
|
171
|
+
</span>
|
|
172
|
+
`;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Based on the footnotes example from https://github.com/ProseMirror/website
|
|
4
|
+
*
|
|
5
|
+
* Copyright (C) 2015-2017 by Marijn Haverbeke <marijnh@gmail.com> and others
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in
|
|
14
|
+
* all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
* THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { action } from '@ember/object';
|
|
26
|
+
import { inject as service } from '@ember/service';
|
|
27
|
+
import { htmlSafe } from '@ember/template';
|
|
28
|
+
import Component from '@glimmer/component';
|
|
29
|
+
import {
|
|
30
|
+
chainCommands,
|
|
31
|
+
createParagraphNear,
|
|
32
|
+
DOMSerializer,
|
|
33
|
+
EditorState,
|
|
34
|
+
keymap,
|
|
35
|
+
liftEmptyBlock,
|
|
36
|
+
newlineInCode,
|
|
37
|
+
NodeSelection,
|
|
38
|
+
RdfaEditorView,
|
|
39
|
+
redo,
|
|
40
|
+
Schema,
|
|
41
|
+
splitBlock,
|
|
42
|
+
StepMap,
|
|
43
|
+
Transaction,
|
|
44
|
+
undo,
|
|
45
|
+
} from '@lblod/ember-rdfa-editor';
|
|
46
|
+
import { date } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/rdfa-date-plugin/nodes';
|
|
47
|
+
import {
|
|
48
|
+
isSome,
|
|
49
|
+
unwrap,
|
|
50
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/option';
|
|
51
|
+
import { insertHardBreak } from '@lblod/ember-rdfa-editor/commands/insert-hard-break';
|
|
52
|
+
import { toggleMarkAddFirst } from '@lblod/ember-rdfa-editor/commands/toggle-mark-add-first';
|
|
53
|
+
import {
|
|
54
|
+
link,
|
|
55
|
+
em,
|
|
56
|
+
strong,
|
|
57
|
+
underline,
|
|
58
|
+
strikethrough,
|
|
59
|
+
} from '@lblod/ember-rdfa-editor/marks';
|
|
60
|
+
import {
|
|
61
|
+
block_rdfa,
|
|
62
|
+
hard_break,
|
|
63
|
+
placeholder,
|
|
64
|
+
text,
|
|
65
|
+
paragraph,
|
|
66
|
+
repaired_block,
|
|
67
|
+
} from '@lblod/ember-rdfa-editor/nodes';
|
|
68
|
+
import {
|
|
69
|
+
inline_rdfa,
|
|
70
|
+
invisible_rdfa,
|
|
71
|
+
} from '@lblod/ember-rdfa-editor/nodes/inline-rdfa';
|
|
72
|
+
import { EmberNodeArgs } from '@lblod/ember-rdfa-editor/utils/ember-node';
|
|
73
|
+
import IntlService from 'ember-intl/services/intl';
|
|
74
|
+
|
|
75
|
+
export default class Variable extends Component<EmberNodeArgs> {
|
|
76
|
+
@service declare intl: IntlService;
|
|
77
|
+
innerView: RdfaEditorView | null = null;
|
|
78
|
+
|
|
79
|
+
contentWrapper: Element | null = null;
|
|
80
|
+
|
|
81
|
+
get outerView() {
|
|
82
|
+
return this.args.view;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get node() {
|
|
86
|
+
return this.args.node;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get pos() {
|
|
90
|
+
return this.args.getPos();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
get htmlContent() {
|
|
94
|
+
const fragment = DOMSerializer.fromSchema(this.schema).serializeFragment(
|
|
95
|
+
this.node.content,
|
|
96
|
+
{
|
|
97
|
+
document,
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
const div = document.createElement('div');
|
|
101
|
+
div.appendChild(fragment);
|
|
102
|
+
return htmlSafe(div.innerHTML);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
get schema() {
|
|
106
|
+
return new Schema({
|
|
107
|
+
nodes: {
|
|
108
|
+
doc: {
|
|
109
|
+
content: 'block+',
|
|
110
|
+
},
|
|
111
|
+
paragraph,
|
|
112
|
+
date: date({
|
|
113
|
+
placeholder: {
|
|
114
|
+
insertDate: this.intl.t('date-plugin.insert.date'),
|
|
115
|
+
insertDateTime: this.intl.t('date-plugin.insert.datetime'),
|
|
116
|
+
},
|
|
117
|
+
}),
|
|
118
|
+
repaired_block,
|
|
119
|
+
placeholder,
|
|
120
|
+
|
|
121
|
+
text,
|
|
122
|
+
|
|
123
|
+
hard_break,
|
|
124
|
+
block_rdfa,
|
|
125
|
+
invisible_rdfa,
|
|
126
|
+
},
|
|
127
|
+
marks: {
|
|
128
|
+
inline_rdfa,
|
|
129
|
+
link,
|
|
130
|
+
em,
|
|
131
|
+
strong,
|
|
132
|
+
underline,
|
|
133
|
+
strikethrough,
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@action
|
|
139
|
+
onFocus() {
|
|
140
|
+
const outerSelectionTr = this.outerView.state.tr;
|
|
141
|
+
const outerSelection = new NodeSelection(
|
|
142
|
+
this.outerView.state.doc.resolve(this.pos)
|
|
143
|
+
);
|
|
144
|
+
outerSelectionTr.setSelection(outerSelection);
|
|
145
|
+
this.outerView.dispatch(outerSelectionTr);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
@action
|
|
149
|
+
didInsertContentWrapper(target: Element) {
|
|
150
|
+
this.contentWrapper = target;
|
|
151
|
+
this.innerView = new RdfaEditorView(this.contentWrapper, {
|
|
152
|
+
state: EditorState.create({
|
|
153
|
+
doc: this.node,
|
|
154
|
+
plugins: [
|
|
155
|
+
keymap({
|
|
156
|
+
'Mod-z': () =>
|
|
157
|
+
undo(this.outerView.state, this.outerView.dispatch.bind(this)),
|
|
158
|
+
'Mod-Z': () =>
|
|
159
|
+
undo(this.outerView.state, this.outerView.dispatch.bind(this)),
|
|
160
|
+
'Mod-y': () =>
|
|
161
|
+
redo(this.outerView.state, this.outerView.dispatch.bind(this)),
|
|
162
|
+
'Mod-Y': () =>
|
|
163
|
+
redo(this.outerView.state, this.outerView.dispatch.bind(this)),
|
|
164
|
+
'Mod-b': toggleMarkAddFirst(this.schema.marks.strong),
|
|
165
|
+
'Mod-B': toggleMarkAddFirst(this.schema.marks.strong),
|
|
166
|
+
'Mod-i': toggleMarkAddFirst(this.schema.marks.em),
|
|
167
|
+
'Mod-I': toggleMarkAddFirst(this.schema.marks.em),
|
|
168
|
+
'Mod-u': toggleMarkAddFirst(this.schema.marks.underline),
|
|
169
|
+
'Mod-U': toggleMarkAddFirst(this.schema.marks.underline),
|
|
170
|
+
Enter: chainCommands(
|
|
171
|
+
newlineInCode,
|
|
172
|
+
createParagraphNear,
|
|
173
|
+
liftEmptyBlock,
|
|
174
|
+
splitBlock,
|
|
175
|
+
insertHardBreak
|
|
176
|
+
),
|
|
177
|
+
}),
|
|
178
|
+
],
|
|
179
|
+
schema: this.schema,
|
|
180
|
+
}),
|
|
181
|
+
dispatchTransaction: this.dispatchInner,
|
|
182
|
+
handleDOMEvents: {
|
|
183
|
+
mousedown: () => {
|
|
184
|
+
// Kludge to prevent issues due to the fact that the whole
|
|
185
|
+
// footnote is node-selected (and thus DOM-selected) when
|
|
186
|
+
// the parent editor is focused.
|
|
187
|
+
|
|
188
|
+
if (this.outerView.hasFocus()) this.innerView?.focus();
|
|
189
|
+
},
|
|
190
|
+
focus: () => {
|
|
191
|
+
const outerSelectionTr = this.outerView.state.tr;
|
|
192
|
+
const outerSelection = new NodeSelection(
|
|
193
|
+
this.outerView.state.doc.resolve(this.pos)
|
|
194
|
+
);
|
|
195
|
+
outerSelectionTr.setSelection(outerSelection);
|
|
196
|
+
this.outerView.dispatch(outerSelectionTr);
|
|
197
|
+
if (this.innerView) {
|
|
198
|
+
this.args.controller.setEmbeddedView(this.innerView);
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
@action
|
|
206
|
+
onNodeUpdate() {
|
|
207
|
+
if (this.innerView) {
|
|
208
|
+
const state = this.innerView.state;
|
|
209
|
+
const start = this.node.content.findDiffStart(state.doc.content);
|
|
210
|
+
const end = this.node.content.findDiffEnd(state.doc.content);
|
|
211
|
+
if (isSome(start) && isSome(end)) {
|
|
212
|
+
let { a: endA, b: endB } = end;
|
|
213
|
+
const overlap = start - Math.min(endA, endB);
|
|
214
|
+
if (overlap > 0) {
|
|
215
|
+
endA += overlap;
|
|
216
|
+
endB += overlap;
|
|
217
|
+
}
|
|
218
|
+
this.innerView.dispatch(
|
|
219
|
+
state.tr
|
|
220
|
+
.replace(start, endB, this.node.slice(start, endA))
|
|
221
|
+
.setMeta('fromOutside', true)
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
dispatchInner = (tr: Transaction) => {
|
|
228
|
+
if (this.innerView) {
|
|
229
|
+
const { state, transactions } = this.innerView.state.applyTransaction(tr);
|
|
230
|
+
this.innerView.updateState(state);
|
|
231
|
+
|
|
232
|
+
if (!tr.getMeta('fromOutside')) {
|
|
233
|
+
const outerTr = this.outerView.state.tr,
|
|
234
|
+
offsetMap = StepMap.offset(this.pos + 1);
|
|
235
|
+
for (let i = 0; i < transactions.length; i++) {
|
|
236
|
+
const steps = transactions[i].steps;
|
|
237
|
+
for (let j = 0; j < steps.length; j++)
|
|
238
|
+
outerTr.step(unwrap(steps[j].map(offsetMap)));
|
|
239
|
+
}
|
|
240
|
+
if (outerTr.docChanged) this.outerView.dispatch(outerTr);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
willDestroy(): void {
|
|
246
|
+
super.willDestroy();
|
|
247
|
+
this.innerView?.destroy();
|
|
248
|
+
this.innerView = null;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Command,
|
|
3
|
+
Fragment,
|
|
3
4
|
NodeSelection,
|
|
4
5
|
NodeType,
|
|
6
|
+
PNode,
|
|
7
|
+
Schema,
|
|
5
8
|
Selection,
|
|
6
9
|
TextSelection,
|
|
7
10
|
} from '@lblod/ember-rdfa-editor';
|
|
@@ -9,56 +12,44 @@ import recalculateStructureNumbers from './recalculate-structure-numbers';
|
|
|
9
12
|
import { StructureSpec } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/article-structure-plugin';
|
|
10
13
|
import wrapStructureContent from './wrap-structure-content';
|
|
11
14
|
import IntlService from 'ember-intl/services/intl';
|
|
15
|
+
import { findNodes } from '@lblod/ember-rdfa-editor/utils/position-utils';
|
|
16
|
+
import { containsOnlyPlaceholder } from '../utils/structure';
|
|
12
17
|
|
|
13
18
|
const insertStructure = (
|
|
14
19
|
structureSpec: StructureSpec,
|
|
15
|
-
intl: IntlService
|
|
20
|
+
intl: IntlService,
|
|
21
|
+
content?: Fragment
|
|
16
22
|
): Command => {
|
|
17
23
|
return (state, dispatch) => {
|
|
18
|
-
const { schema, selection } = state;
|
|
19
|
-
const
|
|
24
|
+
const { schema, selection, doc } = state;
|
|
25
|
+
const insertionRange = findInsertionRange({
|
|
26
|
+
doc,
|
|
20
27
|
selection,
|
|
21
|
-
schema.nodes[structureSpec.name]
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
nodeType: schema.nodes[structureSpec.name],
|
|
29
|
+
schema,
|
|
30
|
+
});
|
|
31
|
+
if (!insertionRange) {
|
|
24
32
|
return wrapStructureContent(structureSpec, intl)(state, dispatch);
|
|
25
33
|
}
|
|
26
34
|
if (dispatch) {
|
|
27
35
|
const { node: newStructureNode, selectionConfig } =
|
|
28
|
-
structureSpec.constructor({ schema, intl });
|
|
36
|
+
structureSpec.constructor({ schema, intl, content });
|
|
29
37
|
const transaction = state.tr;
|
|
30
|
-
let insertRange: { from: number; to: number };
|
|
31
|
-
if (
|
|
32
|
-
container.node.childCount === 1 &&
|
|
33
|
-
container.node.firstChild?.type === schema.nodes['paragraph'] &&
|
|
34
|
-
container.node.firstChild.firstChild?.type ===
|
|
35
|
-
schema.nodes['placeholder']
|
|
36
|
-
) {
|
|
37
|
-
insertRange = {
|
|
38
|
-
from: container.pos + 1,
|
|
39
|
-
to: container.pos + container.node.nodeSize - 1,
|
|
40
|
-
};
|
|
41
|
-
} else {
|
|
42
|
-
insertRange = {
|
|
43
|
-
from: selection.$from.after(container.depth + 1),
|
|
44
|
-
to: selection.$from.after(container.depth + 1),
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
38
|
|
|
48
39
|
transaction.replaceWith(
|
|
49
|
-
|
|
50
|
-
|
|
40
|
+
insertionRange.from,
|
|
41
|
+
insertionRange.to,
|
|
51
42
|
newStructureNode
|
|
52
43
|
);
|
|
53
44
|
const newSelection =
|
|
54
45
|
selectionConfig.type === 'node'
|
|
55
46
|
? NodeSelection.create(
|
|
56
47
|
transaction.doc,
|
|
57
|
-
|
|
48
|
+
insertionRange.from + selectionConfig.relativePos
|
|
58
49
|
)
|
|
59
50
|
: TextSelection.create(
|
|
60
51
|
transaction.doc,
|
|
61
|
-
|
|
52
|
+
insertionRange.from + selectionConfig.relativePos
|
|
62
53
|
);
|
|
63
54
|
transaction.setSelection(newSelection);
|
|
64
55
|
transaction.scrollIntoView();
|
|
@@ -69,14 +60,50 @@ const insertStructure = (
|
|
|
69
60
|
};
|
|
70
61
|
};
|
|
71
62
|
|
|
72
|
-
function
|
|
63
|
+
function findInsertionRange(args: {
|
|
64
|
+
doc: PNode;
|
|
65
|
+
selection: Selection;
|
|
66
|
+
nodeType: NodeType;
|
|
67
|
+
schema: Schema;
|
|
68
|
+
}) {
|
|
69
|
+
const { doc, selection, nodeType, schema } = args;
|
|
73
70
|
const { $from } = selection;
|
|
74
71
|
for (let currentDepth = $from.depth; currentDepth >= 0; currentDepth--) {
|
|
75
72
|
const currentAncestor = $from.node(currentDepth);
|
|
76
73
|
const index = $from.index(currentDepth);
|
|
77
|
-
const pos = currentDepth > 0 ? $from.before(currentDepth) : -1;
|
|
78
74
|
if (currentAncestor.canReplaceWith(index, index, nodeType)) {
|
|
79
|
-
|
|
75
|
+
if (containsOnlyPlaceholder(schema, currentAncestor)) {
|
|
76
|
+
return { from: $from.start(currentDepth), to: $from.end(currentDepth) };
|
|
77
|
+
} else {
|
|
78
|
+
const insertPos = $from.after(currentDepth + 1);
|
|
79
|
+
return { from: insertPos, to: insertPos };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const nextContainerRange = findNodes(
|
|
84
|
+
doc,
|
|
85
|
+
selection.from,
|
|
86
|
+
true,
|
|
87
|
+
false,
|
|
88
|
+
({ from }) => {
|
|
89
|
+
const node = doc.nodeAt(from);
|
|
90
|
+
if (node) {
|
|
91
|
+
if (node.canReplaceWith(node.childCount, node.childCount, nodeType)) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
).next().value;
|
|
98
|
+
if (nextContainerRange) {
|
|
99
|
+
const { from, to } = nextContainerRange;
|
|
100
|
+
const containerNode = doc.nodeAt(from);
|
|
101
|
+
if (containerNode) {
|
|
102
|
+
if (containsOnlyPlaceholder(schema, containerNode)) {
|
|
103
|
+
return { from: from + 1, to: to - 1 };
|
|
104
|
+
} else {
|
|
105
|
+
return { from: to - 1, to: to - 1 };
|
|
106
|
+
}
|
|
80
107
|
}
|
|
81
108
|
}
|
|
82
109
|
return null;
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
EditorState,
|
|
7
7
|
} from '@lblod/ember-rdfa-editor';
|
|
8
8
|
import IntlService from 'ember-intl/services/intl';
|
|
9
|
-
import { Transaction } from '
|
|
9
|
+
import { Transaction } from '@lblod/ember-rdfa-editor';
|
|
10
10
|
import { STRUCTURE_SPECS } from './structures';
|
|
11
11
|
|
|
12
12
|
export type SpecName = string;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { NodeSpec } from '@lblod/ember-rdfa-editor';
|
|
1
|
+
import { Fragment, NodeSpec } from '@lblod/ember-rdfa-editor';
|
|
2
2
|
import { StructureSpec } from '..';
|
|
3
3
|
import { v4 as uuid } from 'uuid';
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
ELI,
|
|
6
|
+
SAY,
|
|
7
|
+
XSD,
|
|
8
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
|
|
9
|
+
import { hasRDFaAttribute } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/namespace';
|
|
6
10
|
|
|
7
11
|
const PLACEHOLDERS = {
|
|
8
12
|
body: 'article-structure-plugin.placeholder.paragraph.body',
|
|
@@ -39,8 +43,11 @@ export const articleParagraphSpec: StructureSpec = {
|
|
|
39
43
|
},
|
|
40
44
|
};
|
|
41
45
|
|
|
46
|
+
const contentSelector = `span[property~='${SAY('body').prefixed}'],
|
|
47
|
+
span[property~='${SAY('body').full}']`;
|
|
48
|
+
|
|
42
49
|
export const article_paragraph: NodeSpec = {
|
|
43
|
-
content: '
|
|
50
|
+
content: 'inline*',
|
|
44
51
|
inline: false,
|
|
45
52
|
attrs: {
|
|
46
53
|
resource: {},
|
|
@@ -77,6 +84,7 @@ export const article_paragraph: NodeSpec = {
|
|
|
77
84
|
hasRDFaAttribute(element, 'property', SAY('hasParagraph')) &&
|
|
78
85
|
hasRDFaAttribute(element, 'typeof', SAY('Paragraph')) &&
|
|
79
86
|
element.getAttribute('resource') &&
|
|
87
|
+
element.querySelector(contentSelector) &&
|
|
80
88
|
numberSpan
|
|
81
89
|
) {
|
|
82
90
|
return {
|
|
@@ -86,8 +94,36 @@ export const article_paragraph: NodeSpec = {
|
|
|
86
94
|
}
|
|
87
95
|
return false;
|
|
88
96
|
},
|
|
89
|
-
contentElement:
|
|
90
|
-
|
|
97
|
+
contentElement: contentSelector,
|
|
98
|
+
},
|
|
99
|
+
// Parsing rule for backwards compatibility (when content was not inside seperate say:body div)
|
|
100
|
+
{
|
|
101
|
+
tag: 'div',
|
|
102
|
+
getAttrs(element: HTMLElement) {
|
|
103
|
+
const numberSpan = element.querySelector(`
|
|
104
|
+
span[property~='${ELI('number').prefixed}'],
|
|
105
|
+
span[property~='${ELI('number').full}']`);
|
|
106
|
+
if (
|
|
107
|
+
hasRDFaAttribute(element, 'property', SAY('hasParagraph')) &&
|
|
108
|
+
hasRDFaAttribute(element, 'typeof', SAY('Paragraph')) &&
|
|
109
|
+
element.getAttribute('resource') &&
|
|
110
|
+
numberSpan
|
|
111
|
+
) {
|
|
112
|
+
return {
|
|
113
|
+
resource: element.getAttribute('resource'),
|
|
114
|
+
number: numberSpan.textContent,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
},
|
|
119
|
+
getContent: (node, schema) => {
|
|
120
|
+
const content = node.lastChild?.textContent;
|
|
121
|
+
if (content) {
|
|
122
|
+
return Fragment.from(schema.text(content));
|
|
123
|
+
} else {
|
|
124
|
+
return Fragment.empty;
|
|
125
|
+
}
|
|
126
|
+
},
|
|
91
127
|
},
|
|
92
128
|
],
|
|
93
129
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NodeSpec } from '@lblod/ember-rdfa-editor';
|
|
1
|
+
import { NodeSpec, PNode } from '@lblod/ember-rdfa-editor';
|
|
2
2
|
import { StructureSpec } from '..';
|
|
3
3
|
import {
|
|
4
4
|
constructStructureBodyNodeSpec,
|
|
@@ -7,7 +7,12 @@ import {
|
|
|
7
7
|
} from '../utils/structure';
|
|
8
8
|
import { v4 as uuid } from 'uuid';
|
|
9
9
|
import { unwrap } from '@lblod/ember-rdfa-editor/utils/option';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
ELI,
|
|
12
|
+
EXT,
|
|
13
|
+
SAY,
|
|
14
|
+
XSD,
|
|
15
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
|
|
11
16
|
|
|
12
17
|
const PLACEHOLDERS = {
|
|
13
18
|
title: 'article-structure-plugin.placeholder.article.heading',
|
|
@@ -88,6 +93,10 @@ export const article_header: NodeSpec = {
|
|
|
88
93
|
default: SAY('heading').prefixed,
|
|
89
94
|
},
|
|
90
95
|
},
|
|
96
|
+
outlineText: (node: PNode) => {
|
|
97
|
+
const { number } = node.attrs;
|
|
98
|
+
return `Artikel ${number as string}: ${node.textContent}`;
|
|
99
|
+
},
|
|
91
100
|
toDOM(node) {
|
|
92
101
|
return [
|
|
93
102
|
'div',
|
|
@@ -118,11 +127,12 @@ export const article_header: NodeSpec = {
|
|
|
118
127
|
}
|
|
119
128
|
return false;
|
|
120
129
|
},
|
|
121
|
-
contentElement: `span[property~='${EXT('title').prefixed}']
|
|
130
|
+
contentElement: `span[property~='${EXT('title').prefixed}'],
|
|
131
|
+
span[property~='${EXT('title').full}']`,
|
|
122
132
|
},
|
|
123
133
|
],
|
|
124
134
|
};
|
|
125
135
|
|
|
126
136
|
export const article_body = constructStructureBodyNodeSpec({
|
|
127
|
-
content: '(
|
|
137
|
+
content: '(block|article_paragraph)+',
|
|
128
138
|
});
|