@lblod/ember-rdfa-editor-lblod-plugins 33.3.0 → 34.0.1

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.
Files changed (31) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/addon/components/variable-plugin/codelist/edit.gts +48 -9
  3. package/addon/components/variable-plugin/codelist/{insert.ts → insert.gts} +52 -7
  4. package/addon/components/variable-plugin/codelist/nodeview.gts +49 -0
  5. package/addon/components/variable-plugin/location/edit.ts +3 -4
  6. package/addon/plugins/roadsign-regulation-plugin/actions/insert-measure.ts +25 -4
  7. package/addon/plugins/roadsign-regulation-plugin/schemas/variable.ts +1 -1
  8. package/addon/plugins/variable-plugin/actions/create-codelist-variable.ts +57 -40
  9. package/addon/plugins/variable-plugin/actions/create-legacy-codelist-variable.ts +101 -0
  10. package/addon/plugins/variable-plugin/utils/codelist-utils.ts +38 -3
  11. package/addon/plugins/variable-plugin/utils/fetch-data.ts +37 -15
  12. package/addon/plugins/variable-plugin/variables/codelist.ts +101 -175
  13. package/addon/plugins/variable-plugin/variables/legacy-codelist.ts +261 -0
  14. package/addon/utils/constants.ts +4 -0
  15. package/declarations/addon/components/variable-plugin/codelist/edit.d.ts +2 -0
  16. package/declarations/addon/components/variable-plugin/codelist/insert.d.ts +15 -9
  17. package/declarations/addon/components/variable-plugin/codelist/nodeview.d.ts +18 -0
  18. package/declarations/addon/plugins/roadsign-regulation-plugin/actions/insert-measure.d.ts +2 -1
  19. package/declarations/addon/plugins/roadsign-regulation-plugin/queries/variable.d.ts +6 -6
  20. package/declarations/addon/plugins/roadsign-regulation-plugin/schemas/variable-instance.d.ts +25 -25
  21. package/declarations/addon/plugins/roadsign-regulation-plugin/schemas/variable.d.ts +36 -36
  22. package/declarations/addon/plugins/variable-plugin/actions/create-codelist-variable.d.ts +20 -11
  23. package/declarations/addon/plugins/variable-plugin/actions/create-legacy-codelist-variable.d.ts +28 -0
  24. package/declarations/addon/plugins/variable-plugin/utils/codelist-utils.d.ts +7 -0
  25. package/declarations/addon/plugins/variable-plugin/utils/fetch-data.d.ts +3 -2
  26. package/declarations/addon/plugins/variable-plugin/variables/codelist.d.ts +3 -1
  27. package/declarations/addon/plugins/variable-plugin/variables/legacy-codelist.d.ts +2 -0
  28. package/declarations/addon/utils/constants.d.ts +1 -0
  29. package/docs/plugins/variable.md +1 -0
  30. package/package.json +1 -1
  31. package/addon/components/variable-plugin/codelist/insert.hbs +0 -31
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @lblod/ember-rdfa-editor-lblod-plugins
2
2
 
