@lblod/ember-rdfa-editor-lblod-plugins 29.1.0 → 29.1.1-dev.4ca46ea39b10dedc794770fcf202fb89b6e0a16e
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/brown-bats-watch-1.md +10 -0
- package/.changeset/brown-bats-watch-2.md +10 -0
- package/.changeset/brown-bats-watch-3.md +10 -0
- package/.changeset/brown-bats-watch-4.md +10 -0
- package/.changeset/brown-bats-watch-5.md +10 -0
- package/.changeset/brown-bats-watch-6.md +10 -0
- package/.changeset/brown-bats-watch-7.md +10 -0
- package/.changeset/brown-bats-watch-8.md +12 -0
- package/.changeset/friendly-suits-deliver.md +5 -0
- package/.changeset/hot-fans-promise.md +5 -0
- package/.changeset/plenty-spies-scream.md +5 -0
- package/.changeset/stupid-eels-eat.md +9 -0
- package/CHANGELOG.md +6 -0
- package/addon/components/lmb-plugin/insert.ts +4 -37
- package/addon/components/location-plugin/insert.gts +27 -5
- package/addon/components/variable-plugin/address/edit.ts +3 -0
- package/addon/components/variable-plugin/address/insert.ts +3 -0
- package/addon/components/variable-plugin/address/nodeview.ts +3 -0
- package/addon/components/variable-plugin/address/utils.ts +3 -0
- package/addon/components/variable-plugin/autofilled/edit.gts +2 -34
- package/addon/components/variable-plugin/autofilled/insert.gts +0 -8
- package/addon/components/variable-plugin/codelist/edit.ts +2 -9
- package/addon/components/variable-plugin/codelist/insert.ts +0 -8
- package/addon/components/variable-plugin/date/edit.ts +12 -33
- package/addon/components/variable-plugin/date/insert-variable.ts +0 -8
- package/addon/components/variable-plugin/date/insert.ts +0 -8
- package/addon/components/variable-plugin/date/nodeview.ts +4 -10
- package/addon/components/variable-plugin/location/edit.ts +1 -3
- package/addon/components/variable-plugin/location/insert.ts +0 -8
- package/addon/components/variable-plugin/number/insert.ts +0 -6
- package/addon/components/variable-plugin/number/nodeview.ts +4 -24
- package/addon/components/variable-plugin/person/edit.hbs +1 -1
- package/addon/components/variable-plugin/person/edit.ts +35 -11
- package/addon/components/variable-plugin/person/insert.ts +4 -37
- package/addon/components/variable-plugin/person/nodeview.ts +12 -13
- package/addon/components/variable-plugin/text/insert.ts +0 -11
- package/addon/models/electee.ts +2 -2
- package/addon/plugins/besluit-type-plugin/utils/fetchBesluitTypes.ts +9 -20
- package/addon/plugins/location-plugin/node.ts +26 -52
- package/addon/plugins/snippet-plugin/nodes/snippet.ts +1 -6
- package/addon/plugins/variable-plugin/actions/create-autofilled-variable.ts +34 -28
- package/addon/plugins/variable-plugin/actions/create-classic-location-variable.ts +42 -34
- package/addon/plugins/variable-plugin/actions/create-codelist-variable.ts +51 -40
- package/addon/plugins/variable-plugin/actions/create-date-variable.ts +46 -36
- package/addon/plugins/variable-plugin/actions/create-number-variable.ts +39 -31
- package/addon/plugins/variable-plugin/actions/create-person-variable.ts +41 -0
- package/addon/plugins/variable-plugin/actions/create-text-variable.ts +36 -29
- package/addon/plugins/variable-plugin/utils/recreate-variable-uris.ts +53 -7
- package/addon/plugins/variable-plugin/variables/autofilled.ts +57 -5
- package/addon/plugins/variable-plugin/variables/codelist.ts +66 -12
- package/addon/plugins/variable-plugin/variables/date.ts +72 -38
- package/addon/plugins/variable-plugin/variables/location.ts +56 -6
- package/addon/plugins/variable-plugin/variables/number.ts +69 -20
- package/addon/plugins/variable-plugin/variables/person.ts +44 -39
- package/addon/plugins/variable-plugin/variables/text.ts +46 -5
- package/declarations/addon/components/variable-plugin/address/edit.d.ts +3 -0
- package/declarations/addon/components/variable-plugin/address/insert.d.ts +3 -0
- package/declarations/addon/components/variable-plugin/address/nodeview.d.ts +3 -0
- package/declarations/addon/components/variable-plugin/address/utils.d.ts +3 -0
- package/declarations/addon/components/variable-plugin/autofilled/edit.d.ts +1 -1
- package/declarations/addon/components/variable-plugin/date/nodeview.d.ts +3 -2
- package/declarations/addon/components/variable-plugin/person/edit.d.ts +1 -1
- package/declarations/addon/components/variable-plugin/person/nodeview.d.ts +3 -4
- package/declarations/addon/models/electee.d.ts +2 -2
- package/declarations/addon/plugins/variable-plugin/actions/create-autofilled-variable.d.ts +10 -6
- package/declarations/addon/plugins/variable-plugin/actions/create-classic-location-variable.d.ts +11 -6
- package/declarations/addon/plugins/variable-plugin/actions/create-codelist-variable.d.ts +12 -6
- package/declarations/addon/plugins/variable-plugin/actions/create-date-variable.d.ts +14 -8
- package/declarations/addon/plugins/variable-plugin/actions/create-number-variable.d.ts +12 -7
- package/declarations/addon/plugins/variable-plugin/actions/create-person-variable.d.ts +18 -0
- package/declarations/addon/plugins/variable-plugin/actions/create-text-variable.d.ts +10 -6
- package/declarations/addon/plugins/variable-plugin/utils/recreate-variable-uris.d.ts +1 -3
- package/package.json +3 -4
- package/pnpm-lock.yaml +5 -98
- package/translations/en-US.yaml +1 -1
- package/translations/nl-BE.yaml +1 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
+
DCT,
|
|
2
3
|
EXT,
|
|
3
4
|
RDF,
|
|
4
5
|
VARIABLES,
|
|
6
|
+
XSD,
|
|
5
7
|
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
|
|
6
8
|
import {
|
|
7
9
|
createEmberNodeSpec,
|
|
@@ -38,6 +40,37 @@ const parseDOM = [
|
|
|
38
40
|
if (!attrs) {
|
|
39
41
|
return false;
|
|
40
42
|
}
|
|
43
|
+
if (
|
|
44
|
+
node.dataset.sayVariable &&
|
|
45
|
+
node.dataset.sayVariableType === 'autofilled' &&
|
|
46
|
+
node.querySelector(CONTENT_SELECTOR)
|
|
47
|
+
) {
|
|
48
|
+
const label = node.dataset.label;
|
|
49
|
+
const autofillKey = node.dataset.autofillKey;
|
|
50
|
+
const convertToString = node.dataset.convertToString === 'true';
|
|
51
|
+
const initialized = node.dataset.initialized === 'true';
|
|
52
|
+
return {
|
|
53
|
+
...attrs,
|
|
54
|
+
label,
|
|
55
|
+
autofillKey,
|
|
56
|
+
convertToString,
|
|
57
|
+
initialized,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
},
|
|
62
|
+
contentElement: CONTENT_SELECTOR,
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
const parseDOMLegacy = [
|
|
67
|
+
{
|
|
68
|
+
tag: 'span',
|
|
69
|
+
getAttrs: (node: HTMLElement) => {
|
|
70
|
+
const attrs = getRdfaAttrs(node, { rdfaAware });
|
|
71
|
+
if (!attrs || attrs.rdfaNodeType !== 'resource') {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
41
74
|
if (
|
|
42
75
|
hasOutgoingNamedNodeTriple(
|
|
43
76
|
attrs,
|
|
@@ -47,21 +80,31 @@ const parseDOM = [
|
|
|
47
80
|
node.querySelector(CONTENT_SELECTOR) &&
|
|
48
81
|
hasRdfaVariableType(attrs, 'autofilled')
|
|
49
82
|
) {
|
|
50
|
-
|
|
83
|
+
const variableInstanceUri = attrs.subject;
|
|
84
|
+
const variableUri = getOutgoingTriple(attrs, VARIABLES('instanceOf'))
|
|
85
|
+
?.object.value;
|
|
86
|
+
if (!variableInstanceUri || !variableUri) {
|
|
51
87
|
return false;
|
|
52
88
|
}
|
|
89
|
+
|
|
53
90
|
const autofillKey = node.dataset.autofillKey;
|
|
54
91
|
const convertToString = node.dataset.convertToString === 'true';
|
|
55
92
|
const initialized = node.dataset.initialized === 'true';
|
|
56
|
-
|
|
93
|
+
const label = getOutgoingTriple(attrs, DCT('title'))?.object.value;
|
|
94
|
+
|
|
95
|
+
return createAutofilledVariableAttrs({
|
|
96
|
+
variable: variableUri,
|
|
97
|
+
variableInstance: variableInstanceUri,
|
|
98
|
+
label,
|
|
99
|
+
autofillKey,
|
|
100
|
+
convertToString,
|
|
101
|
+
initialized,
|
|
102
|
+
});
|
|
57
103
|
}
|
|
58
104
|
return false;
|
|
59
105
|
},
|
|
60
106
|
contentElement: CONTENT_SELECTOR,
|
|
61
107
|
},
|
|
62
|
-
];
|
|
63
|
-
|
|
64
|
-
const parseDOMLegacy = [
|
|
65
108
|
{
|
|
66
109
|
tag: 'span',
|
|
67
110
|
getAttrs: (node: HTMLElement) => {
|
|
@@ -115,9 +158,12 @@ const toDOM = (node: PNode): DOMOutputSpec => {
|
|
|
115
158
|
tag: 'span',
|
|
116
159
|
attrs: {
|
|
117
160
|
class: className,
|
|
161
|
+
'data-say-variable': 'true',
|
|
162
|
+
'data-say-variable-type': 'autofilled',
|
|
118
163
|
'data-autofill-key': node.attrs.autofillKey,
|
|
119
164
|
'data-convert-to-string': node.attrs.convertToString,
|
|
120
165
|
'data-initialized': node.attrs.initialized,
|
|
166
|
+
'data-label': node.attrs['label'],
|
|
121
167
|
},
|
|
122
168
|
content: 0,
|
|
123
169
|
});
|
|
@@ -137,6 +183,12 @@ const emberNodeConfig: EmberNodeConfig = {
|
|
|
137
183
|
selectable: true,
|
|
138
184
|
attrs: {
|
|
139
185
|
...rdfaAttrSpec({ rdfaAware }),
|
|
186
|
+
label: {
|
|
187
|
+
default: null,
|
|
188
|
+
},
|
|
189
|
+
datatype: {
|
|
190
|
+
default: XSD('string').namedNode,
|
|
191
|
+
},
|
|
140
192
|
autofillKey: {
|
|
141
193
|
default: '',
|
|
142
194
|
},
|
|
@@ -6,8 +6,10 @@ import {
|
|
|
6
6
|
import {
|
|
7
7
|
DCT,
|
|
8
8
|
EXT,
|
|
9
|
+
MOBILITEIT,
|
|
9
10
|
RDF,
|
|
10
11
|
VARIABLES,
|
|
12
|
+
XSD,
|
|
11
13
|
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
|
|
12
14
|
import {
|
|
13
15
|
createEmberNodeSpec,
|
|
@@ -49,6 +51,32 @@ const parseDOM = [
|
|
|
49
51
|
if (!attrs) {
|
|
50
52
|
return false;
|
|
51
53
|
}
|
|
54
|
+
if (
|
|
55
|
+
node.dataset.sayVariable &&
|
|
56
|
+
node.dataset.sayVariableType === 'codelist' &&
|
|
57
|
+
node.querySelector(CONTENT_SELECTOR)
|
|
58
|
+
) {
|
|
59
|
+
const label = node.dataset.label;
|
|
60
|
+
const source = node.dataset.source;
|
|
61
|
+
const codelist = node.dataset.codelist;
|
|
62
|
+
const selectionStyle = node.dataset.selectionStyle;
|
|
63
|
+
return { ...attrs, label, source, codelist, selectionStyle };
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
},
|
|
67
|
+
contentElement: CONTENT_SELECTOR,
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
const parseDOMLegacy = [
|
|
72
|
+
{
|
|
73
|
+
tag: 'span',
|
|
74
|
+
getAttrs: (node: HTMLElement) => {
|
|
75
|
+
const attrs = getRdfaAttrs(node, { rdfaAware });
|
|
76
|
+
if (!attrs || attrs.rdfaNodeType !== 'resource') {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
52
80
|
if (
|
|
53
81
|
hasOutgoingNamedNodeTriple(
|
|
54
82
|
attrs,
|
|
@@ -58,43 +86,56 @@ const parseDOM = [
|
|
|
58
86
|
node.querySelector(CONTENT_SELECTOR) &&
|
|
59
87
|
hasRdfaVariableType(attrs, 'codelist')
|
|
60
88
|
) {
|
|
61
|
-
|
|
89
|
+
const variableInstanceUri = attrs.subject;
|
|
90
|
+
const variableUri = getOutgoingTriple(attrs, VARIABLES('instanceOf'))
|
|
91
|
+
?.object.value;
|
|
92
|
+
if (!variableInstanceUri || !variableUri) {
|
|
62
93
|
return false;
|
|
63
94
|
}
|
|
95
|
+
|
|
96
|
+
const codelistUri = getOutgoingTriple(attrs, MOBILITEIT('codelijst'))
|
|
97
|
+
?.object.value;
|
|
98
|
+
const sourceUri = getOutgoingTriple(attrs, DCT('source'))?.object.value;
|
|
64
99
|
const selectionStyle = node.dataset.selectionStyle;
|
|
65
|
-
|
|
100
|
+
const label = getOutgoingTriple(attrs, DCT('title'))?.object.value;
|
|
101
|
+
|
|
102
|
+
return createCodelistVariableAttrs({
|
|
103
|
+
variable: variableUri,
|
|
104
|
+
variableInstance: variableInstanceUri,
|
|
105
|
+
label,
|
|
106
|
+
source: sourceUri,
|
|
107
|
+
codelist: codelistUri,
|
|
108
|
+
selectionStyle,
|
|
109
|
+
});
|
|
66
110
|
}
|
|
67
111
|
return false;
|
|
68
112
|
},
|
|
69
113
|
contentElement: CONTENT_SELECTOR,
|
|
70
114
|
},
|
|
71
|
-
];
|
|
72
|
-
|
|
73
|
-
const parseDOMLegacy = [
|
|
74
115
|
{
|
|
75
116
|
tag: 'span',
|
|
76
117
|
getAttrs(node: HTMLElement) {
|
|
77
118
|
const attrs = getRdfaAttrs(node, { rdfaAware });
|
|
78
|
-
if (!attrs) {
|
|
119
|
+
if (!attrs || attrs.rdfaNodeType !== 'resource') {
|
|
79
120
|
return false;
|
|
80
121
|
}
|
|
122
|
+
|
|
81
123
|
if (
|
|
82
124
|
hasOutgoingNamedNodeTriple(attrs, RDF('type'), EXT('Mapping')) &&
|
|
83
125
|
node.querySelector(CONTENT_SELECTOR) &&
|
|
84
126
|
hasRdfaVariableType(attrs, 'codelist')
|
|
85
127
|
) {
|
|
86
|
-
if (attrs.rdfaNodeType !== 'resource') {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
128
|
const variableUri = attrs.subject;
|
|
90
129
|
const variableInstanceUri =
|
|
91
130
|
getOutgoingTriple(attrs, EXT('instance'))?.object.value ??
|
|
92
131
|
generateVariableInstanceUri();
|
|
93
|
-
|
|
132
|
+
|
|
94
133
|
const codelistUri = getOutgoingTriple(attrs, EXT('codelist'))?.object
|
|
95
134
|
.value;
|
|
96
135
|
const sourceUri = getOutgoingTriple(attrs, DCT('source'))?.object.value;
|
|
97
136
|
const selectionStyle = node.dataset.selectionStyle;
|
|
137
|
+
const label = getOutgoingTriple(attrs, EXT('label'))?.object.value;
|
|
138
|
+
|
|
98
139
|
return createCodelistVariableAttrs({
|
|
99
140
|
variable: variableUri,
|
|
100
141
|
variableInstance: variableInstanceUri,
|
|
@@ -124,7 +165,6 @@ const parseDOMLegacy = [
|
|
|
124
165
|
parseVariableInstance(node) ?? generateVariableInstanceUri();
|
|
125
166
|
|
|
126
167
|
const source = parseVariableSource(node) ?? undefined;
|
|
127
|
-
const label = parseLabel(node) ?? undefined;
|
|
128
168
|
const selectionStyle = node.dataset.selectionStyle;
|
|
129
169
|
const codelistSpan = Array.from(node.children).find((el) =>
|
|
130
170
|
hasRDFaAttribute(el, 'property', EXT('codelist')),
|
|
@@ -133,6 +173,7 @@ const parseDOMLegacy = [
|
|
|
133
173
|
codelistSpan?.getAttribute('resource') ??
|
|
134
174
|
codelistSpan?.getAttribute('content') ??
|
|
135
175
|
undefined;
|
|
176
|
+
const label = parseLabel(node) ?? undefined;
|
|
136
177
|
|
|
137
178
|
return createCodelistVariableAttrs({
|
|
138
179
|
variable: variableUri,
|
|
@@ -151,7 +192,7 @@ const parseDOMLegacy = [
|
|
|
151
192
|
];
|
|
152
193
|
|
|
153
194
|
const toDOM = (node: PNode): DOMOutputSpec => {
|
|
154
|
-
const { selectionStyle } = node.attrs;
|
|
195
|
+
const { selectionStyle, label, codelist, source } = node.attrs;
|
|
155
196
|
const onlyContentType =
|
|
156
197
|
node.content.size === 1 && node.content.firstChild?.type;
|
|
157
198
|
const className =
|
|
@@ -164,7 +205,12 @@ const toDOM = (node: PNode): DOMOutputSpec => {
|
|
|
164
205
|
renderable: node,
|
|
165
206
|
attrs: {
|
|
166
207
|
class: className,
|
|
208
|
+
'data-say-variable': 'true',
|
|
209
|
+
'data-say-variable-type': 'codelist',
|
|
167
210
|
'data-selection-style': selectionStyle as string,
|
|
211
|
+
'data-label': label as string | null,
|
|
212
|
+
'data-codelist': codelist as string,
|
|
213
|
+
'data-source': source as string,
|
|
168
214
|
},
|
|
169
215
|
tag: 'span',
|
|
170
216
|
content: 0,
|
|
@@ -185,9 +231,17 @@ const emberNodeConfig: EmberNodeConfig = {
|
|
|
185
231
|
selectable: true,
|
|
186
232
|
attrs: {
|
|
187
233
|
...rdfaAttrSpec({ rdfaAware }),
|
|
234
|
+
label: {
|
|
235
|
+
default: null,
|
|
236
|
+
},
|
|
237
|
+
codelist: {},
|
|
238
|
+
source: {},
|
|
188
239
|
selectionStyle: {
|
|
189
240
|
default: null,
|
|
190
241
|
},
|
|
242
|
+
datatype: {
|
|
243
|
+
default: XSD('string').namedNode,
|
|
244
|
+
},
|
|
191
245
|
},
|
|
192
246
|
toDOM,
|
|
193
247
|
parseDOM: [...parseDOM, ...parseDOMLegacy],
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
EmberNodeConfig,
|
|
5
5
|
} from '@lblod/ember-rdfa-editor/utils/ember-node';
|
|
6
6
|
import {
|
|
7
|
+
DCT,
|
|
7
8
|
EXT,
|
|
8
9
|
RDF,
|
|
9
10
|
VARIABLES,
|
|
@@ -28,12 +29,13 @@ import {
|
|
|
28
29
|
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/variable-attribute-parsers';
|
|
29
30
|
import type { ComponentLike } from '@glint/template';
|
|
30
31
|
import { getTranslationFunction } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/translation';
|
|
31
|
-
import { formatDate, validateDateFormat } from '../utils/date-helpers';
|
|
32
|
-
import DateNodeviewComponent from '@lblod/ember-rdfa-editor-lblod-plugins/components/variable-plugin/date/nodeview';
|
|
33
32
|
import {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
formatContainsTime,
|
|
34
|
+
formatDate,
|
|
35
|
+
validateDateFormat,
|
|
36
|
+
} from '../utils/date-helpers';
|
|
37
|
+
import DateNodeviewComponent from '@lblod/ember-rdfa-editor-lblod-plugins/components/variable-plugin/date/nodeview';
|
|
38
|
+
import { renderRdfaAware } from '@lblod/ember-rdfa-editor/core/schema';
|
|
37
39
|
import { recreateVariableUris } from '../utils/recreate-variable-uris';
|
|
38
40
|
import {
|
|
39
41
|
generateVariableInstanceUri,
|
|
@@ -68,6 +70,33 @@ const parseDOM = [
|
|
|
68
70
|
if (!attrs) {
|
|
69
71
|
return false;
|
|
70
72
|
}
|
|
73
|
+
if (node.dataset.sayVariable && node.dataset.sayVariableType === 'date') {
|
|
74
|
+
const label = node.dataset.label;
|
|
75
|
+
const format = node.dataset.format;
|
|
76
|
+
const custom = node.dataset.custom === 'true';
|
|
77
|
+
const customAllowed = node.dataset.customAllowed !== 'false';
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
...attrs,
|
|
81
|
+
label,
|
|
82
|
+
format,
|
|
83
|
+
custom,
|
|
84
|
+
customAllowed,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
const parseDOMLegacy = [
|
|
93
|
+
{
|
|
94
|
+
tag: 'span',
|
|
95
|
+
getAttrs: (node: HTMLElement) => {
|
|
96
|
+
const attrs = getRdfaAttrs(node, { rdfaAware });
|
|
97
|
+
if (!attrs || attrs.rdfaNodeType !== 'resource') {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
71
100
|
if (
|
|
72
101
|
hasOutgoingNamedNodeTriple(
|
|
73
102
|
attrs,
|
|
@@ -76,25 +105,32 @@ const parseDOM = [
|
|
|
76
105
|
) &&
|
|
77
106
|
hasRdfaVariableType(attrs, 'date')
|
|
78
107
|
) {
|
|
79
|
-
|
|
108
|
+
const variableInstanceUri = attrs.subject;
|
|
109
|
+
const variableUri = getOutgoingTriple(attrs, VARIABLES('instanceOf'))
|
|
110
|
+
?.object.value;
|
|
111
|
+
if (!variableInstanceUri || !variableUri) {
|
|
80
112
|
return false;
|
|
81
113
|
}
|
|
114
|
+
const value = getOutgoingTriple(attrs, RDF('value'))?.object.value;
|
|
115
|
+
|
|
82
116
|
const format = node.dataset.format;
|
|
83
117
|
const custom = node.dataset.custom === 'true';
|
|
84
118
|
const customAllowed = node.dataset.customAllowed !== 'false';
|
|
119
|
+
const label = getOutgoingTriple(attrs, DCT('title'))?.object.value;
|
|
85
120
|
|
|
86
|
-
return {
|
|
87
|
-
|
|
121
|
+
return createDateVariableAttrs({
|
|
122
|
+
variable: variableUri,
|
|
123
|
+
variableInstance: variableInstanceUri,
|
|
124
|
+
value,
|
|
125
|
+
label,
|
|
88
126
|
format,
|
|
89
127
|
custom,
|
|
90
128
|
customAllowed,
|
|
91
|
-
};
|
|
129
|
+
});
|
|
92
130
|
}
|
|
93
131
|
return false;
|
|
94
132
|
},
|
|
95
133
|
},
|
|
96
|
-
];
|
|
97
|
-
const parseDOMLegacy = [
|
|
98
134
|
{
|
|
99
135
|
tag: 'span',
|
|
100
136
|
getAttrs(node: HTMLElement) {
|
|
@@ -125,7 +161,6 @@ const parseDOMLegacy = [
|
|
|
125
161
|
variableInstance: variableInstanceUri,
|
|
126
162
|
label,
|
|
127
163
|
value,
|
|
128
|
-
onlyDate: true,
|
|
129
164
|
format,
|
|
130
165
|
custom,
|
|
131
166
|
customAllowed,
|
|
@@ -147,7 +182,6 @@ const parseDOMLegacy = [
|
|
|
147
182
|
hasRDFaAttribute(node, 'datatype', XSD('date')) ||
|
|
148
183
|
hasRDFaAttribute(node, 'datatype', XSD('dateTime'))
|
|
149
184
|
) {
|
|
150
|
-
const onlyDate = hasRDFaAttribute(node, 'datatype', XSD('date'));
|
|
151
185
|
const content = node.getAttribute('content') ?? undefined;
|
|
152
186
|
return createDateVariableAttrs({
|
|
153
187
|
variable: generateVariableUri(),
|
|
@@ -155,7 +189,6 @@ const parseDOMLegacy = [
|
|
|
155
189
|
format: node.dataset.format,
|
|
156
190
|
custom: node.dataset.custom === 'true',
|
|
157
191
|
customAllowed: node.dataset.customAllowed !== 'false',
|
|
158
|
-
onlyDate,
|
|
159
192
|
value: content,
|
|
160
193
|
});
|
|
161
194
|
}
|
|
@@ -182,9 +215,6 @@ const parseDOMLegacy = [
|
|
|
182
215
|
if (!variableUri) {
|
|
183
216
|
return false;
|
|
184
217
|
}
|
|
185
|
-
const onlyDate = !![...node.children].find((el) =>
|
|
186
|
-
hasRDFaAttribute(el, 'datatype', XSD('date')),
|
|
187
|
-
);
|
|
188
218
|
const dateNode = [...node.children].find((el) =>
|
|
189
219
|
hasRDFaAttribute(el, 'property', EXT('content')),
|
|
190
220
|
) as HTMLElement | undefined;
|
|
@@ -197,7 +227,6 @@ const parseDOMLegacy = [
|
|
|
197
227
|
format,
|
|
198
228
|
custom: node.dataset.custom === 'true',
|
|
199
229
|
customAllowed: node.dataset.customAllowed !== 'false',
|
|
200
|
-
onlyDate,
|
|
201
230
|
value,
|
|
202
231
|
label,
|
|
203
232
|
});
|
|
@@ -210,14 +239,11 @@ const parseDOMLegacy = [
|
|
|
210
239
|
|
|
211
240
|
const serialize = (node: PNode, state: EditorState) => {
|
|
212
241
|
const t = getTranslationFunction(state);
|
|
213
|
-
const
|
|
214
|
-
// TODO Could remove the custom 'onlyDate' attr and instead use the datatype of the outgoing
|
|
215
|
-
// content triple.
|
|
216
|
-
const { onlyDate, format, custom, customAllowed } = node.attrs;
|
|
242
|
+
const { format, custom, customAllowed, content } = node.attrs;
|
|
217
243
|
let humanReadableDate: string;
|
|
218
|
-
if (
|
|
244
|
+
if (content) {
|
|
219
245
|
if (validateDateFormat(format).type === 'ok') {
|
|
220
|
-
humanReadableDate = formatDate(new Date(
|
|
246
|
+
humanReadableDate = formatDate(new Date(content), format);
|
|
221
247
|
} else {
|
|
222
248
|
humanReadableDate = t(
|
|
223
249
|
'date-plugin.validation.unknown',
|
|
@@ -225,15 +251,18 @@ const serialize = (node: PNode, state: EditorState) => {
|
|
|
225
251
|
);
|
|
226
252
|
}
|
|
227
253
|
} else {
|
|
228
|
-
humanReadableDate = (
|
|
254
|
+
humanReadableDate = !formatContainsTime(format)
|
|
229
255
|
? t('date-plugin.insert.date', TRANSLATION_FALLBACKS.insertDate)
|
|
230
256
|
: t('date-plugin.insert.datetime', TRANSLATION_FALLBACKS.insertDateTime);
|
|
231
257
|
}
|
|
232
258
|
const dateAttrs = {
|
|
233
|
-
class:
|
|
259
|
+
class: content ? '' : 'say-variable',
|
|
260
|
+
'data-say-variable': 'true',
|
|
261
|
+
'data-say-variable-type': 'date',
|
|
234
262
|
'data-format': format as string,
|
|
235
263
|
'data-custom': custom ? 'true' : 'false',
|
|
236
264
|
'data-custom-allowed': customAllowed ? 'true' : 'false',
|
|
265
|
+
'data-label': node.attrs['label'],
|
|
237
266
|
};
|
|
238
267
|
return renderRdfaAware({
|
|
239
268
|
renderable: node,
|
|
@@ -256,6 +285,10 @@ const emberNodeConfig = (options: DateOptions): EmberNodeConfig => ({
|
|
|
256
285
|
defining: false,
|
|
257
286
|
options,
|
|
258
287
|
attrs: {
|
|
288
|
+
...rdfaAttrSpec({ rdfaAware }),
|
|
289
|
+
label: {
|
|
290
|
+
default: null,
|
|
291
|
+
},
|
|
259
292
|
format: {
|
|
260
293
|
default: options.formats[0].dateFormat,
|
|
261
294
|
},
|
|
@@ -268,22 +301,23 @@ const emberNodeConfig = (options: DateOptions): EmberNodeConfig => ({
|
|
|
268
301
|
customAllowed: {
|
|
269
302
|
default: options.allowCustomFormat,
|
|
270
303
|
},
|
|
271
|
-
|
|
304
|
+
datatype: {
|
|
305
|
+
default: !formatContainsTime(options.formats[0].dateFormat)
|
|
306
|
+
? XSD('date').namedNode
|
|
307
|
+
: XSD('dateTime').namedNode,
|
|
308
|
+
},
|
|
272
309
|
},
|
|
273
310
|
outlineText: (node: PNode, state: EditorState) => {
|
|
274
311
|
const t = getTranslationFunction(state);
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
const
|
|
312
|
+
const { format, content } = node.attrs;
|
|
313
|
+
|
|
314
|
+
const placeholder = !formatContainsTime(format)
|
|
315
|
+
? t('date-plugin.insert.date', TRANSLATION_FALLBACKS.insertDate)
|
|
316
|
+
: t('date-plugin.insert.datetime', TRANSLATION_FALLBACKS.insertDateTime);
|
|
278
317
|
|
|
279
|
-
const humanReadableDate =
|
|
280
|
-
? formatDate(new Date(
|
|
281
|
-
:
|
|
282
|
-
? t('date-plugin.insert.date', TRANSLATION_FALLBACKS.insertDate)
|
|
283
|
-
: t(
|
|
284
|
-
'date-plugin.insert.datetime',
|
|
285
|
-
TRANSLATION_FALLBACKS.insertDateTime,
|
|
286
|
-
);
|
|
318
|
+
const humanReadableDate = content
|
|
319
|
+
? formatDate(new Date(content), format)
|
|
320
|
+
: placeholder;
|
|
287
321
|
|
|
288
322
|
return humanReadableDate;
|
|
289
323
|
},
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
+
DCT,
|
|
2
3
|
EXT,
|
|
3
4
|
RDF,
|
|
4
5
|
VARIABLES,
|
|
6
|
+
XSD,
|
|
5
7
|
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
|
|
6
8
|
import {
|
|
7
9
|
createEmberNodeSpec,
|
|
@@ -25,10 +27,13 @@ import {
|
|
|
25
27
|
import NodeViewComponent from '@lblod/ember-rdfa-editor-lblod-plugins/components/variable-plugin/variable/nodeview';
|
|
26
28
|
import type { ComponentLike } from '@glint/template';
|
|
27
29
|
import { recreateVariableUris } from '../utils/recreate-variable-uris';
|
|
28
|
-
import { hasOutgoingNamedNodeTriple } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/namespace';
|
|
29
30
|
import { renderRdfaAware } from '@lblod/ember-rdfa-editor/core/schema';
|
|
30
31
|
import { createClassicLocationVariableAttrs } from '../actions/create-classic-location-variable';
|
|
31
32
|
import { generateVariableInstanceUri } from '../utils/variable-helpers';
|
|
33
|
+
import {
|
|
34
|
+
getOutgoingTriple,
|
|
35
|
+
hasOutgoingNamedNodeTriple,
|
|
36
|
+
} from '@lblod/ember-rdfa-editor-lblod-plugins/utils/namespace';
|
|
32
37
|
|
|
33
38
|
const CONTENT_SELECTOR = '[data-content-container="true"]';
|
|
34
39
|
|
|
@@ -45,6 +50,30 @@ const parseDOM = [
|
|
|
45
50
|
if (!attrs) {
|
|
46
51
|
return false;
|
|
47
52
|
}
|
|
53
|
+
if (
|
|
54
|
+
node.dataset.sayVariable &&
|
|
55
|
+
node.dataset.sayVariableType === 'location' &&
|
|
56
|
+
node.querySelector(CONTENT_SELECTOR)
|
|
57
|
+
) {
|
|
58
|
+
const label = node.dataset.label;
|
|
59
|
+
const source = node.dataset.source;
|
|
60
|
+
return { ...attrs, label, source };
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
},
|
|
64
|
+
contentElement: CONTENT_SELECTOR,
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
const parseDOMLegacy = [
|
|
69
|
+
{
|
|
70
|
+
tag: 'span',
|
|
71
|
+
getAttrs: (node: HTMLElement) => {
|
|
72
|
+
const attrs = getRdfaAttrs(node, { rdfaAware });
|
|
73
|
+
if (!attrs || attrs.rdfaNodeType !== 'resource') {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
|
|
48
77
|
if (
|
|
49
78
|
hasOutgoingNamedNodeTriple(
|
|
50
79
|
attrs,
|
|
@@ -54,18 +83,27 @@ const parseDOM = [
|
|
|
54
83
|
node.querySelector(CONTENT_SELECTOR) &&
|
|
55
84
|
hasRdfaVariableType(attrs, 'location')
|
|
56
85
|
) {
|
|
57
|
-
|
|
86
|
+
const variableInstanceUri = attrs.subject;
|
|
87
|
+
const variableUri = getOutgoingTriple(attrs, VARIABLES('instanceOf'))
|
|
88
|
+
?.object.value;
|
|
89
|
+
if (!variableInstanceUri || !variableUri) {
|
|
58
90
|
return false;
|
|
59
91
|
}
|
|
60
|
-
|
|
92
|
+
|
|
93
|
+
const sourceUri = getOutgoingTriple(attrs, DCT('source'))?.object.value;
|
|
94
|
+
const label = getOutgoingTriple(attrs, DCT('title'))?.object.value;
|
|
95
|
+
|
|
96
|
+
return createClassicLocationVariableAttrs({
|
|
97
|
+
variable: variableUri,
|
|
98
|
+
variableInstance: variableInstanceUri,
|
|
99
|
+
label,
|
|
100
|
+
source: sourceUri,
|
|
101
|
+
});
|
|
61
102
|
}
|
|
62
103
|
return false;
|
|
63
104
|
},
|
|
64
105
|
contentElement: CONTENT_SELECTOR,
|
|
65
106
|
},
|
|
66
|
-
];
|
|
67
|
-
|
|
68
|
-
const parseDOMLegacy = [
|
|
69
107
|
{
|
|
70
108
|
tag: 'span',
|
|
71
109
|
getAttrs: (node: HTMLElement) => {
|
|
@@ -104,10 +142,15 @@ const toDOM = (node: PNode): DOMOutputSpec => {
|
|
|
104
142
|
onlyContentType === onlyContentType.schema.nodes['placeholder']
|
|
105
143
|
? 'say-variable'
|
|
106
144
|
: '';
|
|
145
|
+
const { label, source } = node.attrs;
|
|
107
146
|
return renderRdfaAware({
|
|
108
147
|
renderable: node,
|
|
109
148
|
attrs: {
|
|
110
149
|
class: className,
|
|
150
|
+
'data-say-variable': 'true',
|
|
151
|
+
'data-say-variable-type': 'location',
|
|
152
|
+
'data-label': label,
|
|
153
|
+
'data-source': source,
|
|
111
154
|
},
|
|
112
155
|
tag: 'span',
|
|
113
156
|
content: 0,
|
|
@@ -128,6 +171,13 @@ const emberNodeConfig: EmberNodeConfig = {
|
|
|
128
171
|
needsFFKludge: true,
|
|
129
172
|
attrs: {
|
|
130
173
|
...rdfaAttrSpec({ rdfaAware }),
|
|
174
|
+
label: {
|
|
175
|
+
default: null,
|
|
176
|
+
},
|
|
177
|
+
source: {},
|
|
178
|
+
datatype: {
|
|
179
|
+
default: XSD('string').namedNode,
|
|
180
|
+
},
|
|
131
181
|
},
|
|
132
182
|
toDOM,
|
|
133
183
|
parseDOM: [...parseDOM, ...parseDOMLegacy],
|