@lblod/ember-rdfa-editor-lblod-plugins 7.1.0 → 8.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 (36) hide show
  1. package/CHANGELOG.md +32 -1
  2. package/README.md +12 -11
  3. package/addon/components/generic-rdfa-variable/insert-menu.hbs +30 -0
  4. package/addon/components/generic-rdfa-variable/insert-menu.ts +97 -0
  5. package/addon/components/rdfa-date-plugin/date.hbs +9 -0
  6. package/addon/components/rdfa-date-plugin/date.ts +55 -0
  7. package/addon/components/variable-plugin/insert-variable-card.hbs +19 -0
  8. package/addon/components/variable-plugin/insert-variable-card.ts +26 -5
  9. package/addon/components/variable-plugin/number-settings.hbs +31 -0
  10. package/addon/components/variable-plugin/template-variable-card.hbs +3 -0
  11. package/addon/components/variable-plugin/template-variable-card.ts +3 -0
  12. package/addon/components/variable-plugin/variable.hbs +7 -1
  13. package/addon/components/variable-plugin/variable.ts +39 -0
  14. package/addon/plugins/citation-plugin/utils/vlaamse-codex.ts +1 -2
  15. package/addon/plugins/rdfa-date-plugin/nodes/date.ts +150 -114
  16. package/addon/plugins/validation/README.md +1 -1
  17. package/addon/plugins/variable-plugin/nodes.ts +68 -3
  18. package/addon/plugins/variable-plugin/utils/constants.ts +29 -15
  19. package/addon/plugins/variable-plugin/utils/fetch-data.ts +9 -5
  20. package/app/components/generic-rdfa-variable/insert-menu.js +1 -0
  21. package/app/components/rdfa-date-plugin/date.js +1 -0
  22. package/app/components/variable-plugin/number-settings.js +1 -0
  23. package/app/styles/generic-rdfa-variable.scss +20 -0
  24. package/app/styles/variable-plugin.scss +31 -0
  25. package/components/generic-rdfa-variable/insert-menu.d.ts +17 -0
  26. package/components/rdfa-date-plugin/date.d.ts +16 -0
  27. package/components/variable-plugin/insert-variable-card.d.ts +4 -0
  28. package/components/variable-plugin/template-variable-card.d.ts +1 -0
  29. package/components/variable-plugin/variable.d.ts +11 -0
  30. package/package.json +8 -4
  31. package/plugins/citation-plugin/utils/vlaamse-codex.d.ts +2 -2
  32. package/plugins/rdfa-date-plugin/nodes/date.d.ts +2 -3
  33. package/plugins/variable-plugin/nodes.d.ts +22 -1
  34. package/plugins/variable-plugin/utils/constants.d.ts +11 -2
  35. package/translations/en-US.yaml +15 -0
  36. package/translations/nl-BE.yaml +15 -0
package/CHANGELOG.md CHANGED
@@ -7,6 +7,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [8.0.1] - 2023-06-15
11
+ ### Fixed
12
+ - Change problematic type in citation that made it to break with new ember
13
+
14
+
15
+ ## [8.0.0] - 2023-06-15
16
+ ### Fixed
17
+ - Bump `@lblod/ember-rdfa-editor` package to fix annotation not present for some structures
18
+ - Change variable label to be stored in the data-attributes and solve bug with date not getting a default label
19
+
20
+ ### Added
21
+ - navigation links in TOC of readme
22
+ - support for option labels in Variable-plugin
23
+ - Generic rdfa variables input plugin - HTML only input
24
+ - Number variable - support min/max
25
+
26
+ ### Breaking
27
+ - Add label to variables
28
+
29
+ ### Dependencies
30
+ - Bumps `webpack` from 5.75.0 to 5.76.0
31
+ - Move `tracked-toolbox` to dependencies
32
+ - Bumps `prettier` from 2.8.0 to 2.8.8
33
+ - Bumps `minimist` from 0.2.2 to 0.2.4
34
+ - Bumps `socket.io-parser` from 4.2.1 to 4.2.4
35
+ - Bumps `decode-uri-component` from 0.2.0 to 0.2.2
36
+ - Bumps loader-utils from 1.0.4 to 2.0.4
37
+ - Bumps handlebars-loader from 1.7.2 to 1.7.3
38
+
10
39
  ## [7.1.0] - 2023-05-18
11
40
 
12
41
  ### Added
@@ -444,7 +473,9 @@ add onclick handler to pencil icon in variable plugin
444
473
 
445
474
  # Changelog