3
+ ## 34.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#615](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/615) [`29ed983`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/29ed98336174e12667195f4b28cb9502b10cb479) Thanks [@elpoelma](https://github.com/elpoelma)! - Add missing `toDOM` method to `codelist_option` nodespec
8
+
9
+ ## 34.0.0
10
+
11
+ ### Major Changes
12
+
13
+ - [#610](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/610) [`2f70345`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/2f7034552c477920d75ebf9dfff0f84bac7fba9a) Thanks [@elpoelma](https://github.com/elpoelma)! - Introduce new `codelist` variable which stores either a single or multiple `codelist_option` nodes.
14
+ Each `codelist_option` node is a resource node which represents a selected codelist-option, and a variable instance.
15
+ The `codelist` variable node itself is more of a container node and does not store any RDFa.
16
+ The old `codelist` variable node is renamed to `legacy_codelist`, and can still be used with the existing `codelist-edit` widget.
17
+ `legacy_codelist` nodes will not be automatically converted to new `codelist` nodes, as we lack the necessary information to do so (codelist-option URIs).
18
+
19
+ ## 33.4.0
20
+
21
+ ### Minor Changes
22
+
23
+ - [#614](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/614) [`a3d02d2`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/a3d02d2d456f4c9925cbd609ed14cfcb0b800195) Thanks [@piemonkey](https://github.com/piemonkey)! - When inserting traffic measures, filter 'zonebord' signs from the list
24
+
25
+ - [#613](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/613) [`770636c`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/770636ca8ec292930c2ff01dfcb8b20c5737251d) Thanks [@piemonkey](https://github.com/piemonkey)! - When inserting an AR design, include the link to the design in the RDFa
26
+
3
27
  ## 33.3.0
4
28
 
5
29
  ### Minor Changes
@@ -13,9 +13,11 @@ import {
13
13
  import { MULTI_SELECT_CODELIST_TYPE } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/constants';
14
14
  import { NodeSelection } from '@lblod/ember-rdfa-editor';
15
15
  import { trackedFunction } from 'reactiveweb/function';
16
- import { updateCodelistVariable } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/codelist-utils';
16
+ import {
17
+ updateCodelistVariable,
18
+ updateCodelistVariableLegacy,
19
+ } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/codelist-utils';
17
20
  import { Option } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/option';
18
- import { tracked } from '@glimmer/tracking';
19
21
  import AuCard from '@appuniversum/ember-appuniversum/components/au-card';
20
22
  import AuHeading from '@appuniversum/ember-appuniversum/components/au-heading';
21
23
  import AuLabel from '@appuniversum/ember-appuniversum/components/au-label';
@@ -23,6 +25,7 @@ import PowerSelectMultiple from 'ember-power-select/components/power-select-mult
23
25
  import AuButton from '@appuniversum/ember-appuniversum/components/au-button';
24
26
  import { AlertTriangleIcon } from '@appuniversum/ember-appuniversum/components/icons/alert-triangle';
25
27
  import AuAlert from '@appuniversum/ember-appuniversum/components/au-alert';
28
+ import { tracked } from '@glimmer/tracking';
26
29
 
27
30
  export type CodelistEditOptions = {
28
31
  endpoint: string;
@@ -35,17 +38,26 @@ type Sig = {
35
38
  };
36
39
 
37
40
  export default class CodelistEditComponent extends Component<Sig> {
38
- @tracked selectedCodelistOption?: CodeListOption | CodeListOption[];
41
+ @tracked
42
+ selectedCodelistOption?: CodeListOption | CodeListOption[];
39
43
 
40
44
  get controller() {
41
45
  return this.args.controller;
42
46
  }
43
47
 
48
+ get isLegacyCodelist() {
49
+ return (
50
+ this.selectedCodelist?.node.type ===
51
+ this.controller.schema.nodes.legacy_codelist
52
+ );
53
+ }
54
+
44
55
  get selectedCodelist() {
45
56
  const { selection } = this.controller.mainEditorState;
46
57
  if (
47
58
  selection instanceof NodeSelection &&
48
- selection.node.type === this.controller.schema.nodes.codelist
59
+ (selection.node.type === this.controller.schema.nodes.codelist ||
60
+ selection.node.type === this.controller.schema.nodes.legacy_codelist)
49
61
  ) {
50
62
  const codelist = {
51
63
  node: selection.node,
@@ -86,6 +98,10 @@ export default class CodelistEditComponent extends Component<Sig> {
86
98
  return this.selectedCodelist?.node.attrs.label as string | undefined;
87
99
  }
88
100
 
101
+ get schema() {
102
+ return this.args.controller.schema;
103
+ }
104
+
89
105
  codelistOptions = trackedFunction(this, async () => {
90
106
  let result: CodeListOptions | undefined;
91
107
  if (this.source && this.codelistUri) {
@@ -95,6 +111,21 @@ export default class CodelistEditComponent extends Component<Sig> {
95
111
  // Normally we'd do this with a `trackedReset`, but this gave us `write-after-read` dev-errors at the time of writing this.
96
112
  // TODO: convert this back to a `trackedReset` (or an alternative) once possible.
97
113
  this.selectedCodelistOption = undefined;
114
+ const codelistNode = this.selectedCodelist?.node;
115
+ if (
116
+ !this.isLegacyCodelist &&
117
+ codelistNode &&
118
+ codelistNode.children.length > 0
119
+ ) {
120
+ const options = codelistNode.children.map((child) => ({
121
+ uri: child.attrs['subject'],
122
+ label: child.textContent,
123
+ }));
124
+ this.selectedCodelistOption = this.multiSelect ? options : options[0];
125
+ } else {
126
+ this.selectedCodelistOption = undefined;
127
+ }
128
+
98
129
  return result;
99
130
  });
100
131
 
@@ -112,11 +143,19 @@ export default class CodelistEditComponent extends Component<Sig> {
112
143
  if (!this.selectedCodelist || !this.selectedCodelistOption) {
113
144
  return;
114
145
  }
115
- updateCodelistVariable(
116
- this.selectedCodelist,
117
- this.selectedCodelistOption,
118
- this.controller,
119
- );
146
+ if (this.isLegacyCodelist) {
147
+ updateCodelistVariableLegacy(
148
+ this.selectedCodelist,
149
+ this.selectedCodelistOption,
150
+ this.controller,
151
+ );
152
+ } else {
153
+ updateCodelistVariable(
154
+ this.selectedCodelist,
155
+ this.selectedCodelistOption,
156
+ this.controller,
157
+ );
158
+ }
120
159
  }
121
160
 
122
161
  @action
@@ -10,6 +10,13 @@ import { service } from '@ember/service';
10
10
  import IntlService from 'ember-intl/services/intl';
11
11
  import { trackedFunction } from 'reactiveweb/function';
12
12
  import { replaceSelectionWithAndSelectNode } from '@lblod/ember-rdfa-editor-lblod-plugins/commands';
13
+ import PowerSelect from 'ember-power-select/components/power-select';
14
+ import AuFormRow from '@appuniversum/ember-appuniversum/components/au-form-row';
15
+ import AuButton from '@appuniversum/ember-appuniversum/components/au-button';
16
+ import { on } from '@ember/modifier';
17
+ import { not } from 'ember-truth-helpers';
18
+ import t from 'ember-intl/helpers/t';
19
+ import LabelInput from '../utils/label-input';
13
20
  import { createCodelistVariable } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/actions/create-codelist-variable';
14
21
 
15
22
  export type CodelistInsertOptions = {
@@ -25,14 +32,14 @@ type Args = {
25
32
 
26
33
  interface SelectStyle {
27
34
  label: string;
28
- value: string;
35
+ value: 'single' | 'multi';
29
36
  }
30
37
 
31
38
  export default class CodelistInsertComponent extends Component<Args> {
32
39
  @service declare intl: IntlService;
33
40
  @tracked selectedCodelist?: CodeList;
34
- @tracked label?: string;
35
- @tracked selectedStyleValue = 'single';
41
+ @tracked label: string = '';
42
+ @tracked selectedStyleValue: 'single' | 'multi' = 'single';
36
43
 
37
44
  get controller() {
38
45
  return this.args.controller;
@@ -58,11 +65,11 @@ export default class CodelistInsertComponent extends Component<Args> {
58
65
  const singleSelect = {
59
66
  label: this.intl.t('variable.codelist.single-select'),
60
67
  value: 'single',
61
- };
68
+ } as const;
62
69
  const multiSelect = {
63
70
  label: this.intl.t('variable.codelist.multi-select'),
64
71
  value: 'multi',
65
- };
72
+ } as const;
66
73
  return [singleSelect, multiSelect];
67
74
  }
68
75
 
@@ -84,6 +91,9 @@ export default class CodelistInsertComponent extends Component<Args> {
84
91
  @action
85
92
  insert() {
86
93
  const codelistResource = this.selectedCodelist?.uri;
94
+ if (!codelistResource) {
95
+ return;
96
+ }
87
97
  const label =
88
98
  this.label ??
89
99
  this.selectedCodelist?.label ??
@@ -96,10 +106,10 @@ export default class CodelistInsertComponent extends Component<Args> {
96
106
  selectionStyle: this.selectedStyleValue,
97
107
  codelist: codelistResource,
98
108
  source,
99
- label,
109
+ label: label ?? this.selectedCodelist?.label,
100
110
  });
101
111
 
102
- this.label = undefined;
112
+ this.label = '';
103
113
  this.controller.doCommand(replaceSelectionWithAndSelectNode(node), {
104
114
  view: this.controller.mainEditorView,
105
115
  });
@@ -114,4 +124,39 @@ export default class CodelistInsertComponent extends Component<Args> {
114
124
  selectStyle(style: SelectStyle) {
115
125
  this.selectedStyleValue = style.value;
116
126
  }
127
+
128
+ <template>
129
+ {{#if this.codelistData.value}}
130
+ <PowerSelect
131
+ @allowClear={{false}}
132
+ @searchEnabled={{true}}
133
+ @searchField='label'
134
+ @options={{this.codelistData.value}}
135
+ @selected={{this.selectedCodelist}}
136
+ @onChange={{this.selectCodelist}}
137
+ as |codelist|
138
+ >
139
+ {{codelist.label}}
140
+ </PowerSelect>
141
+ <PowerSelect
142
+ @allowClear={{false}}
143
+ @searchEnabled={{false}}
144
+ @options={{this.selectionStyles}}
145
+ @selected={{this.selectedStyle}}
146
+ @onChange={{this.selectStyle}}
147
+ as |style|
148
+ >
149
+ {{style.label}}
150
+ </PowerSelect>
151
+ <AuFormRow>
152
+ <LabelInput @label={{this.label}} @updateLabel={{this.updateLabel}} />
153
+ </AuFormRow>
154
+ <AuButton
155
+ {{on 'click' this.insert}}
156
+ @disabled={{not this.selectedCodelist}}
157
+ >
158
+ {{t 'variable-plugin.button'}}
159
+ </AuButton>
160
+ {{/if}}
161
+ </template>
117
162
  }
@@ -0,0 +1,49 @@
1
+ import Component from '@glimmer/component';
2
+ import {
3
+ DecorationSource,
4
+ PNode,
5
+ SayController,
6
+ SayView,
7
+ } from '@lblod/ember-rdfa-editor';
8
+ import getClassnamesFromNode from '@lblod/ember-rdfa-editor/utils/get-classnames-from-node';
9
+ import AuPill from '@appuniversum/ember-appuniversum/components/au-pill';
10
+ import { on } from '@ember/modifier';
11
+
12
+ type Args = {
13
+ getPos: () => number | undefined;
14
+ node: PNode;
15
+ selectNode: () => void;
16
+ updateAttribute: (attr: string, value: unknown) => void;
17
+ controller: SayController;
18
+ view: SayView;
19
+ selected: boolean;
20
+ contentDecorations?: DecorationSource;
21
+ };
22
+
23
+ export default class CodelistNodeviewComponent extends Component<Args> {
24
+ get filled() {
25
+ return this.args.node.childCount !== 0;
26
+ }
27
+
28
+ get humanReadableCodelistOption() {
29
+ if (this.filled) {
30
+ return this.args.node.children
31
+ .map((child) => child.textContent)
32
+ .join(', ');
33
+ } else {
34
+ return this.args.node.attrs['label'];
35
+ }
36
+ }
37
+
38
+ get class() {
39
+ return getClassnamesFromNode(this.args.node);
40
+ }
41
+
42
+ <template>
43
+ <AuPill class='{{this.class}} say-pill atomic' {{on 'click' @selectNode}}>
44
+ <span class='{{unless this.filled "unfilled-variable"}}'>
45
+ {{this.humanReadableCodelistOption}}
46
+ </span>
47
+ </AuPill>
48
+ </template>
49
+ }
@@ -8,9 +8,8 @@ import {
8
8
  import { MULTI_SELECT_CODELIST_TYPE } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/constants';
9
9
  import { findParentNode } from '@curvenote/prosemirror-utils';
10
10
  import { NodeSelection } from '@lblod/ember-rdfa-editor';
11
- import { unwrap } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/option';
12
11
  import { trackedFunction } from 'reactiveweb/function';
13
- import { updateCodelistVariable } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/codelist-utils';
12
+ import { updateCodelistVariableLegacy } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/codelist-utils';
14
13
  import { tracked } from '@glimmer/tracking';
15
14
  import {
16
15
  ZONALITY_OPTIONS,
@@ -52,7 +51,7 @@ export default class LocationEditComponent extends Component<Args> {
52
51
  if (!this.selectedLocation || !this.selectedLocationOption) {
53
52
  return;
54
53
  }
55
- updateCodelistVariable(
54
+ updateCodelistVariableLegacy(
56
55
  this.selectedLocation,
57
56
  this.selectedLocationOption,
58
57
  this.controller,
@@ -126,8 +125,8 @@ export default class LocationEditComponent extends Component<Args> {
126
125
  : this.options.nonZonalLocationCodelistUri,
127
126
  );
128
127
  result.options = result.options.map((option) => ({
128
+ uri: option.uri,
129
129
  label: option.label,
130
- value: unwrap(option.value),
131
130
  }));
132
131
  // This a workaround/hack to be able to reset the `selected` option after the `locationOptions` change.
133
132
  // Normally we'd do this with a `trackedReset`, but this gave us `write-after-read` dev-errors at the time of writing this.
@@ -7,10 +7,12 @@ import {
7
7
  } from '@lblod/ember-rdfa-editor';
8
8
  import { v4 as uuid } from 'uuid';
9
9
  import { addPropertyToNode } from '@lblod/ember-rdfa-editor/utils/rdfa-utils';
10
+ import { type FullTriple } from '@lblod/ember-rdfa-editor/core/rdfa-processor';
10
11
  import {
11
12
  DCT,
12
13
  EXT,
13
14
  MOBILITEIT,
15
+ ONDERDEEL,
14
16
  PROV,
15
17
  RDF,
16
18
  } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
@@ -36,7 +38,6 @@ import { createTextVariable } from '../../variable-plugin/actions/create-text-va
36
38
  import { generateVariableInstanceUri } from '../../variable-plugin/utils/variable-helpers';
37
39
  import { createNumberVariable } from '../../variable-plugin/actions/create-number-variable';
38
40
  import { createDateVariable } from '../../variable-plugin/actions/create-date-variable';
39
- import { createCodelistVariable } from '../../variable-plugin/actions/create-codelist-variable';
40
41
  import { createClassicLocationVariable } from '../../variable-plugin/actions/create-classic-location-variable';
41
42
  import { isTrafficSignal, TrafficSignal } from '../schemas/traffic-signal';
42
43
  import { MobilityMeasureDesign } from '../schemas/mobility-measure-design';
@@ -44,8 +45,10 @@ import {
44
45
  isVariableInstance,
45
46
  VariableInstance,
46
47
  } from '../schemas/variable-instance';
48
+ import { createCodelistVariable } from '../../variable-plugin/actions/create-codelist-variable';
47
49
 
48
50
  type InsertMeasureArgs = {
51
+ arDesignUri?: string;
49
52
  zonality: ZonalOrNot;
50
53
  temporal: boolean;
51
54
  variables: Record<
@@ -65,6 +68,7 @@ type InsertMeasureArgs = {
65
68
  );
66
69
 
67
70
  export default function insertMeasure({
71
+ arDesignUri,
68
72
  zonality,
69
73
  temporal,
70
74
  variables,
@@ -79,10 +83,26 @@ export default function insertMeasure({
79
83
  ? args.measureConcept
80
84
  : args.measureDesign.measureConcept;
81
85
  const measureDesign = 'measureDesign' in args && args.measureDesign;
86
+ const externalTriples: FullTriple[] | undefined =
87
+ !arDesignUri || !measureDesign
88
+ ? undefined
89
+ : [
90
+ {
91
+ subject: sayDataFactory.namedNode(arDesignUri),
92
+ predicate: ONDERDEEL('BevatMaatregelOntwerp').full,
93
+ object: sayDataFactory.namedNode(measureDesign.uri),
94
+ },
95
+ ];
82
96
  const { schema } = state;
83
- const signNodes = measureConcept.trafficSignalConcepts.map((signConcept) =>
84
- constructSignalNode(signConcept, schema, zonality),
85
- );
97
+ const signNodes = measureConcept.trafficSignalConcepts
98
+ .filter(
99
+ (signConcept) =>
100
+ signConcept.type !== TRAFFIC_SIGNAL_CONCEPT_TYPES.ROAD_SIGN ||
101
+ !signConcept.categories.some(
102
+ (cat) => cat.uri === ROAD_SIGN_CATEGORIES.ZONEBORD,
103
+ ),
104
+ )
105
+ .map((signConcept) => constructSignalNode(signConcept, schema, zonality));
86
106
  let signSection: PNode[] = [];
87
107
  if (signNodes.length) {
88
108
  const signList = schema.nodes.bullet_list.create(
@@ -150,6 +170,7 @@ export default function insertMeasure({
150
170
  // mobiliteit:periode, mobiliteit:plaatsbepaling, schema:eventSchedule, mobiliteit:type,
151
171
  // mobiliteit:verwijstNaar, mobiliteit:heeftGevolg
152
172
  ],
173
+ externalTriples,
153
174
  },
154
175
  [measureBody, ...signSection, ...(temporalNode ? [temporalNode] : [])],
155
176
  );
@@ -3,7 +3,7 @@ import { z } from 'zod';
3
3
  const BaseVariableSchema = z.object({
4
4
  uri: z.string(),
5
5
  label: z.string(),
6
- source: z.string().optional(),
6
+ source: z.string(),
7
7
  });
8
8
  export const TextVariableSchema = BaseVariableSchema.extend({
9
9
  type: z.literal('text'),
@@ -1,53 +1,44 @@
1
1
  import { Schema } from '@lblod/ember-rdfa-editor';
2
2
  import {
3
3
  DCT,
4
- MOBILITEIT,
5
4
  RDF,
5
+ SKOS,
6
6
  VARIABLES,
7
- XSD,
8
7
  } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
9
8
  import { AllOrNone } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/types';
10
9
  import {
11
10
  FullTriple,
12
11
  IncomingTriple,
12
+ OutgoingTriple,
13
13
  } from '@lblod/ember-rdfa-editor/core/rdfa-processor';
14
14
  import { sayDataFactory } from '@lblod/ember-rdfa-editor/core/say-data-factory';
15
15
 
16
16
  type CreateCodelistVariableArgs = {
17
17
  schema: Schema;
18
- value?: string;
19
18
  } & CreateCodelistVariableAttrsArgs;
20
19
 
21
20
  export function createCodelistVariable(args: CreateCodelistVariableArgs) {
22
- const { schema, value, label } = args;
21
+ const { schema } = args;
23
22
  const attrs = createCodelistVariableAttrs(args);
24
- return schema.nodes.codelist.create(
25
- attrs,
26
- value
27
- ? schema.text(value)
28
- : schema.node('placeholder', {
29
- placeholderText: label,
30
- }),
31
- );
23
+ return schema.nodes.codelist.create(attrs);
32
24
  }
33
25
 
34
26
  type CreateCodelistVariableAttrsArgs = {
27
+ selectionStyle?: 'single' | 'multi';
35
28
  label?: string;
36
- source?: string;
37
- codelist?: string;
38
- selectionStyle?: string;
29
+ source: string;
30
+ codelist: string;
39
31
  } & AllOrNone<{ variable: string; variableInstance: string }>;
40
32
 
41
33
  export function createCodelistVariableAttrs({
42
- variable,
43
- variableInstance,
34
+ selectionStyle,
44
35
  label,
45
36
  source,
46
37
  codelist,
47
- selectionStyle,
38
+ variable,
39
+ variableInstance,
48
40
  }: CreateCodelistVariableAttrsArgs) {
49
41
  const externalTriples: FullTriple[] = [];
50
- const backlinks: IncomingTriple[] = [];
51
42
  if (variable) {
52
43
  externalTriples.push(
53
44
  {
@@ -66,34 +57,60 @@ export function createCodelistVariableAttrs({
66
57
  object: sayDataFactory.literal('codelist'),
67
58
  },
68
59
  );
69
- if (codelist) {
70
- externalTriples.push({
71
- subject: sayDataFactory.namedNode(variableInstance),
72
- predicate: MOBILITEIT('codelijst').full,
73
- object: sayDataFactory.namedNode(codelist),
74
- });
75
- }
76
- if (source) {
77
- externalTriples.push({
78
- subject: sayDataFactory.namedNode(variableInstance),
79
- predicate: DCT('source').full,
80
- object: sayDataFactory.namedNode(source),
81
- });
82
- }
83
- backlinks.push({
84
- subject: sayDataFactory.resourceNode(variableInstance),
85
- predicate: RDF('value').full,
86
- });
87
60
  }
88
61
 
89
62
  return {
90
63
  rdfaNodeType: 'literal',
91
- datatype: XSD('string').namedNode,
92
64
  externalTriples,
93
- backlinks,
65
+ selectionStyle,
94
66
  source,
95
67
  codelist,
96
68
  label,
97
- selectionStyle,
69
+ variable,
70
+ variableInstance,
71
+ };
72
+ }
73
+
74
+ type CreateCodelistOptionNodeArgs = {
75
+ schema: Schema;
76
+ text: string;
77
+ } & CreateCodelistOptionNodeAttrsArgs;
78
+
79
+ export function createCodelistOptionNode(args: CreateCodelistOptionNodeArgs) {
80
+ const { schema, text } = args;
81
+ const attrs = createCodelistOptionNodeAttrs(args);
82
+ return schema.nodes.codelist_option.create(attrs, schema.text(text));
83
+ }
84
+
85
+ type CreateCodelistOptionNodeAttrsArgs = {
86
+ subject: string;
87
+ text: string;
88
+ variableInstance?: string;
89
+ };
90
+
91
+ function createCodelistOptionNodeAttrs({
92
+ subject,
93
+ text,
94
+ variableInstance,
95
+ }: CreateCodelistOptionNodeAttrsArgs) {
96
+ const backlinks: IncomingTriple[] = [];
97
+ if (variableInstance) {
98
+ backlinks.push({
99
+ subject: sayDataFactory.resourceNode(variableInstance),
100
+ predicate: RDF('value').full,
101
+ });
102
+ }
103
+ const properties: OutgoingTriple[] = [
104
+ {
105
+ predicate: SKOS('prefLabel').full,
106
+ object: sayDataFactory.literal(text),
107
+ },
108
+ ];
109
+
110
+ return {
111
+ rdfaNodeType: 'resource',
112
+ subject,
113
+ properties,
114
+ backlinks,
98
115
  };
99
116
  }
@@ -0,0 +1,101 @@
1
+ import { Schema } from '@lblod/ember-rdfa-editor';
2
+ import {
3
+ DCT,
4
+ MOBILITEIT,
5
+ RDF,
6
+ VARIABLES,
7
+ XSD,
8
+ } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
9
+ import { AllOrNone } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/types';
10
+ import {
11
+ FullTriple,
12
+ IncomingTriple,
13
+ } from '@lblod/ember-rdfa-editor/core/rdfa-processor';
14
+ import { sayDataFactory } from '@lblod/ember-rdfa-editor/core/say-data-factory';
15
+
16
+ type CreateLegacyCodelistVariableArgs = {
17
+ schema: Schema;
18
+ value?: string;
19
+ } & CreateLegacyCodelistVariableAttrsArgs;
20
+
21
+ export function createLegacyCodelistVariable(
22
+ args: CreateLegacyCodelistVariableArgs,
23
+ ) {
24
+ const { schema, value, label } = args;
25
+ const attrs = createLegacyCodelistVariableAttrs(args);
26
+ return schema.nodes.legacy_codelist.create(
27
+ attrs,
28
+ value
29
+ ? schema.text(value)
30
+ : schema.node('placeholder', {
31
+ placeholderText: label,
32
+ }),
33
+ );
34
+ }
35
+
36
+ type CreateLegacyCodelistVariableAttrsArgs = {
37
+ label?: string;
38
+ source?: string;
39
+ codelist?: string;
40
+ selectionStyle?: string;
41
+ } & AllOrNone<{ variable: string; variableInstance: string }>;
42
+
43
+ export function createLegacyCodelistVariableAttrs({
44
+ variable,
45
+ variableInstance,
46
+ label,
47
+ source,
48
+ codelist,
49
+ selectionStyle,
50
+ }: CreateLegacyCodelistVariableAttrsArgs) {
51
+ const externalTriples: FullTriple[] = [];
52
+ const backlinks: IncomingTriple[] = [];
53
+ if (variable) {
54
+ externalTriples.push(
55
+ {
56
+ subject: sayDataFactory.namedNode(variableInstance),
57
+ predicate: RDF('type').full,
58
+ object: sayDataFactory.namedNode(VARIABLES('VariableInstance').full),
59
+ },
60
+ {
61
+ subject: sayDataFactory.namedNode(variableInstance),
62
+ predicate: VARIABLES('instanceOf').full,
63
+ object: sayDataFactory.namedNode(variable),
64
+ },
65
+ {
66
+ subject: sayDataFactory.namedNode(variableInstance),
67
+ predicate: DCT('type').full,
68
+ object: sayDataFactory.literal('codelist'),
69
+ },
70
+ );
71
+ if (codelist) {
72
+ externalTriples.push({
73
+ subject: sayDataFactory.namedNode(variableInstance),
74
+ predicate: MOBILITEIT('codelijst').full,
75
+ object: sayDataFactory.namedNode(codelist),
76
+ });
77
+ }
78
+ if (source) {
79
+ externalTriples.push({
80
+ subject: sayDataFactory.namedNode(variableInstance),
81
+ predicate: DCT('source').full,
82
+ object: sayDataFactory.namedNode(source),
83
+ });
84
+ }
85
+ backlinks.push({
86
+ subject: sayDataFactory.resourceNode(variableInstance),
87
+ predicate: RDF('value').full,
88
+ });
89
+ }
90
+
91
+ return {
92
+ rdfaNodeType: 'literal',
93
+ datatype: XSD('string').namedNode,
94
+ externalTriples,
95
+ backlinks,
96
+ source,
97
+ codelist,
98
+ label,
99
+ selectionStyle,
100
+ };
101
+ }