@lblod/ember-rdfa-editor-lblod-plugins 9.1.1 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/CHANGELOG.md +65 -1
  2. package/README.md +213 -150
  3. package/addon/components/import-snippet-plugin/card.hbs +11 -5
  4. package/addon/components/rdfa-date-plugin/help-modal.hbs +12 -0
  5. package/addon/components/roadsign-regulation-plugin/expanded-measure.hbs +40 -10
  6. package/addon/components/roadsign-regulation-plugin/expanded-measure.ts +1 -0
  7. package/addon/components/roadsign-regulation-plugin/measure-template.ts +6 -12
  8. package/addon/components/roadsign-regulation-plugin/roadsign-regulation-card.hbs +1 -1
  9. package/addon/components/roadsign-regulation-plugin/roadsigns-modal.hbs +5 -5
  10. package/addon/components/roadsign-regulation-plugin/roadsigns-pagination.hbs +4 -4
  11. package/addon/components/roadsign-regulation-plugin/roadsigns-table.hbs +25 -9
  12. package/addon/components/snippet-plugin/search-modal.ts +4 -0
  13. package/addon/components/snippet-plugin/snippet-insert.hbs +1 -0
  14. package/addon/components/snippet-plugin/snippet-insert.ts +14 -11
  15. package/addon/components/snippet-plugin/snippet-list/snippet-list-modal.hbs +80 -0
  16. package/addon/components/snippet-plugin/snippet-list/snippet-list-modal.ts +98 -0
  17. package/addon/components/snippet-plugin/snippet-list/snippet-list-view.hbs +29 -0
  18. package/addon/components/snippet-plugin/snippet-list/snippet-list-view.ts +28 -0
  19. package/addon/components/snippet-plugin/snippet-list-select.hbs +16 -0
  20. package/addon/components/snippet-plugin/snippet-list-select.ts +27 -0
  21. package/addon/components/table-of-contents-plugin/ember-nodes/table-of-contents.hbs +1 -1
  22. package/addon/components/table-of-contents-plugin/ember-nodes/table-of-contents.ts +16 -55
  23. package/addon/components/template-comments-plugin/edit-card.hbs +7 -9
  24. package/addon/components/template-comments-plugin/template-comment.hbs +2 -2
  25. package/addon/components/template-comments-plugin/template-comment.ts +0 -36
  26. package/addon/components/variable-plugin/address/edit.hbs +35 -0
  27. package/addon/components/variable-plugin/address/edit.ts +96 -0
  28. package/addon/components/variable-plugin/address/insert.hbs +9 -0
  29. package/addon/components/variable-plugin/address/insert.ts +37 -0
  30. package/addon/components/variable-plugin/address/nodeview.hbs +19 -0
  31. package/addon/components/variable-plugin/address/nodeview.ts +31 -0
  32. package/addon/components/variable-plugin/{template-variable-card.hbs → codelist/edit.hbs} +14 -12
  33. package/addon/components/variable-plugin/codelist/edit.ts +94 -0
  34. package/addon/components/variable-plugin/codelist/insert.hbs +22 -0
  35. package/addon/components/variable-plugin/codelist/insert.ts +84 -0
  36. package/addon/components/variable-plugin/date/insert.hbs +9 -0
  37. package/addon/components/variable-plugin/date/insert.ts +45 -0
  38. package/addon/components/variable-plugin/insert-variable-card.hbs +7 -40
  39. package/addon/components/variable-plugin/insert-variable-card.ts +18 -166
  40. package/addon/components/variable-plugin/location/edit.hbs +40 -0
  41. package/addon/components/variable-plugin/location/edit.ts +122 -0
  42. package/addon/components/variable-plugin/location/insert.hbs +9 -0
  43. package/addon/components/variable-plugin/location/insert.ts +65 -0
  44. package/addon/components/variable-plugin/{number-settings.hbs → number/insert.hbs} +20 -9
  45. package/addon/components/variable-plugin/number/insert.ts +88 -0
  46. package/addon/components/{variable-number/number.hbs → variable-plugin/number/nodeview.hbs} +2 -2
  47. package/addon/components/{variable-number/number.ts → variable-plugin/number/nodeview.ts} +3 -7
  48. package/addon/components/variable-plugin/text/insert.hbs +9 -0
  49. package/addon/components/variable-plugin/text/insert.ts +49 -0
  50. package/addon/components/variable-plugin/utils/label-input.hbs +11 -0
  51. package/addon/components/variable-plugin/{variable.ts → variable/nodeview.ts} +1 -1
  52. package/addon/helpers/in-array.ts +13 -0
  53. package/addon/plugins/article-structure-plugin/structures/article-paragraph.ts +1 -1
  54. package/addon/plugins/rdfa-date-plugin/nodes/date.ts +48 -51
  55. package/addon/plugins/snippet-plugin/index.ts +20 -0
  56. package/addon/plugins/snippet-plugin/utils/fetch-data.ts +127 -11
  57. package/addon/plugins/table-of-contents-plugin/nodes/table-of-contents.ts +23 -17
  58. package/addon/plugins/table-of-contents-plugin/utils/index.ts +1 -1
  59. package/addon/plugins/template-comments-plugin/index.ts +1 -5
  60. package/addon/plugins/template-comments-plugin/node.ts +3 -16
  61. package/addon/plugins/variable-plugin/utils/address-helpers.ts +112 -0
  62. package/addon/plugins/variable-plugin/utils/attribute-parsers.ts +31 -0
  63. package/addon/plugins/variable-plugin/utils/codelist-utils.ts +56 -0
  64. package/addon/plugins/variable-plugin/utils/constants.ts +0 -120
  65. package/addon/plugins/variable-plugin/utils/dom-constructors.ts +66 -0
  66. package/addon/plugins/variable-plugin/utils/fetch-data.ts +2 -2
  67. package/addon/plugins/variable-plugin/variables/address.ts +322 -0
  68. package/addon/plugins/variable-plugin/variables/codelist.ts +120 -0
  69. package/addon/plugins/variable-plugin/variables/index.ts +5 -0
  70. package/addon/plugins/variable-plugin/variables/location.ts +98 -0
  71. package/addon/plugins/variable-plugin/variables/number.ts +145 -0
  72. package/addon/plugins/variable-plugin/variables/text.ts +90 -0
  73. package/addon/utils/constants.ts +7 -0
  74. package/addon/utils/dom-output-spec-helpers.ts +8 -0
  75. package/addon/utils/namespace.ts +11 -0
  76. package/app/components/snippet-plugin/snippet-list/snippet-list-modal.js +1 -0
  77. package/app/components/{variable-plugin/template-variable-card.js → snippet-plugin/snippet-list/snippet-list-view.js} +1 -1
  78. package/app/components/snippet-plugin/snippet-list-select.js +1 -0
  79. package/app/components/variable-plugin/{variable.js → address/edit.js} +1 -1
  80. package/app/components/variable-plugin/{number-settings.js → address/insert.js} +1 -1
  81. package/app/components/variable-plugin/address/nodeview.js +1 -0
  82. package/app/components/variable-plugin/codelist/edit.js +1 -0
  83. package/app/components/variable-plugin/codelist/insert.js +1 -0
  84. package/app/components/{address-plugin → variable-plugin/date}/insert.js +1 -1
  85. package/app/components/variable-plugin/location/edit.js +1 -0
  86. package/app/components/variable-plugin/location/insert.js +1 -0
  87. package/app/components/variable-plugin/number/insert.js +1 -0
  88. package/app/components/variable-plugin/number/nodeview.js +1 -0
  89. package/app/components/{variable-number/number.js → variable-plugin/text/insert.js} +1 -1
  90. package/app/components/variable-plugin/utils/label-input.js +1 -0
  91. package/app/components/variable-plugin/variable/nodeview.js +1 -0
  92. package/app/helpers/in-array.js +4 -0
  93. package/app/styles/snippet-plugin.scss +18 -1
  94. package/components/roadsign-regulation-plugin/expanded-measure.d.ts +1 -0
  95. package/components/roadsign-regulation-plugin/measure-template.d.ts +2 -4
  96. package/components/snippet-plugin/search-modal.d.ts +1 -0
  97. package/components/snippet-plugin/snippet-insert.d.ts +3 -1
  98. package/components/snippet-plugin/snippet-list/snippet-list-modal.d.ts +23 -0
  99. package/components/snippet-plugin/snippet-list/snippet-list-view.d.ts +10 -0
  100. package/components/snippet-plugin/snippet-list-select.d.ts +14 -0
  101. package/components/table-of-contents-plugin/ember-nodes/table-of-contents.d.ts +5 -12
  102. package/components/template-comments-plugin/template-comment.d.ts +0 -8
  103. package/components/variable-plugin/address/edit.d.ts +23 -0
  104. package/components/variable-plugin/address/insert.d.ts +11 -0
  105. package/components/variable-plugin/address/nodeview.d.ts +14 -0
  106. package/components/variable-plugin/codelist/edit.d.ts +27 -0
  107. package/components/variable-plugin/codelist/insert.d.ts +26 -0
  108. package/components/variable-plugin/date/insert.d.ts +13 -0
  109. package/components/variable-plugin/insert-variable-card.d.ts +10 -34
  110. package/components/variable-plugin/location/edit.d.ts +31 -0
  111. package/components/variable-plugin/location/insert.d.ts +20 -0
  112. package/components/variable-plugin/number/insert.d.ts +20 -0
  113. package/components/{variable-number/number.d.ts → variable-plugin/number/nodeview.d.ts} +1 -1
  114. package/components/variable-plugin/text/insert.d.ts +13 -0
  115. package/components/variable-plugin/{variable.d.ts → variable/nodeview.d.ts} +1 -1
  116. package/helpers/in-array.d.ts +9 -0
  117. package/package.json +5 -5
  118. package/plugins/snippet-plugin/index.d.ts +11 -0
  119. package/plugins/snippet-plugin/utils/fetch-data.d.ts +10 -1
  120. package/plugins/table-of-contents-plugin/utils/index.d.ts +1 -1
  121. package/plugins/template-comments-plugin/index.d.ts +1 -1
  122. package/plugins/template-comments-plugin/node.d.ts +0 -4
  123. package/plugins/variable-plugin/utils/address-helpers.d.ts +4 -0
  124. package/plugins/variable-plugin/utils/attribute-parsers.d.ts +5 -0
  125. package/plugins/variable-plugin/utils/codelist-utils.d.ts +6 -0
  126. package/plugins/variable-plugin/utils/constants.d.ts +0 -19
  127. package/plugins/variable-plugin/utils/dom-constructors.d.ts +24 -0
  128. package/plugins/variable-plugin/utils/fetch-data.d.ts +1 -1
  129. package/plugins/variable-plugin/variables/address.d.ts +23 -0
  130. package/plugins/variable-plugin/variables/codelist.d.ts +2 -0
  131. package/plugins/variable-plugin/variables/index.d.ts +5 -0
  132. package/plugins/variable-plugin/variables/location.d.ts +2 -0
  133. package/plugins/variable-plugin/variables/text.d.ts +2 -0
  134. package/translations/en-US.yaml +74 -2
  135. package/translations/nl-BE.yaml +73 -1
  136. package/types/global.d.ts +10 -0
  137. package/utils/constants.d.ts +3 -0
  138. package/utils/dom-output-spec-helpers.d.ts +2 -0
  139. package/utils/namespace.d.ts +1 -0
  140. package/addon/components/address-plugin/insert.hbs +0 -47
  141. package/addon/components/address-plugin/insert.ts +0 -100
  142. package/addon/components/address-plugin/types.ts +0 -26
  143. package/addon/components/address-plugin/utils.ts +0 -59
  144. package/addon/components/variable-plugin/template-variable-card.ts +0 -163
  145. package/addon/plugins/variable-plugin/index.ts +0 -5
  146. package/addon/plugins/variable-plugin/nodes.ts +0 -264
  147. package/addon/plugins/variable-plugin/number.ts +0 -50
  148. package/app/components/variable-plugin/variable-edit-modal.js +0 -1
  149. package/components/address-plugin/insert.d.ts +0 -21
  150. package/components/address-plugin/types.d.ts +0 -25
  151. package/components/address-plugin/utils.d.ts +0 -9
  152. package/components/variable-plugin/template-variable-card.d.ts +0 -29
  153. package/plugins/variable-plugin/index.d.ts +0 -5
  154. package/plugins/variable-plugin/nodes.d.ts +0 -37
  155. /package/addon/components/variable-plugin/{variable.hbs → variable/nodeview.hbs} +0 -0
  156. /package/plugins/variable-plugin/{number.d.ts → variables/number.d.ts} +0 -0