446
475
 
447
- [unreleased]: https://github.com/lblod/ember-rdfa-editor-lblod-plugins/compare/v7.1.0...HEAD
476
+ [unreleased]: https://github.com/lblod/ember-rdfa-editor-lblod-plugins/compare/v8.0.1...HEAD
477
+ [8.0.0]: https://github.com/lblod/ember-rdfa-editor-lblod-plugins/compare/v8.0.0...v8.0.1
478
+ [8.0.0]: https://github.com/lblod/ember-rdfa-editor-lblod-plugins/compare/v7.1.0...v8.0.0
448
479
  [7.1.0]: https://github.com/lblod/ember-rdfa-editor-lblod-plugins/compare/v7.0.0...v7.1.0
449
480
  [7.0.0]: https://github.com/lblod/ember-rdfa-editor-lblod-plugins/compare/v6.1.0...v7.0.0
450
481
  [6.1.0]: https://github.com/lblod/ember-rdfa-editor-lblod-plugins/compare/v6.0.0...v6.1.0
package/README.md CHANGED
@@ -19,17 +19,18 @@ ember install ember-rdfa-editor-lblod-plugins
19
19
 
20
20
  This addon contains the following editor plugins:
21
21
 
22
- * besluit-type-plugin
23
- * citaten-plugin
24
- * decision-plugin
25
- * import-snippet-plugin
26
- * insert-variable-plugin
27
- * rdfa-date-plugin
28
- * roadsign-regulation-plugin
29
- * standard-template-plugin
30
- * table-of-contents-plugin
31
- * template-variable-plugin
32
- * validation-plugin
22
+ * [besluit-type-plugin](#besluit-type-plugin)
23
+ * [citaten-plugin](#citaten-plugin)
24
+ * [decision-plugin](#decision-plugin)
25
+ * [import-snippet-plugin](#import-snippet-plugin)
26
+ * [insert-variable-plugin](#insert-variable-plugin)
27
+ * [rdfa-date-plugin](#rdfa-date-plugin)
28
+ * [roadsign-regulation-plugin](#roadsign-regulation-plugin)
29
+ * [standard-template-plugin](#standard-template-plugin)
30
+ * [table-of-contents-plugin](#table-of-contents-plugin)
31
+ * [template-variable-plugin](#template-variable-plugin)
32
+ * [validation-plugin](#validation-plugin)
33
+ * [address-plugin](#address-plugin)
33
34
 
34
35
  You can configure your editor like this:
35
36
  ```hbs
@@ -0,0 +1,30 @@
1
+ <Toolbar::Button
2
+ @title={{t 'generic-rdfa-variable.menu.insert'}}
3
+ @icon='html-plus'
4
+ {{on 'click' this.showModal}}
5
+ />
6
+ <AuModal
7
+ @modalOpen={{this.modalOpen}}
8
+ @closeModal={{this.onCancel}}
9
+ @initialFocus={{false}}
10
+ class='generic-rdfa-plugin-modal'
11
+ >
12
+ <:title>{{t 'generic-rdfa-variable.menu.insert'}}</:title>
13
+ <:body>
14
+ <div
15
+ class='generic-rdfa-variable-textarea-wrapper'
16
+ {{did-insert this.setupHtmlEditor}}
17
+ >
18
+ </div>
19
+ </:body>
20
+ <:footer>
21
+ <AuButtonGroup>
22
+ <AuButton @skin='primary' {{on 'click' this.onInsert}}>
23
+ {{t 'generic-rdfa-variable.modal.insert'}}
24
+ </AuButton>
25
+ <AuButton @skin='secondary' {{on 'click' this.onCancel}}>
26
+ {{t 'generic-rdfa-variable.modal.cancel'}}
27
+ </AuButton>
28
+ </AuButtonGroup>
29
+ </:footer>
30
+ </AuModal>
@@ -0,0 +1,97 @@
1
+ import Component from '@glimmer/component';
2
+ import { action } from '@ember/object';
3
+ import { SayController } from '@lblod/ember-rdfa-editor';
4
+ import { tracked } from 'tracked-built-ins';
5
+
6
+ import { DOMParser as ProseParser } from 'prosemirror-model';
7
+
8
+ import { basicSetup, EditorView } from 'codemirror';
9
+ import { EditorState } from '@codemirror/state';
10
+ import { html } from '@codemirror/lang-html';
11
+ import { tooltips } from '@codemirror/view';
12
+
13
+ type Args = {
14
+ controller: SayController;
15
+ };
16
+
17
+ export default class GenericRdfaVariableInsertMenu extends Component<Args> {
18
+ @tracked modalOpen = false;
19
+ private htmlEditor?: EditorView;
20
+
21
+ get controller() {
22
+ return this.args.controller;
23
+ }
24
+
25
+ get schema() {
26
+ return this.args.controller.schema;
27
+ }
28
+
29
+ @action
30
+ showModal() {
31
+ this.modalOpen = true;
32
+ }
33
+
34
+ @action
35
+ closeModal() {
36
+ this.modalOpen = false;
37
+
38
+ // The recommended way to focus the editor is to call `this.controller.focus()` before opening the modal
39
+ // e.g. in the `showModal` fn, then `focus-trap` inside modal will record it as the element that should
40
+ // be focused when `focus-trap` is deactivated (modal is closed).
41
+ //
42
+ // However, for some reason, this doesn't work in this case. Maybe because `initialFocus` is false, maybe
43
+ // because of something else, I wasn't able to get to the bottom of it.
44
+ //
45
+ // So, we're doing it the other way here: we wait for the modal to close, wait for the `focus-trap` to
46
+ // deactivate, and then focus the editor.
47
+ setTimeout(() => {
48
+ this.controller.focus();
49
+ }, 0);
50
+ }
51
+
52
+ @action
53
+ onCancel() {
54
+ this.closeModal();
55
+ }
56
+
57
+ @action
58
+ setupHtmlEditor(element: HTMLElement) {
59
+ this.htmlEditor = new EditorView({
60
+ state: EditorState.create({
61
+ extensions: [
62
+ basicSetup,
63
+ html(),
64
+ tooltips({ position: 'absolute', parent: element }),
65
+ ],
66
+ }),
67
+ parent: element,
68
+ });
69
+
70
+ this.htmlEditor.focus();
71
+ }
72
+
73
+ @action
74
+ onInsert() {
75
+ if (!this.htmlEditor) {
76
+ return;
77
+ }
78
+
79
+ const editorContent = this.htmlEditor.state.sliceDoc();
80
+
81
+ if (!editorContent) {
82
+ return;
83
+ }
84
+
85
+ const domParser = new DOMParser();
86
+
87
+ this.controller.withTransaction((tr) => {
88
+ return tr.replaceSelectionWith(
89
+ ProseParser.fromSchema(this.schema).parse(
90
+ domParser.parseFromString(editorContent, 'text/html')
91
+ )
92
+ );
93
+ });
94
+
95
+ this.closeModal();
96
+ }
97
+ }
@@ -0,0 +1,9 @@
1
+ <AuPill @icon="pencil" @iconAlignment="right" class="variable" {{on 'click' this.onClick}}>
2
+
3
+ {{this.humanReadableDate}}
4
+ {{#if @node.attrs.label}}
5
+ <span class="label">
6
+ ({{@node.attrs.label}})
7
+ </span>
8
+ {{/if}}
9
+ </AuPill>
@@ -0,0 +1,55 @@
1
+ import Component from '@glimmer/component';
2
+ import {
3
+ DecorationSource,
4
+ NodeSelection,
5
+ PNode,
6
+ SayController,
7
+ SayView,
8
+ } from '@lblod/ember-rdfa-editor';
9
+ import { action } from '@ember/object';
10
+ import {
11
+ formatDate,
12
+ validateDateFormat,
13
+ } from '../../plugins/rdfa-date-plugin/utils';
14
+ import { DateOptions } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/rdfa-date-plugin';
15
+
16
+ type Args = {
17
+ getPos: () => number | undefined;
18
+ node: PNode;
19
+ updateAttribute: (attr: string, value: unknown) => void;
20
+ controller: SayController;
21
+ view: SayView;
22
+ selected: boolean;
23
+ contentDecorations?: DecorationSource;
24
+ };
25
+
26
+ export default class VariableComponent extends Component<Args> {
27
+ @action
28
+ onClick() {
29
+ const tr = this.args.controller.activeEditorState.tr;
30
+ tr.setSelection(
31
+ NodeSelection.create(
32
+ this.args.controller.activeEditorState.doc,
33
+ this.args.getPos() as number
34
+ )
35
+ );
36
+ this.args.controller.activeEditorView.dispatch(tr);
37
+ }
38
+
39
+ get humanReadableDate() {
40
+ const value = this.args.node.attrs.value as string;
41
+ const format = this.args.node.attrs.format as string;
42
+ if (value) {
43
+ if (validateDateFormat(format).type === 'ok') {
44
+ return formatDate(new Date(value), format);
45
+ } else {
46
+ return 'Ongeldig formaat';
47
+ }
48
+ } else {
49
+ const options = this.args.node.type.spec.options as DateOptions;
50
+ return (this.args.node.attrs.onlyDate as boolean)
51
+ ? options.placeholder.insertDate
52
+ : options.placeholder.insertDateTime;
53
+ }
54
+ }
55
+ }
@@ -36,6 +36,25 @@
36
36
  {{subtype.label}}
37
37
  </PowerSelect>
38
38
  {{/if}}
39
+ <AuFormRow>
40
+ <AuLabel for='label'>
41
+ {{t 'variable-plugin.label'}}
42
+ </AuLabel>
43
+ <AuInput
44
+ id="label"
45
+ placeholder={{t 'variable-plugin.labelPlaceholder'}}
46
+ @type="text"
47
+ @width="block"
48
+ @value={{this.variableLabel}}
49
+ {{on "input" this.updateVariableLabel}}
50
+ />
51
+ </AuFormRow>
52
+ {{#if (eq this.type 'number')}}
53
+ <VariablePlugin::NumberSettings
54
+ @minimumValue={{this.extraAttributes.minimumValue}}
55
+ @maximumValue={{this.extraAttributes.maximumValue}}
56
+ />
57
+ {{/if}}
39
58
  <AuButton
40
59
  {{on 'click' this.insert}}
41
60
  @disabled={{or
@@ -25,6 +25,8 @@ export default class EditorPluginsInsertCodelistCardComponent extends Component<
25
25
  @tracked hasSubtype = false;
26
26
  @tracked selectedSubtype?: CodeList;
27
27
  @tracked subtypes?: CodeList[];
28
+ @tracked variableLabel?: string;
29
+ @tracked extraAttributes: Record<string, unknown> = {};
28
30
  publisher: string;
29
31
  endpoint: string;
30
32
 
@@ -64,16 +66,30 @@ export default class EditorPluginsInsertCodelistCardComponent extends Component<
64
66
  return this.args.controller;
65
67
  }
66
68
 
69
+ @action
70
+ updateVariableLabel(event: InputEvent) {
71
+ this.variableLabel = (event.target as HTMLInputElement).value;
72
+ }
73
+
67
74
  @action
68
75
  insert() {
69
76
  if (!this.selectedVariable) {
70
77
  return;
71
78
  }
72
- const node = this.selectedVariable.constructor(
73
- this.controller.schema,
74
- this.endpoint,
75
- this.selectedSubtype
76
- );
79
+
80
+ const node = this.selectedVariable.constructor({
81
+ schema: this.controller.schema,
82
+ codelist: this.selectedSubtype,
83
+ label: this.variableLabel !== '' ? this.variableLabel : undefined,
84
+ attributes: {
85
+ source: this.endpoint,
86
+ ...this.extraAttributes,
87
+ },
88
+ });
89
+
90
+ this.variableLabel = '';
91
+ this.extraAttributes = {};
92
+
77
93
  this.controller.withTransaction(
78
94
  (tr) => {
79
95
  return tr.replaceSelectionWith(node);
@@ -108,6 +124,11 @@ export default class EditorPluginsInsertCodelistCardComponent extends Component<
108
124
  @action
109
125
  updateSubtype(subtype: CodeList) {
110
126
  this.selectedSubtype = subtype;
127
+ this.extraAttributes = {};
128
+ }
129
+
130
+ get type() {
131
+ return this.selectedVariable?.label;
111
132
  }
112
133
 
113
134
  get showCard() {
@@ -0,0 +1,31 @@
1
+ <div class='number-settings'>
2
+ <AuFormRow>
3
+ {{#let (unique-id) as |id|}}
4
+ <AuLabel for={{id}}>
5
+ {{t 'variable-plugin.number.minimum'}}
6
+ </AuLabel>
7
+ <AuInput
8
+ id={{id}}
9
+ @value={{@minimumValue}}
10
+ placeholder={{t 'variable-plugin.number.minimum-placeholder'}}
11
+ @width='block'
12
+ @type='number'
13
+ />
14
+ {{/let}}
15
+ </AuFormRow>
16
+ <div class='to'><span>{{t 'variable-plugin.number.to'}}</span></div>
17
+ <AuFormRow>
18
+ {{#let (unique-id) as |id|}}
19
+ <AuLabel for={{id}}>
20
+ {{t 'variable-plugin.number.maximum'}}
21
+ </AuLabel>
22
+ <AuInput
23
+ id={{id}}
24
+ @value={{@maximumValue}}
25
+ placeholder={{t 'variable-plugin.number.maximum-placeholder'}}
26
+ @width='block'
27
+ @type='number'
28
+ />
29
+ {{/let}}
30
+ </AuFormRow>
31
+ </div>
@@ -7,6 +7,9 @@
7
7
  </AuHeading>
8
8
  </c.header>
9
9
  <c.content>
10
+ <AuLabel for='label'>
11
+ {{this.label}}
12
+ </AuLabel>
10
13
  {{#if this.multiSelect}}
11
14
  <PowerSelectMultiple
12
15
  @allowClear={{false}}
@@ -24,6 +24,7 @@ export default class EditorPluginsTemplateVariableCardComponent extends Componen
24
24
  @tracked selectedVariable: { pos: number; node: PNode } | undefined;
25
25
  @tracked showCard = false;
26
26
  @tracked multiSelect = false;
27
+ @tracked label?: string;
27
28
  mappingUri?: string;
28
29
 
29
30
  get controller() {
@@ -93,6 +94,7 @@ export default class EditorPluginsTemplateVariableCardComponent extends Componen
93
94
  const codelistURI = variable.node.attrs.codelistResource as string;
94
95
  void this.fetchCodeListOptions.perform(source, codelistURI);
95
96
  this.showCard = true;
97
+ this.label = variable.node.attrs.label as string;
96
98
  } else if (type === 'location') {
97
99
  const source =
98
100
  (variable.node.attrs.source as string | undefined) ??
@@ -103,6 +105,7 @@ export default class EditorPluginsTemplateVariableCardComponent extends Componen
103
105
  const zonalityUri = roadSignRegulation?.node.attrs.zonality as
104
106
  | string
105
107
  | undefined;
108
+ this.label = variable.node.attrs.label as string;
106
109
  if (zonalityUri === ZONAL_URI) {
107
110
  void this.fetchCodeListOptions.perform(
108
111
  source,
@@ -1,9 +1,15 @@
1
- <AuPill @icon="pencil" @iconAlignment="right" class="variable">
1
+ <AuPill @icon="pencil" @iconAlignment="right" class="variable" {{on 'click' this.onClick}}>
2
2
  <EmberNode::EmbeddedEditor
3
3
  @controller={{@controller}}
4
4
  @node={{@node}}
5
5
  @view={{@view}}
6
6
  @getPos={{@getPos}}
7
7
  @selected={{@selected}}
8
+ @initEditor={{this.initEditor}}
8
9
  />
10
+ {{#if @node.attrs.label}}
11
+ <span class="label">
12
+ ({{@node.attrs.label}})
13
+ </span>
14
+ {{/if}}
9
15
  </AuPill>
@@ -0,0 +1,39 @@
1
+ import Component from '@glimmer/component';
2
+ import {
3
+ NodeSelection,
4
+ SayController,
5
+ SayView,
6
+ } from '@lblod/ember-rdfa-editor';
7
+ import { tracked } from '@glimmer/tracking';
8
+ import { action } from '@ember/object';
9
+
10
+ type Args = {
11
+ controller: SayController;
12
+ };
13
+
14
+ export default class VariableComponent extends Component<Args> {
15
+ @tracked innerView?: SayView;
16
+
17
+ @action
18
+ onClick() {
19
+ if (this.innerView) {
20
+ if (this.innerView.state.doc.firstChild?.type.name === 'placeholder') {
21
+ this.innerView.focus();
22
+ // Use request animation frame to only change the selection when the focus has been established
23
+ window.requestAnimationFrame(() => {
24
+ if (this.innerView) {
25
+ const tr = this.innerView.state.tr;
26
+ tr.setSelection(NodeSelection.create(this.innerView?.state.doc, 0));
27
+ this.innerView?.dispatch(tr);
28
+ }
29
+ });
30
+ } else {
31
+ this.innerView.focus();
32
+ }
33
+ }
34
+ }
35
+ @action
36
+ initEditor(view: SayView) {
37
+ this.innerView = view;
38
+ }
39
+ }
@@ -5,8 +5,7 @@ import {
5
5
  Option,
6
6
  optionMapOr,
7
7
  } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/option';
8
- import Ember from 'ember';
9
- import SafeString = Ember.Handlebars.SafeString;
8
+ type SafeString = ReturnType<typeof htmlSafe>;
10
9
 
11
10
  interface DecisionArgs {
12
11
  uri: string;