@lblod/ember-rdfa-editor-lblod-plugins 1.0.0-beta.8 → 2.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 (43) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/addon/components/article-structure-plugin/structure-card.hbs +1 -1
  3. package/addon/components/besluit-type-plugin/toolbar-dropdown.hbs +5 -4
  4. package/addon/components/besluit-type-plugin/toolbar-dropdown.ts +7 -10
  5. package/addon/components/rdfa-date-plugin/card.hbs +87 -50
  6. package/addon/components/rdfa-date-plugin/card.ts +210 -61
  7. package/addon/components/rdfa-date-plugin/date-time-picker.hbs +5 -2
  8. package/addon/components/rdfa-date-plugin/date-time-picker.ts +11 -1
  9. package/addon/components/rdfa-date-plugin/help-modal.hbs +91 -0
  10. package/addon/components/rdfa-date-plugin/help-modal.ts +17 -0
  11. package/addon/components/rdfa-date-plugin/insert.ts +23 -0
  12. package/addon/components/roadsign-regulation-plugin/roadsign-regulation-card.hbs +2 -2
  13. package/addon/components/roadsign-regulation-plugin/roadsign-regulation-card.ts +8 -2
  14. package/addon/components/variable-plugin/insert-variable-card.hbs +1 -1
  15. package/addon/components/variable-plugin/template-variable-card.hbs +1 -1
  16. package/addon/plugins/article-structure-plugin/commands/insert-structure.ts +14 -2
  17. package/addon/plugins/article-structure-plugin/commands/move-selected-structure.ts +7 -7
  18. package/addon/plugins/article-structure-plugin/structures/article-paragraph.ts +4 -2
  19. package/addon/plugins/article-structure-plugin/structures/article.ts +4 -2
  20. package/addon/plugins/article-structure-plugin/structures/chapter.ts +2 -2
  21. package/addon/plugins/article-structure-plugin/structures/section.ts +2 -2
  22. package/addon/plugins/article-structure-plugin/structures/structure-header.ts +2 -0
  23. package/addon/plugins/article-structure-plugin/structures/subsection.ts +2 -2
  24. package/addon/plugins/article-structure-plugin/structures/title.ts +2 -2
  25. package/addon/plugins/article-structure-plugin/utils/structure.ts +2 -0
  26. package/addon/plugins/rdfa-date-plugin/index.ts +13 -10
  27. package/addon/plugins/rdfa-date-plugin/nodes/date.ts +22 -9
  28. package/addon/plugins/rdfa-date-plugin/utils.ts +72 -0
  29. package/addon/plugins/standard-template-plugin/utils/nodes.ts +3 -2
  30. package/addon/plugins/variable-plugin/nodes.ts +2 -0
  31. package/app/components/rdfa-date-plugin/help-modal.js +1 -0
  32. package/app/styles/date-plugin.scss +7 -1
  33. package/components/besluit-type-plugin/toolbar-dropdown.d.ts +3 -5
  34. package/components/rdfa-date-plugin/card.d.ts +28 -11
  35. package/components/rdfa-date-plugin/date-time-picker.d.ts +2 -0
  36. package/components/rdfa-date-plugin/help-modal.d.ts +10 -0
  37. package/components/rdfa-date-plugin/insert.d.ts +11 -0
  38. package/components/roadsign-regulation-plugin/roadsign-regulation-card.d.ts +2 -1
  39. package/package.json +5 -4
  40. package/plugins/rdfa-date-plugin/index.d.ts +2 -2
  41. package/plugins/rdfa-date-plugin/utils.d.ts +13 -0
  42. package/translations/en-US.yaml +39 -5
  43. package/translations/nl-BE.yaml +41 -10
package/CHANGELOG.md CHANGED
@@ -16,6 +16,31 @@
16
16
 
17
17
 
18
18
 