@@ -1,15 +1,20 @@
1
+
2
+ <AuFormRow>
3
+ <VariablePlugin::Utils::LabelInput @label={{this.label}} @updateLabel={{this.updateLabel}}/>
4
+ </AuFormRow>
1
5
  <div class='number-settings'>
2
6
  <AuFormRow>
3
7
  {{#let (unique-id) as |id|}}
4
8
  <AuLabel for={{id}}>
5
9
  {{t 'variable-plugin.number.minimum'}}
6
10
  </AuLabel>
7
- <AuInput
11
+ <AuNativeInput
8
12
  id={{id}}
9
- @value={{@minimumValue}}
13
+ value={{this.minimumValue}}
14
+ {{on 'input' this.updateMinimumValue}}
10
15
  placeholder={{t 'variable-plugin.number.minimum-placeholder'}}
11
16
  @width='block'
12
- @type='number'
17
+ @type="number"
13
18
  />
14
19
  {{/let}}
15
20
  </AuFormRow>
@@ -19,18 +24,24 @@
19
24
  <AuLabel for={{id}}>
20
25
  {{t 'variable-plugin.number.maximum'}}
21
26
  </AuLabel>
22
- <AuInput
27
+ <AuNativeInput
23
28
  id={{id}}
24
- @value={{@maximumValue}}
29
+ value={{this.maximumValue}}
30
+ {{on 'input' this.updateMaximumValue}}
25
31
  placeholder={{t 'variable-plugin.number.maximum-placeholder'}}
26
32
  @width='block'
27
- @type='number'
33
+ @type="number"
28
34
  />
29
35
  {{/let}}
30
36
  </AuFormRow>
31
- {{#if @error}}
37
+ {{#if this.numberVariableError}}
32
38
  <AuHelpText @error={{true}}>
33
- {{@error}}
39
+ {{this.numberVariableError}}
34
40
  </AuHelpText>
35
41
  {{/if}}
36
- </div>
42
+ </div>
43
+ <AuButton
44
+ {{on 'click' this.insert}}
45
+ @disabled={{this.numberVariableError}}>
46
+ {{t 'variable-plugin.button'}}
47
+ </AuButton>
@@ -0,0 +1,88 @@
1
+ import Component from '@glimmer/component';
2
+ import { tracked } from '@glimmer/tracking';
3
+ import { action } from '@ember/object';
4
+ import { SayController } from '@lblod/ember-rdfa-editor';
5
+ import { v4 as uuidv4 } from 'uuid';
6
+ import { isNumber } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/strings';
7
+ import { inject as service } from '@ember/service';
8
+ import IntlService from 'ember-intl/services/intl';
9
+
10
+ type Args = {
11
+ controller: SayController;
12
+ };
13
+
14
+ export default class NumberInsertComponent extends Component<Args> {
15
+ @service declare intl: IntlService;
16
+ @tracked label?: string;
17
+ @tracked minimumValue = '';
18
+ @tracked maximumValue = '';
19
+
20
+ get controller() {
21
+ return this.args.controller;
22
+ }
23
+
24
+ get schema() {
25
+ return this.args.controller.schema;
26
+ }
27
+
28
+ get numberVariableError() {
29
+ const minVal = this.minimumValue;
30
+ const maxVal = this.maximumValue;
31
+ if (
32
+ isNumber(minVal) &&
33
+ isNumber(maxVal) &&
34
+ Number(minVal) > Number(maxVal)
35
+ ) {
36
+ return this.intl.t('variable.number.error-min-bigger-than-max');
37
+ }
38
+
39
+ return '';
40
+ }
41
+
42
+ @action
43
+ updateLabel(event: InputEvent) {
44
+ this.label = (event.target as HTMLInputElement).value;
45
+ }
46
+
47
+ @action
48
+ updateMinimumValue(event: InputEvent) {
49
+ this.minimumValue = (event.target as HTMLInputElement).value;
50
+ }
51
+
52
+ @action
53
+ updateMaximumValue(event: InputEvent) {
54
+ this.maximumValue = (event.target as HTMLInputElement).value;
55
+ }
56
+
57
+ @action
58
+ insert() {
59
+ if (this.numberVariableError !== '') return;
60
+
61
+ const mappingResource = `http://data.lblod.info/mappings/${uuidv4()}`;
62
+ const variableInstance = `http://data.lblod.info/variables/${uuidv4()}`;
63
+
64
+ const node = this.schema.nodes.number.create({
65
+ label: this.label,
66
+ value: null,
67
+ mappingResource,
68
+ variableInstance,
69
+ ...(isNumber(this.minimumValue) && {
70
+ minimumValue: Number(this.minimumValue),
71
+ }),
72
+ ...(isNumber(this.maximumValue) && {
73
+ maximumValue: Number(this.maximumValue),
74
+ }),
75
+ });
76
+
77
+ this.label = undefined;
78
+ this.minimumValue = '';
79
+ this.maximumValue = '';
80
+
81
+ this.controller.withTransaction(
82
+ (tr) => {
83
+ return tr.replaceSelectionWith(node);
84
+ },
85
+ { view: this.controller.mainEditorView },
86
+ );
87
+ }
88
+ }
@@ -33,8 +33,8 @@
33
33
  >
34
34
  <card.content>
35
35
  {{!-- template-lint-disable no-down-event-binding --}}
36
- <AuInput
37
- @value={{this.inputNumber}}
36
+ <AuNativeInput
37
+ value={{this.inputNumber}}
38
38
  placeholder={{t 'variable.number.type-number'}}
39
39
  {{did-insert this.focus}}
40
40
  {{on 'input' this.onInputNumberChange}}
@@ -11,10 +11,6 @@ import { action } from '@ember/object';
11
11
  import { inject as service } from '@ember/service';
12
12
  import intlService from 'ember-intl/services/intl';
13
13
  import { localCopy } from 'tracked-toolbox';
14
- import {
15
- MAXIMUM_VALUE_PNODE_KEY,
16
- MINIMUM_VALUE_PNODE_KEY,
17
- } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/constants';
18
14
  import { isBlank } from '@ember/utils';
19
15
  import { isNumber } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/strings';
20
16
  import { numberToWords } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/number-to-words';
@@ -28,7 +24,7 @@ type Args = {
28
24
  selected: boolean;
29
25
  contentDecorations?: DecorationSource;
30
26
  };
31
- export default class VariableNumberPluginNumberComponent extends Component<Args> {
27
+ export default class NumberNodeviewComponent extends Component<Args> {
32
28
  @localCopy('args.node.attrs.value', '') declare inputNumber: string;
33
29
  @localCopy('args.node.attrs.writtenNumber', false)
34
30
  declare writtenNumber: boolean;
@@ -60,11 +56,11 @@ export default class VariableNumberPluginNumberComponent extends Component<Args>
60
56
  }
61
57
 
62
58
  get minValue() {
63
- return this.node.attrs[MINIMUM_VALUE_PNODE_KEY] as number;
59
+ return this.node.attrs.minimumValue as number;
64
60
  }
65
61
 
66
62
  get maxValue() {
67
- return this.node.attrs[MAXIMUM_VALUE_PNODE_KEY] as number;
63
+ return this.node.attrs.maximumValue as number;
68
64
  }
69
65
 
70
66
  @action onInputNumberChange(event: InputEvent) {
@@ -0,0 +1,9 @@
1
+ <AuFormRow>
2
+ <VariablePlugin::Utils::LabelInput
3
+ @label={{this.label}}
4
+ @updateLabel={{this.updateLabel}}
5
+ />
6
+ </AuFormRow>
7
+ <AuButton {{on 'click' this.insert}}>
8
+ {{t 'variable-plugin.button'}}
9
+ </AuButton>
@@ -0,0 +1,49 @@
1
+ import Component from '@glimmer/component';
2
+ import { tracked } from '@glimmer/tracking';
3
+ import { action } from '@ember/object';
4
+ import { SayController } from '@lblod/ember-rdfa-editor';
5
+ import { v4 as uuidv4 } from 'uuid';
6
+
7
+ type Args = {
8
+ controller: SayController;
9
+ };
10
+
11
+ export default class TextVariableInsertComponent extends Component<Args> {
12
+ @tracked label?: string;
13
+
14
+ get controller() {
15
+ return this.args.controller;
16
+ }
17
+
18
+ get schema() {
19
+ return this.args.controller.schema;
20
+ }
21
+
22
+ @action
23
+ updateLabel(event: InputEvent) {
24
+ this.label = (event.target as HTMLInputElement).value;
25
+ }
26
+
27
+ @action
28
+ insert() {
29
+ const mappingResource = `http://data.lblod.info/mappings/${uuidv4()}`;
30
+ const variableInstance = `http://data.lblod.info/variables/${uuidv4()}`;
31
+ const node = this.schema.nodes.text_variable.create(
32
+ {
33
+ label: this.label,
34
+ mappingResource,
35
+ variableInstance,
36
+ },
37
+ this.schema.node('placeholder', { placeholderText: 'text' }),
38
+ );
39
+
40
+ this.label = undefined;
41
+
42
+ this.controller.withTransaction(
43
+ (tr) => {
44
+ return tr.replaceSelectionWith(node);
45
+ },
46
+ { view: this.controller.mainEditorView },
47
+ );
48
+ }
49
+ }
@@ -0,0 +1,11 @@
1
+ <AuLabel for='label'>
2
+ {{t 'variable-plugin.label'}}
3
+ </AuLabel>
4
+ <AuNativeInput
5
+ id="label"
6
+ placeholder={{t 'variable-plugin.labelPlaceholder'}}
7
+ @type='text'
8
+ @width='block'
9
+ value={{@label}}
10
+ {{on 'input' @updateLabel}}
11
+ />
@@ -11,7 +11,7 @@ type Args = {
11
11
  controller: SayController;
12
12
  };
13
13
 
14
- export default class VariableComponent extends Component<Args> {
14
+ export default class VariableNodeViewComponent extends Component<Args> {
15
15
  @tracked innerView?: SayView;
16
16
 
17
17
  @action
@@ -0,0 +1,13 @@
1
+ import { helper } from '@ember/component/helper';
2
+
3
+ type PositionalParams = [array: unknown[], needle: unknown];
4
+
5
+ function inArray([theArray, needle]: PositionalParams) {
6
+ if (!Array.isArray(theArray)) {
7
+ return false;
8
+ }
9
+
10
+ return theArray.includes(needle);
11
+ }
12
+
13
+ export default helper<PositionalParams>(inArray);
@@ -53,7 +53,7 @@ const contentSelector = `span[property~='${SAY('body').prefixed}'],
53
53
  span[property~='${SAY('body').full}']`;
54
54
 
55
55
  export const article_paragraph: NodeSpec = {
56
- content: 'paragraph*',
56
+ content: 'block*',
57
57
  inline: false,
58
58
  isolating: true,
59
59
  defining: true,
@@ -4,7 +4,6 @@ import {
4
4
  EmberNodeConfig,
5
5
  } from '@lblod/ember-rdfa-editor/utils/ember-node';
6
6
  import {
7
- DCT,
8
7
  EXT,
9
8
  XSD,
10
9
  } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
@@ -12,10 +11,20 @@ import { hasRDFaAttribute } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/n
12
11
  import { DateOptions } from '..';
13
12
  import { formatDate, validateDateFormat } from '../utils';
14
13
  import { PNode } from '@lblod/ember-rdfa-editor';
14
+ import {
15
+ isVariable,
16
+ parseLabel,
17
+ parseVariableType,
18
+ } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/attribute-parsers';
19
+ import {
20
+ mappingSpan,
21
+ typeSpan,
22
+ } from '../../variable-plugin/utils/dom-constructors';
23
+ import { span } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/dom-output-spec-helpers';
15
24
 
16
25
  const emberNodeConfig = (options: DateOptions): EmberNodeConfig => ({
17
26
  name: 'date',
18
- group: 'inline',
27
+ group: 'inline variable',
19
28
  componentPath: 'rdfa-date-plugin/date',
20
29
  inline: true,
21
30
  selectable: true,
@@ -41,7 +50,7 @@ const emberNodeConfig = (options: DateOptions): EmberNodeConfig => ({
41
50
  default: false,
42
51
  },
43
52
  label: {
44
- default: '',
53
+ default: 'datum',
45
54
  },
46
55
  },
47
56
  leafText: (node: PNode) => {
@@ -77,19 +86,14 @@ const emberNodeConfig = (options: DateOptions): EmberNodeConfig => ({
77
86
  ...(!!value && { content: value as string }),
78
87
  };
79
88
  if (mappingResource) {
80
- return [
81
- 'span',
82
- {
83
- resource: mappingResource as string,
84
- typeof: EXT('Mapping').prefixed,
85
- class: 'date',
86
- 'data-label': label as string,
87
- },
88
- ['span', { property: DCT('type').prefixed, content: 'date' }],
89
- ['span', dateAttrs, humanReadableDate],
90
- ];
89
+ return mappingSpan(
90
+ mappingResource,
91
+ { class: 'date', 'data-label': label as string },
92
+ typeSpan('date'),
93
+ span(dateAttrs, humanReadableDate),
94
+ );
91
95
  } else {
92
- return ['span', { class: 'date', ...dateAttrs }, humanReadableDate];
96
+ return span({ class: 'date', ...dateAttrs }, humanReadableDate);
93
97
  }
94
98
  },
95
99
  parseDOM: [
@@ -114,50 +118,43 @@ const emberNodeConfig = (options: DateOptions): EmberNodeConfig => ({
114
118
  {
115
119
  tag: 'span',
116
120
  getAttrs: (node: HTMLElement) => {
117
- if (hasRDFaAttribute(node, 'typeof', EXT('Mapping'))) {
121
+ if (isVariable(node) && parseVariableType(node) === 'date') {
118
122
  const mappingResource = node.getAttribute('resource');
119
123
  if (!mappingResource) {
120
124
  return false;
121
125
  }
122
- const variableType = [...node.children]
123
- .find((el) => hasRDFaAttribute(el, 'property', DCT('type')))
124
- ?.getAttribute('content');
125
- const datatype = [...node.children]
126
- .find((el) => hasRDFaAttribute(el, 'property', EXT('content')))
127
- ?.getAttribute('datatype');
128
- if (variableType === 'date' && datatype) {
129
- const onlyDate = !![...node.children].find((el) =>
130
- hasRDFaAttribute(el, 'datatype', XSD('date')),
131
- );
132
- const dateNode = [...node.children].find((el) =>
133
- hasRDFaAttribute(el, 'property', EXT('content')),
134
- ) as HTMLElement | undefined;
135
- let humanReadableDate: string;
136
- const value = dateNode?.getAttribute('content');
137
- const format = dateNode?.dataset.format;
138
- if (value && format) {
139
- if (validateDateFormat(format).type === 'ok') {
140
- humanReadableDate = formatDate(new Date(value), format);
141
- } else {
142
- humanReadableDate = 'Ongeldig formaat';
143
- }
126
+ const onlyDate = !![...node.children].find((el) =>
127
+ hasRDFaAttribute(el, 'datatype', XSD('date')),
128
+ );
129
+ const dateNode = [...node.children].find((el) =>
130
+ hasRDFaAttribute(el, 'property', EXT('content')),
131
+ ) as HTMLElement | undefined;
132
+ let humanReadableDate: string;
133
+ const value = dateNode?.getAttribute('content');
134
+ const format = dateNode?.dataset.format;
135
+ if (value && format) {
136
+ if (validateDateFormat(format).type === 'ok') {
137
+ humanReadableDate = formatDate(new Date(value), format);
144
138
  } else {
145
- humanReadableDate = onlyDate
146
- ? options.placeholder.insertDate
147
- : options.placeholder.insertDateTime;
139
+ humanReadableDate = 'Ongeldig formaat';
148
140
  }
149
- const label = node.getAttribute('data-label') || variableType;
150
- return {
151
- mappingResource,
152
- onlyDate,
153
- humanReadableDate,
154
- value: value,
155
- format: format,
156
- custom: dateNode?.dataset.custom === 'true',
157
- label,
158
- };
141
+ } else {
142
+ humanReadableDate = onlyDate
143
+ ? options.placeholder.insertDate
144
+ : options.placeholder.insertDateTime;
159
145
  }
146
+ const label = parseLabel(node);
147
+ return {
148
+ mappingResource,
149
+ onlyDate,
150
+ humanReadableDate,
151
+ value: value,
152
+ format: format,
153
+ custom: dateNode?.dataset.custom === 'true',
154
+ label,
155
+ };
160
156
  }
157
+
161
158
  return false;
162
159
  },
163
160
  },
@@ -25,3 +25,23 @@ export class Snippet {
25
25
  this.title = title;
26
26
  }
27
27
  }
28
+
29
+ interface SnippetListArgs {
30
+ id: string | null;
31
+ label: string | null;
32
+ createdOn: string | null;
33
+ }
34
+
35
+ const snippetListBase = 'http://lblod.data.gift/snippet-lists/';
36
+
37
+ export class SnippetList {
38
+ id: string | null;
39
+ label: string | null;
40
+ createdOn: string | null;
41
+
42
+ constructor({ id, label, createdOn }: SnippetListArgs) {
43
+ this.id = id?.replace(snippetListBase, '') ?? null;
44
+ this.label = label;
45
+ this.createdOn = dateValue(createdOn ?? undefined);
46
+ }
47
+ }
@@ -2,35 +2,69 @@ import {
2
2
  executeCountQuery,
3
3
  executeQuery,
4
4
  } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/sparql-helpers';
5
- import { Snippet } from '../index';
5
+ import { Snippet, SnippetList } from '../index';
6
6
 
7
- type Filter = { name?: string };
7
+ type Filter = { name?: string; assignedSnippetListIds?: string[] };
8
8
  type Pagination = { pageNumber: number; pageSize: number };
9
9
 
10
- const buildCountQuery = ({ name }: Filter) => {
10
+ const sparqlEscapeString = (value: string) =>
11
+ '"""' + value.replace(/[\\"]/g, (match) => '\\' + match) + '"""';
12
+
13
+ const buildSnippetCountQuery = ({ name, assignedSnippetListIds }: Filter) => {
11
14
  return `
12
15
  PREFIX schema: <http://schema.org/>
13
16
  PREFIX dct: <http://purl.org/dc/terms/>
14
17
  PREFIX pav: <http://purl.org/pav/>
15
18
  PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
16
19
  PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>
20
+ PREFIX prov: <http://www.w3.org/ns/prov#>
21
+ PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
17
22
 
18
23
  SELECT (COUNT(?publishedSnippetVersion) AS ?count)
19
24
  WHERE {
20
25
  ?publishedSnippetContainer a ext:PublishedSnippetContainer ;
21
- pav:hasCurrentVersion ?publishedSnippetVersion .
26
+ pav:hasCurrentVersion ?publishedSnippetVersion ;
27
+ ext:fromSnippetList ?fromSnippetList .
28
+ ?fromSnippetList mu:uuid ?fromSnippetListId .
22
29
  ?publishedSnippetVersion dct:title ?title ;
23
30
  ext:editorDocumentContent ?content ;
24
31
  pav:createdOn ?createdOn .
25
32
  OPTIONAL { ?publishedSnippetVersion schema:validThrough ?validThrough. }
26
33
  FILTER(!BOUND(?validThrough) || xsd:dateTime(?validThrough) > now())
27
- ${name ? `FILTER (CONTAINS(LCASE(?title), "${name}"))` : ''}
34
+ ${
35
+ name
36
+ ? `FILTER (CONTAINS(LCASE(?title), "${name.toLowerCase()}"))`
37
+ : ''
38
+ }
39
+ ${
40
+ assignedSnippetListIds && assignedSnippetListIds.length
41
+ ? `FILTER (?fromSnippetListId IN (${assignedSnippetListIds
42
+ .map((from) => sparqlEscapeString(from))
43
+ .join(', ')}))`
44
+ : ''
45
+ }
28
46
  }
29
47
  `;
30
48
  };
31
49
 
32
- const buildFetchQuery = ({
33
- filter: { name },
50
+ const buildSnippetListCountQuery = ({ name }: Filter) => {
51
+ return `
52
+ PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>
53
+ SELECT (COUNT(?snippetLists) AS ?count)
54
+ WHERE {
55
+ ?snippetLists a ext:SnippetList;
56
+ skos:prefLabel ?label.
57
+ ${
58
+ name
59
+ ? `FILTER (CONTAINS(LCASE(?label), "${name.toLowerCase()}"))`
60
+ : ''
61
+ }
62
+ }
63
+ `;
64
+ };
65
+
66
+ const buildSnippetFetchQuery = ({
67
+ filter: { name, assignedSnippetListIds },
34
68
  pagination: { pageSize, pageNumber },
35
69
  }: {
36
70
  filter: Filter;
@@ -42,15 +76,30 @@ const buildFetchQuery = ({
42
76
  PREFIX pav: <http://purl.org/pav/>
43
77
  PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
44
78
  PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>
79
+ PREFIX prov: <http://www.w3.org/ns/prov#>
80
+ PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
45
81
 
46
82
  SELECT DISTINCT ?title ?content ?createdOn
47
83
  WHERE {
48
84
  ?publishedSnippetContainer a ext:PublishedSnippetContainer ;
49
- pav:hasCurrentVersion ?publishedSnippetVersion .
85
+ pav:hasCurrentVersion ?publishedSnippetVersion ;
86
+ ext:fromSnippetList ?fromSnippetList .
87
+ ?fromSnippetList mu:uuid ?fromSnippetListId .
50
88
  ?publishedSnippetVersion dct:title ?title ;
51
89
  ext:editorDocumentContent ?content ;
52
90
  pav:createdOn ?createdOn .
53
- ${name ? `FILTER (CONTAINS(LCASE(?title), "${name}"))` : ''}
91
+ ${
92
+ name
93
+ ? `FILTER (CONTAINS(LCASE(?title), "${name.toLowerCase()}"))`
94
+ : ''
95
+ }
96
+ ${
97
+ assignedSnippetListIds && assignedSnippetListIds.length
98
+ ? `FILTER (?fromSnippetListId IN (${assignedSnippetListIds
99
+ .map((from) => sparqlEscapeString(from))
100
+ .join(', ')}))`
101
+ : ''
102
+ }
54
103
  OPTIONAL { ?publishedSnippetVersion schema:validThrough ?validThrough. }
55
104
  FILTER(!BOUND(?validThrough) || xsd:dateTime(?validThrough) > now())
56
105
  }
@@ -60,6 +109,28 @@ const buildFetchQuery = ({
60
109
  `;
61
110
  };
62
111
 
112
+ const buildSnippetListFetchQuery = ({
113
+ filter: { name },
114
+ }: {
115
+ filter: Filter;
116
+ }) => {
117
+ return `
118
+ PREFIX pav: <http://purl.org/pav/>
119
+ PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
120
+ PREFIX ext: <http://mu.semte.ch/vocabularies/ext/>
121
+
122
+ SELECT (?snippetLists as ?id) ?label ?createdOn WHERE {
123
+ ?snippetLists a ext:SnippetList;
124
+ skos:prefLabel ?label;
125
+ pav:createdOn ?createdOn.
126
+ ${
127
+ name
128
+ ? `FILTER (CONTAINS(LCASE(?label), "${name.toLowerCase()}"))`
129
+ : ''
130
+ }
131
+ }`;
132
+ };
133
+
63
134
  export const fetchSnippets = async ({
64
135
  endpoint,
65
136
  abortSignal,
@@ -71,9 +142,13 @@ export const fetchSnippets = async ({
71
142
  filter: Filter;
72
143
  pagination: Pagination;
73
144
  }) => {
145
+ if (!filter.assignedSnippetListIds?.length) {
146
+ return { totalCount: 0, results: [] };
147
+ }
148
+
74
149
  const totalCount = await executeCountQuery({
75
150
  endpoint,
76
- query: buildCountQuery(filter),
151
+ query: buildSnippetCountQuery(filter),
77
152
  abortSignal,
78
153
  });
79
154
 
@@ -87,7 +162,7 @@ export const fetchSnippets = async ({
87
162
  content: { value: string };
88
163
  }>({
89
164
  endpoint,
90
- query: buildFetchQuery({ filter, pagination }),
165
+ query: buildSnippetFetchQuery({ filter, pagination }),
91
166
  abortSignal,
92
167
  });
93
168
 
@@ -102,3 +177,44 @@ export const fetchSnippets = async ({
102
177
 
103
178
  return { totalCount, results };
104
179
  };
180
+
181
+ export const fetchSnippetLists = async ({
182
+ endpoint,
183
+ abortSignal,
184
+ filter,
185
+ }: {
186
+ endpoint: string;
187
+ abortSignal: AbortSignal;
188
+ filter: Filter;
189
+ }) => {
190
+ const totalCount = await executeCountQuery({
191
+ endpoint,
192
+ query: buildSnippetListCountQuery(filter),
193
+ abortSignal,
194
+ });
195
+
196
+ if (totalCount === 0) {
197
+ return { totalCount, results: [] };
198
+ }
199
+
200
+ const queryResult = await executeQuery<{
201
+ id: { value: string };
202
+ label: { value: string };
203
+ createdOn: { value: string };
204
+ }>({
205
+ endpoint,
206
+ query: buildSnippetListFetchQuery({ filter }),
207
+ abortSignal,
208
+ });
209
+
210
+ const results = queryResult.results.bindings.map(
211
+ (binding) =>
212
+ new SnippetList({
213
+ id: binding.id?.value,
214
+ label: binding.label?.value,
215
+ createdOn: binding.createdOn?.value,
216
+ }),
217
+ );
218
+
219
+ return { totalCount, results };
220
+ };