19
+
20
+ ## 2.0.0 (2023-02-06)
21
+ version-only bump to match editor major cycle
22
+
23
+
24
+ ## 1.0.0 (2023-02-06)
25
+
26
+ #### :boom: Breaking Change
27
+ * [#94](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/94) feat(dates): add nice error messages to custom format box ([@abeforgit](https://github.com/abeforgit))
28
+
29
+ #### :rocket: Enhancement
30
+ * [#94](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/94) feat(dates): add nice error messages to custom format box ([@abeforgit](https://github.com/abeforgit))
31
+ * [#93](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/93) Make headers and content nodes of structures isolating and defining ([@elpoelma](https://github.com/elpoelma))
32
+ * [#74](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/74) Feature/recreate uuids on paste ([@lagartoverde](https://github.com/lagartoverde))
33
+ * [#90](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/90) show error when the date format is empty ([@lagartoverde](https://github.com/lagartoverde))
34
+
35
+ #### :house: Internal
36
+ * [#92](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/92) Update editor to 2.0.1 ([@elpoelma](https://github.com/elpoelma))
37
+
38
+ #### Committers: 3
39
+ - Arne Bertrand ([@abeforgit](https://github.com/abeforgit))
40
+ - Elena Poelman ([@elpoelma](https://github.com/elpoelma))
41
+ - Oscar Rodriguez Villalobos ([@lagartoverde](https://github.com/lagartoverde))
42
+
43
+
19
44
  ## 1.0.0-beta.8 (2023-01-26)
20
45
 
21
46
  #### :house: Internal
@@ -1,7 +1,7 @@
1
1
  {{#unless this.isOutsideStructure}}
2
2
  <AuCard @flex={{true}} @divided={{true}} @expandable={{false}} @shadow={{true}} @size="flush" as |c|>
3
3
  <c.header class="au-u-hidden-visually">
4
- <AuHeading @level="3" @skin="6">{{t "article-structure-plugin.title.structureCard"}}</AuHeading>
4
+ <AuHeading @level="3" @skin="6">{{t "article-structure-plugin.title.structure-card"}}</AuHeading>
5
5
  </c.header>
6
6
  <c.content class="au-c-content--small">
7
7
  <AuList @divider={{true}} class="au-u-padding-top-tiny au-u-padding-bottom-tiny" as |Item|>
@@ -1,6 +1,7 @@
1
- <div {{did-update this.updateBesluitTypes @controller.state}}>
1
+ <div {{did-update this.updateBesluitTypes @controller.state}}
2
+ {{did-update this.updateBesluitTypes this.types.value}}>
2
3
  {{#if this.showCard}}
3
- {{#if this.loadDataTaskInstance.isError}}
4
+ {{#if this.types.isError}}
4
5
  <AuPill
5
6
  @skin="error"
6
7
  @icon="circle-x"
@@ -36,7 +37,7 @@
36
37
  class="au-c-modal--overflow"
37
38
  as |Modal|>
38
39
  <Modal.Body>
39
- {{#if this.loadDataTaskInstance.isError}}
40
+ {{#if this.types.isError}}
40
41
  <AuAlert
41
42
  @title={{t "besluit-type-plugin.error-title"}}
42
43
  @skin="error"
@@ -56,7 +57,7 @@
56
57
  </AuAlert>
57
58
  {{else}}
58
59
  <BesluitTypePlugin::BesluitTypeSelect
59
- @besluitTypes={{this.types}}
60
+ @besluitTypes={{this.types.value}}
60
61
  @onchange={{this.updateBesluitType}}
61
62
  @selected={{this.besluit}}
62
63
  @showWarningWhenEmpty={{false}}/>
@@ -1,7 +1,6 @@
1
1
  import { tracked } from '@glimmer/tracking';
2
2
  import Component from '@glimmer/component';
3
3
  import { action } from '@ember/object';
4
- import { task } from 'ember-concurrency';
5
4
  import { getOwner } from '@ember/application';
6
5
  import { inject as service } from '@ember/service';
7
6
  import {
@@ -17,6 +16,7 @@ import fetchBesluitTypes, {
17
16
  BesluitType,
18
17
  } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/besluit-type-plugin/utils/fetchBesluitTypes';
19
18
  import { findAncestorOfType } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/article-structure-plugin/utils/structure';
19
+ import { trackedFunction } from 'ember-resources/util/function';
20
20
 
21
21
  declare module 'ember__owner' {
22
22
  export default interface Owner {
@@ -39,7 +39,6 @@ export default class EditorPluginsToolbarDropdownComponent extends Component<Arg
39
39
  */
40
40
  @tracked besluitType?: BesluitType;
41
41
  @tracked previousBesluitType?: string;
42
- @tracked types: BesluitType[] = [];
43
42
 
44
43
  //used to update selections since the other vars dont seem to work in octane
45
44
  @tracked besluit?: BesluitType;
@@ -47,11 +46,9 @@ export default class EditorPluginsToolbarDropdownComponent extends Component<Arg
47
46
  @tracked subSubBesluit?: BesluitType;
48
47
 
49
48
  @tracked cardExpanded = false;
50
- @tracked loadDataTaskInstance;
51
49
 
52
50
  constructor(parent: unknown, args: Args) {
53
51
  super(parent, args);
54
- this.loadDataTaskInstance = this.loadData.perform();
55
52
  }
56
53
 
57
54
  get controller() {
@@ -62,7 +59,7 @@ export default class EditorPluginsToolbarDropdownComponent extends Component<Arg
62
59
  return this.controller.state.doc;
63
60
  }
64
61
 
65
- loadData = task(async () => {
62
+ types = trackedFunction(this, async () => {
66
63
  // eslint-disable-next-line @typescript-eslint/await-thenable
67
64
  const bestuurseenheid = await this.currentSession.get('group');
68
65
  const classificatie = await bestuurseenheid.get('classificatie');
@@ -70,7 +67,7 @@ export default class EditorPluginsToolbarDropdownComponent extends Component<Arg
70
67
  besluitTypePlugin: { endpoint: string };
71
68
  };
72
69
  const types = await fetchBesluitTypes(classificatie.uri, ENV);
73
- this.types = types;
70
+ return types;
74
71
  });
75
72
 
76
73
  get currentBesluitRange(): ResolvedPNode | undefined {
@@ -103,7 +100,7 @@ export default class EditorPluginsToolbarDropdownComponent extends Component<Arg
103
100
 
104
101
  @action
105
102
  updateBesluitTypes() {
106
- if (!this.currentBesluitURI) {
103
+ if (!this.currentBesluitURI || !this.types.value) {
107
104
  return;
108
105
  }
109
106
  const besluit = findAncestorOfType(
@@ -169,7 +166,7 @@ export default class EditorPluginsToolbarDropdownComponent extends Component<Arg
169
166
 
170
167
  findBesluitTypeParent(
171
168
  besluitType?: BesluitType,
172
- array: BesluitType[] = this.types,
169
+ array: BesluitType[] | null = this.types.value,
173
170
  parent?: BesluitType
174
171
  ): BesluitType | undefined {
175
172
  if (!besluitType || !array) {
@@ -188,9 +185,9 @@ export default class EditorPluginsToolbarDropdownComponent extends Component<Arg
188
185
 
189
186
  findBesluitTypeByURI(
190
187
  uri: string,
191
- types = this.types
188
+ types = this.types.value
192
189
  ): BesluitType | undefined {
193
- if (uri) {
190
+ if (uri && types) {
194
191
  for (const besluitType of types) {
195
192
  if (besluitType.uri === uri) {
196
193
  return besluitType;
@@ -1,52 +1,89 @@
1
- <div {{did-update this.onSelectionChanged @controller.state}}>
2
- {{#if this.showCard}}
3
- <AuCard @shadow={{true}} @size="flush" as |c|>
4
- <c.header class="au-u-hidden-visually">
5
- <AuHeading @level="3" @skin="6">{{t "date-plugin.card.title"}}</AuHeading>
6
- </c.header>
7
- <c.content class="au-o-box au-o-box--small">
8
- <div class="au-o-flow au-o-flow--small">
9
- <RdfaDatePlugin::DateTimePicker
10
- @onChange={{this.changeDate}}
11
- @value={{this.dateValue}}
12
- @onlyDate={{this.onlyDate}}/>
13
- {{#each @widgetArgs.options.formats as |format|}}
14
- <AuFormRow>
15
- <AuControlRadio
16
- @label={{format.label}}
17
- @identifier={{format.key}}
18
- @name="dateFormat"
19
- @value={{format.key}}
20
- checked={{eq this.dateFormat format.key}}
21
- @onChange={{this.setDateFormat}}
22
- />
23
- </AuFormRow>
24
- {{/each}}
25
- <AuFormRow>
26
- <AuControlRadio
27
- @label="Custom Date"
28
- @identifier="custom"
29
- @name="dateFormat"
30
- @value="custom"
31
- checked={{eq this.dateFormat "custom"}}
32
- @onChange={{this.setDateFormat}}
33
- />
34
- {{#if (eq this.dateFormat "custom")}}
35
- <AuInput
36
- @value={{this.customDateFormat}}
37
- {{on "input" this.setCustomDateFormat}}
1
+ <div>
2
+ {{#if this.showCard}}
3
+ <AuCard @shadow={{true}} @size="flush" as |c|>
4
+ <c.header class="au-u-hidden-visually">
5
+ <AuHeading @level="3" @skin="6">{{t "date-plugin.card.title"}}</AuHeading>
6
+ </c.header>
7
+ <c.content class="au-o-box au-o-box--small">
8
+ <div class="au-o-flow au-o-flow--small">
9
+ <RdfaDatePlugin::DateTimePicker
10
+ @onChange={{this.changeDate}}
11
+ @value={{this.pickerDate}}
12
+ @onlyDate={{this.onlyDate}}
13
+ @showSeconds={{this.showSeconds}}
14
+ >
15
+
16
+ <AuFormRow @alignment="inline">
17
+ <AuControlCheckbox
18
+ @label={{t 'date-plugin.card.include-time'}}
19
+ @disabled={{eq this.dateFormatType "custom"}}
20
+ @checked={{not this.onlyDate}}
21
+ @onChange={{this.changeIncludeTime}}
22
+ />
23
+ {{#if this.isCustom}}
24
+ <Velcro @placement="top" @offsetOptions={{hash mainAxis=10}} as |velcro|>
25
+ <AuBadge
26
+ @size="small"
27
+ @icon="info-circle"
28
+ aria-describedby="date-plugin-time-info-tooltip"
29
+ {{velcro.hook}}
30
+ {{on "mouseenter" this.showTooltip }}
31
+ {{on "mouseleave" this.hideTooltip}}
32
+ {{on "focus" this.showTooltip }}
33
+ {{on "blur" this.hideTooltip }}
34
+ />
35
+ {{#if this.tooltipOpen}}
36
+ <AuPill
37
+ id="date-plugin-time-info-tooltip"
38
+ role="tooltip"
39
+ {{velcro.loop}}>
40
+ {{t 'date-plugin.card.info-custom-time'}}
41
+ </AuPill>
42
+ {{/if}}
43
+ </Velcro>
44
+ {{/if}}
45
+ </AuFormRow>
46
+ </RdfaDatePlugin::DateTimePicker>
47
+ {{#each this.formats as |format|}}
48
+ <AuFormRow>
49
+ <AuControlRadio
50
+ @label={{format.label}}
51
+ @identifier={{format.key}}
52
+ @name="dateFormat"
53
+ @value={{format.key}}
54
+ checked={{eq this.dateFormatType format.key}}
55
+ @onChange={{this.setDateFormatFromKey}}
56
+ />
57
+ </AuFormRow>
58
+ {{/each}}
59
+ <AuFormRow>
60
+ <AuControlRadio
61
+ @label={{t "date-plugin.card.custom-date" }}
62
+ @identifier="custom"
63
+ @name="dateFormat"
64
+ @value="custom"
65
+ checked={{eq this.dateFormatType "custom"}}
66
+ @onChange={{this.setDateFormatFromKey}}
38
67
  />
39
- {{/if}}
40
- </AuFormRow>
41
- {{#unless this.dateInDocument}}
42
- <AuFormRow class="au-u-margin-top">
43
- <AuButton {{on 'click' this.modifyDate}}>
44
- {{if this.onlyDate (t "date-plugin.card.insert-date") (t "date-plugin.card.insert-datetime")}}
45
- </AuButton>
46
68
  </AuFormRow>
47
- {{/unless}}
48
- </div>
49
- </c.content>
50
- </AuCard>
51
- {{/if}}
52
- </div>
69
+ {{#if (eq this.dateFormatType "custom")}}
70
+ <AuFormRow @alignment="post">
71
+ <AuButton @skin="secondary" @icon="info-circle"
72
+ {{on 'click' this.toggleHelpModal}}>
73
+ </AuButton>
74
+ <AuNativeInput
75
+ @error={{this.customDateFormatError}}
76
+ value={{this.documentDateFormat}}
77
+ {{on "input" this.setCustomDateFormat}}
78
+ />
79
+ </AuFormRow>
80
+ {{#if this.humanError}}
81
+ <AuPill @skin="error" @icon="cross">{{this.humanError}}</AuPill>
82
+ {{/if}}
83
+ {{/if}}
84
+ </div>
85
+ </c.content>
86
+ </AuCard>
87
+ {{/if}}
88
+ </div>
89
+ <RdfaDatePlugin::HelpModal @modalOpen={{this.helpModalOpen}} @closeModal={{this.toggleHelpModal}} />
@@ -2,8 +2,22 @@ import Component from '@glimmer/component';
2
2
  import { tracked } from '@glimmer/tracking';
3
3
  import { action } from '@ember/object';
4
4
  import { ProseController } from '@lblod/ember-rdfa-editor/core/prosemirror';
5
- import { NodeSelection } from '@lblod/ember-rdfa-editor';
5
+ import { NodeSelection, PNode } from '@lblod/ember-rdfa-editor';
6
6
  import { DateFormat } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/rdfa-date-plugin';
7
+ import {
8
+ validateDateFormat,
9
+ ValidationError,
10
+ } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/rdfa-date-plugin/utils';
11
+ import { inject as service } from '@ember/service';
12
+ import IntlService from 'ember-intl/services/intl';
13
+ import {
14
+ isNone,
15
+ isSome,
16
+ Option,
17
+ optionMap,
18
+ optionMapOr,
19
+ unwrapOr,
20
+ } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/option';
7
21
 
8
22
  type Args = {
9
23
  controller: ProseController;
@@ -14,93 +28,228 @@ type Args = {
14
28
  };
15
29
  };
16
30
  };
31
+ const TIME_CHAR_REGEX = new RegExp('[abBhHkKmsStTp]');
32
+ const SECONDS_REGEX = new RegExp('[sStT]|p{2,}');
17
33
  export default class RdfaDatePluginCardComponent extends Component<Args> {
18
- @tracked dateValue?: Date;
19
- @tracked datePos?: number;
20
- @tracked dateInDocument = false;
21
- @tracked onlyDate = false;
22
- @tracked dateFormat = '';
23
- @tracked customDateFormat = 'dd/MM/yyyy';
34
+ @service
35
+ declare intl: IntlService;
24
36
 
25
- constructor(owner: unknown, args: Args) {
26
- super(owner, args);
27
- const formats = this.args.widgetArgs.options.formats;
28
- const firstKey = [...formats.keys()][0];
29
- this.dateFormat = formats[firstKey].key;
37
+ @tracked helpModalOpen = false;
38
+ @tracked
39
+ tooltipOpen = false;
40
+
41
+ get formats(): DateFormat[] {
42
+ return this.args.widgetArgs.options.formats;
30
43
  }
31
44
 
32
45
  get controller() {
33
46
  return this.args.controller;
34
47
  }
35
48
 
49
+ get selection() {
50
+ return this.controller.getState(true).selection;
51
+ }
52
+
53
+ get selectedDateNode(): Option<PNode> {
54
+ if (
55
+ this.selection instanceof NodeSelection &&
56
+ this.selection.node.type === this.args.controller.schema.nodes['date']
57
+ ) {
58
+ return this.selection.node;
59
+ } else {
60
+ return null;
61
+ }
62
+ }
63
+
64
+ get documentDate(): Option<Date> {
65
+ const dateVal = this.selectedDateNode?.attrs.value as Option<string>;
66
+ if (dateVal) {
67
+ return new Date(dateVal);
68
+ }
69
+ return null;
70
+ }
71
+
72
+ get documentDatePos(): Option<number> {
73
+ if (this.selectedDateNode) {
74
+ return this.selection.from;
75
+ }
76
+ return null;
77
+ }
78
+
79
+ get showCard() {
80
+ return isSome(this.documentDatePos);
81
+ }
82
+
83
+ get onlyDate(): boolean {
84
+ return optionMapOr(
85
+ false,
86
+ (node) => {
87
+ const format = node.attrs.format as string;
88
+ return !TIME_CHAR_REGEX.test(format);
89
+ },
90
+ this.selectedDateNode
91
+ );
92
+ }
93
+
94
+ get showSeconds(): boolean {
95
+ return optionMapOr(
96
+ false,
97
+ (node) => {
98
+ const format = node.attrs.format as string;
99
+ return SECONDS_REGEX.test(format);
100
+ },
101
+ this.selectedDateNode
102
+ );
103
+ }
104
+
105
+ get documentDateFormat(): Option<string> {
106
+ return optionMap(
107
+ (node) => node.attrs.format as string,
108
+ this.selectedDateNode
109
+ );
110
+ }
111
+
112
+ get documentDateFormatType(): Option<DateFormat> {
113
+ if (this.documentDateFormat) {
114
+ if (this.onlyDate) {
115
+ return this.formats.find(
116
+ (format) => format.dateFormat === this.documentDateFormat
117
+ );
118
+ } else {
119
+ return this.formats.find(
120
+ (format) => format.dateTimeFormat === this.documentDateFormat
121
+ );
122
+ }
123
+ }
124
+ return null;
125
+ }
126
+
127
+ get isCustom(): boolean {
128
+ return unwrapOr(false, this.selectedDateNode?.attrs.custom as boolean);
129
+ }
130
+
131
+ get dateFormatType(): string {
132
+ if (this.isCustom) {
133
+ return 'custom';
134
+ }
135
+ return this.documentDateFormatType?.key || 'custom';
136
+ }
137
+
138
+ get customDateFormatError(): ValidationError | null {
139
+ const format = this.documentDateFormat ?? '';
140
+ const validation = validateDateFormat(format);
141
+ if (validation.type === 'ok') {
142
+ return null;
143
+ } else {
144
+ return validation;
145
+ }
146
+ }
147
+
148
+ get humanError(): string | null {
149
+ if (this.customDateFormatError) {
150
+ const { error, payload } = this.customDateFormatError;
151
+ if (error === 'character') {
152
+ const msg = this.intl.lookup(`date-plugin.validation.${error}`) ?? '';
153
+ const suggestion =
154
+ this.intl.lookup('date-plugin.validation.character-suggestion') ?? '';
155
+ const chars = payload?.invalidCharacters ?? '';
156
+ return `${msg}: ${chars}. ${suggestion}: '${chars}'`;
157
+ }
158
+ return this.intl.lookup(`date-plugin.validation.${error}`) ?? null;
159
+ }
160
+ return null;
161
+ }
162
+
163
+ get pickerDate(): Date {
164
+ return this.documentDate ?? new Date();
165
+ }
166
+
36
167
  @action
37
- modifyDate() {
38
- if (this.datePos && this.dateValue) {
39
- const pos = this.datePos;
40
- const value = this.dateValue;
168
+ showTooltip() {
169
+ this.tooltipOpen = true;
170
+ }
171
+
172
+ @action hideTooltip() {
173
+ this.tooltipOpen = false;
174
+ }
175
+
176
+ @action
177
+ changeDate(date: Date) {
178
+ const pos = this.documentDatePos;
179
+ if (pos) {
41
180
  this.controller.withTransaction((tr) => {
42
- tr.setNodeAttribute(pos, 'format', this.customDateFormat);
43
- return tr.setNodeAttribute(pos, 'value', value.toISOString());
181
+ return tr.setNodeAttribute(pos, 'value', date.toISOString());
44
182
  }, true);
45
183
  }
46
184
  }
47
185
 
48
186
  @action
49
- changeDate(date: Date) {
50
- this.dateValue = date;
51
- if (this.dateInDocument) this.modifyDate();
187
+ changeIncludeTime(includeTime: boolean) {
188
+ console.log('Include time', includeTime);
189
+ if (this.isCustom) {
190
+ console.log("but it's custom");
191
+ return;
192
+ }
193
+ const dateFormatType = this.documentDateFormatType;
194
+ if (dateFormatType) {
195
+ if (includeTime) {
196
+ this.setDateFormat(dateFormatType.dateTimeFormat, false);
197
+ } else {
198
+ this.setDateFormat(dateFormatType.dateFormat, false);
199
+ }
200
+ }
201
+ }
202
+
203
+ setDateFormat(dateFormat: string, custom = false) {
204
+ const pos = this.documentDatePos;
205
+ if (isNone(pos)) {
206
+ return;
207
+ }
208
+ this.controller.withTransaction((tr) => {
209
+ return tr
210
+ .setNodeAttribute(pos, 'format', dateFormat)
211
+ .setNodeAttribute(pos, 'custom', custom)
212
+ .setNodeAttribute(pos, 'onlyDate', this.onlyDate);
213
+ }, true);
52
214
  }
53
215
 
54
216
  @action
55
- setDateFormat(dateFormat: string) {
56
- this.dateFormat = dateFormat;
57
- if (dateFormat !== 'custom') {
58
- const format = this.args.widgetArgs.options.formats.find(
59
- (format) => format.key === dateFormat
60
- );
217
+ setDateFormatFromKey(formatKey: string) {
218
+ const pos = this.documentDatePos;
219
+ if (isNone(pos)) {
220
+ return;
221
+ }
222
+ if (formatKey === 'custom') {
223
+ this.controller.withTransaction((tr) => {
224
+ return tr.setNodeAttribute(pos, 'custom', true);
225
+ }, true);
226
+ } else {
227
+ const format = this.formats.find((format) => format.key === formatKey);
61
228
  if (format) {
62
- if (this.onlyDate) {
63
- this.customDateFormat = format.dateFormat;
64
- } else {
65
- this.customDateFormat = format.dateTimeFormat;
66
- }
229
+ this.setDateFormat(
230
+ this.onlyDate ? format.dateFormat : format.dateTimeFormat,
231
+ false
232
+ );
67
233
  }
68
234
  }
69
- if (this.dateInDocument) this.modifyDate();
70
235
  }
236
+
71
237
  @action
72
238
  setCustomDateFormat(event: InputEvent) {
73
- this.customDateFormat = (event.target as HTMLInputElement).value;
74
- if (this.dateInDocument) this.modifyDate();
75
- }
239
+ const format = (event.target as HTMLInputElement).value;
76
240
 
77
- get showCard() {
78
- return this.datePos !== undefined && this.datePos !== null;
241
+ const pos = this.documentDatePos;
242
+ if (isSome(pos) && isSome(format)) {
243
+ this.controller.withTransaction((tr) => {
244
+ return tr
245
+ .setNodeAttribute(pos, 'format', format)
246
+ .setNodeAttribute(pos, 'onlyDate', this.onlyDate);
247
+ }, true);
248
+ }
79
249
  }
80
250
 
81
251
  @action
82
- onSelectionChanged() {
83
- const selection = this.controller.getState(true).selection;
84
- if (
85
- selection instanceof NodeSelection &&
86
- selection.node.type === this.args.controller.schema.nodes['date']
87
- ) {
88
- this.dateInDocument = !!selection.node.attrs.value;
89
- this.onlyDate = selection.node.attrs.onlyDate as boolean;
90
- this.dateValue = this.dateInDocument
91
- ? new Date(selection.node.attrs.value)
92
- : new Date();
93
- if (this.dateInDocument) {
94
- this.dateValue = new Date(selection.node.attrs.value);
95
- } else {
96
- this.dateValue = new Date();
97
- if (this.onlyDate) {
98
- this.dateValue.setHours(0, 0, 0, 0);
99
- }
100
- }
101
- this.datePos = selection.from;
102
- } else {
103
- this.datePos = undefined;
104
- }
252
+ toggleHelpModal() {
253
+ this.helpModalOpen = !this.helpModalOpen;
105
254
  }
106
255
  }
@@ -5,17 +5,20 @@
5
5
  @label={{t "date-plugin.card.label"}}
6
6
  @localization={{this.datePickerLocalization}}/>
7
7
  </AuFormRow>
8
+ {{yield}}
8
9
  {{#unless @onlyDate}}
9
10
  <AuFormRow>
10
11
  <AuTimePicker
11
12
  @hoursLabel={{t "date-plugin.card.hours"}}
12
13
  @minutesLabel={{t "date-plugin.card.minutes"}}
14
+ @secondsLabel={{t "date-plugin.card.seconds"}}
13
15
  @nowLabel={{t "date-plugin.card.now"}}
14
16
  @hours={{this.hours}}
15
17
  @minutes={{this.minutes}}
16
- @showSeconds={{false}}
18
+ @seconds={{this.seconds}}
19
+ @showSeconds={{@showSeconds}}
17
20
  @showNow={{true}}
18
21
  @onChange={{this.onChangeTime}}
19
- />
22
+ />
20
23
  </AuFormRow>
21
24
  {{/unless}}
@@ -5,6 +5,7 @@ import { inject as service } from '@ember/service';
5
5
  // @ts-ignore
6
6
  import { localCopy } from 'tracked-toolbox';
7
7
  import Intl from 'ember-intl/services/intl';
8
+
8
9
  type Args = {
9
10
  value: Date;
10
11
  onChange: (date: Date) => void;
@@ -23,6 +24,10 @@ export default class RdfaDatePluginDateTimePicker extends Component<Args> {
23
24
  return this.date.getMinutes();
24
25
  }
25
26
 
27
+ get seconds() {
28
+ return this.date.getSeconds();
29
+ }
30
+
26
31
  get datePickerLocalization() {
27
32
  return {
28
33
  buttonLabel: this.intl.t('auDatePicker.buttonLabel'),
@@ -56,10 +61,15 @@ export default class RdfaDatePluginDateTimePicker extends Component<Args> {
56
61
  }
57
62
 
58
63
  @action
59
- onChangeTime(timeObject: { hours: number; minutes: number }) {
64
+ onChangeTime(timeObject: {
65
+ hours: number;
66
+ minutes: number;
67
+ seconds: number;
68
+ }) {
60
69
  if (!this.date) this.date = new Date();
61
70
  this.date.setHours(timeObject.hours);
62
71
  this.date.setMinutes(timeObject.minutes);
72
+ this.date.setSeconds(timeObject.seconds);
63
73
  this.args.onChange(this.date);
64
74
  }
65
75
  }