@lblod/ember-rdfa-editor-lblod-plugins 38.2.0 → 38.3.0-dev.d90fd82598dbe0c2a18f7ced268012b9d80a4352

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 (42) hide show
  1. package/.changeset/clean-trains-punch.md +5 -0
  2. package/CHANGELOG.md +8 -0
  3. package/addon/components/lmb-plugin/insert.ts +11 -5
  4. package/addon/components/variable-plugin/date/{date-time-picker.ts → date-picker.gts} +46 -42
  5. package/addon/components/variable-plugin/date/date-time-picker.gts +42 -0
  6. package/addon/components/variable-plugin/date/{edit.ts → edit.gts} +176 -11
  7. package/addon/components/variable-plugin/date/floating-date-container.gts +54 -0
  8. package/addon/components/variable-plugin/date/time-picker.gts +61 -0
  9. package/addon/components/variable-plugin/person/edit.ts +15 -41
  10. package/addon/plugins/lmb-plugin/index.ts +84 -0
  11. package/addon/plugins/location-plugin/contextual-actions/index.ts +11 -5
  12. package/addon/plugins/location-plugin/node.ts +4 -4
  13. package/addon/plugins/location-plugin/utils/replace-location.ts +2 -30
  14. package/addon/plugins/variable-plugin/contextual-actions/person.ts +140 -0
  15. package/addon/plugins/variable-plugin/utils/replace-person.ts +64 -0
  16. package/addon/plugins/variable-plugin/variables/address.ts +5 -4
  17. package/addon/plugins/variable-plugin/variables/date.ts +10 -3
  18. package/addon/plugins/variable-plugin/variables/number.ts +3 -1
  19. package/addon/plugins/variable-plugin/variables/person.ts +32 -2
  20. package/addon/{plugins/location-plugin/utils/get-document-locations.ts → utils/get-ranked-pnodes.ts} +34 -34
  21. package/addon/utils/move-node-selection-forward.ts +27 -0
  22. package/app/styles/variable-plugin.scss +10 -0
  23. package/declarations/addon/components/lmb-plugin/insert.d.ts +1 -1
  24. package/declarations/addon/components/variable-plugin/date/date-picker.d.ts +44 -0
  25. package/declarations/addon/components/variable-plugin/date/date-time-picker.d.ts +11 -27
  26. package/declarations/addon/components/variable-plugin/date/edit.d.ts +15 -12
  27. package/declarations/addon/components/variable-plugin/date/floating-date-container.d.ts +21 -0
  28. package/declarations/addon/components/variable-plugin/date/time-picker.d.ts +22 -0
  29. package/declarations/addon/components/variable-plugin/person/edit.d.ts +3 -6
  30. package/declarations/addon/plugins/lmb-plugin/index.d.ts +11 -0
  31. package/declarations/addon/plugins/location-plugin/contextual-actions/index.d.ts +2 -7
  32. package/declarations/addon/plugins/variable-plugin/contextual-actions/person.d.ts +4 -0
  33. package/declarations/addon/plugins/variable-plugin/utils/replace-person.d.ts +5 -0
  34. package/declarations/addon/plugins/variable-plugin/variables/person.d.ts +4 -0
  35. package/declarations/addon/utils/get-ranked-pnodes.d.ts +6 -0
  36. package/declarations/addon/utils/move-node-selection-forward.d.ts +2 -0
  37. package/package.json +2 -2
  38. package/translations/en-US.yaml +4 -0
  39. package/translations/nl-BE.yaml +6 -0
  40. package/addon/components/variable-plugin/date/date-time-picker.hbs +0 -26
  41. package/addon/components/variable-plugin/date/edit.hbs +0 -113
  42. package/declarations/addon/plugins/location-plugin/utils/get-document-locations.d.ts +0 -4
@@ -0,0 +1,5 @@
1
+ ---
2
+ '@lblod/ember-rdfa-editor-lblod-plugins': patch
3
+ ---
4
+
5
+ Fix floating window position on date variable
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @lblod/ember-rdfa-editor-lblod-plugins
2
2
 
3
+ ## 38.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#676](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/676) [`c7c44ec`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/c7c44ec8b883dbcc3330f33c0638d764684eb1e9) Thanks [@kobemertens](https://github.com/kobemertens)! - Add document-local suggestions for person variables
8
+
9
+ - [#678](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/678) [`294b023`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/294b023cdd48d946d8c2b49ec2c5ae947d97f64a) Thanks [@kobemertens](https://github.com/kobemertens)! - Add floating edit window for date variable nodes
10
+
3
11
  ## 38.2.0
4
12
 
5
13
  ### Minor Changes
@@ -1,10 +1,14 @@
1
1
  import { action } from '@ember/object';
2
2
  import Component from '@glimmer/component';
3
- import { tracked } from '@glimmer/tracking';
4
3
  import { AddIcon } from '@appuniversum/ember-appuniversum/components/icons/add';
5
4
 
6
5
  import { SayController } from '@lblod/ember-rdfa-editor';
7
- import { LmbPluginConfig } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/lmb-plugin';
6
+ import {
7
+ closeLmbModal,
8
+ getLmbModalsPluginState,
9
+ LmbPluginConfig,
10
+ openLmbModal,
11
+ } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/lmb-plugin';
8
12
  import Electee from '@lblod/ember-rdfa-editor-lblod-plugins/models/electee';
9
13
  import { replaceSelectionWithAndSelectNode } from '@lblod/ember-rdfa-editor-lblod-plugins/commands';
10
14
  import { service } from '@ember/service';
@@ -22,7 +26,9 @@ export default class LmbPluginInsertComponent extends Component<Args> {
22
26
  @service declare intl: IntlService;
23
27
  AddIcon = AddIcon;
24
28
 
25
- @tracked showModal = false;
29
+ get showModal() {
30
+ return getLmbModalsPluginState(this.controller.mainEditorState)?.modalOpen;
31
+ }
26
32
 
27
33
  get controller() {
28
34
  return this.args.controller;
@@ -31,12 +37,12 @@ export default class LmbPluginInsertComponent extends Component<Args> {
31
37
  @action
32
38
  openModal() {
33
39
  this.controller.focus();
34
- this.showModal = true;
40
+ openLmbModal(this.controller.mainEditorView);
35
41
  }
36
42
 
37
43
  @action
38
44
  closeModal() {
39
- this.showModal = false;
45
+ closeLmbModal(this.controller.mainEditorView);
40
46
  }
41
47
 
42
48
  @action
@@ -4,27 +4,20 @@ import { service } from '@ember/service';
4
4
  import { localCopy } from 'tracked-toolbox';
5
5
  import Intl from 'ember-intl/services/intl';
6
6
 
7
- type Args = {
8
- value?: Date;
9
- onChange: (date: Date) => void;
7
+ import AuDatePicker from '@appuniversum/ember-appuniversum/components/au-date-picker';
8
+ import t from 'ember-intl/helpers/t';
9
+
10
+ type Sig = {
11
+ Args: {
12
+ value?: Date | null;
13
+ onChange: (date: Date) => void;
14
+ };
10
15
  };
11
16
 
12
- export default class DateTimePickerComponent extends Component<Args> {
17
+ export default class DatePickerComponent extends Component<Sig> {
13
18
  @service declare intl: Intl;
14
19
  @localCopy('args.value') declare date?: Date;
15
20
 
16
- get hours() {
17
- return this.date?.getHours();
18
- }
19
-
20
- get minutes() {
21
- return this.date?.getMinutes();
22
- }
23
-
24
- get seconds() {
25
- return this.date?.getSeconds();
26
- }
27
-
28
21
  get datePickerLocalization() {
29
22
  return {
30
23
  buttonLabel: this.intl.t('au-date-picker.button-label'),
@@ -39,38 +32,49 @@ export default class DateTimePickerComponent extends Component<Args> {
39
32
  monthNames: getLocalizedMonths(this.intl),
40
33
  monthNamesShort: getLocalizedMonths(this.intl, 'short'),
41
34
  placeholder: this.intl.t('au-date-picker.placeholder'),
35
+ locale: this.intl.primaryLocale ?? 'nl-BE',
42
36
  };
43
37
  }
44
38
 
45
39
  @action
46
- onChangeDate(_isoDate: unknown, date: Date) {
47
- const wasDateInputCleared = !date;
48
- if (!wasDateInputCleared) {
49
- if (!this.date) {
50
- this.date = new Date();
51
- this.date.setHours(0, 0, 0, 0);
52
- }
53
- this.date.setFullYear(date.getFullYear());
54
- this.date.setMonth(date.getMonth());
55
- this.date.setDate(date.getDate());
56
- this.args.onChange(this.date);
57
- }
58
- }
40
+ onChangeDate(_isoDate: unknown | null, date: Date | null) {
41
+ if (!date) return;
59
42
 
60
- @action
61
- onChangeTime(timeObject: {
62
- hours: number;
63
- minutes: number;
64
- seconds: number;
65
- }) {
66
- if (!this.date) this.date = new Date();
67
- this.date.setHours(timeObject.hours);
68
- this.date.setMinutes(timeObject.minutes);
69
- this.date.setSeconds(timeObject.seconds);
43
+ if (!this.date) {
44
+ this.date = new Date();
45
+ this.date.setHours(0, 0, 0, 0);
46
+ }
47
+ this.date.setFullYear(date.getFullYear());
48
+ this.date.setMonth(date.getMonth());
49
+ this.date.setDate(date.getDate());
70
50
  this.args.onChange(this.date);
71
51
  }
52
+
53
+ <template>
54
+ <AuDatePicker
55
+ @onChange={{this.onChangeDate}}
56
+ @value={{this.date}}
57
+ @label={{t 'date-plugin.card.label'}}
58
+ @localization={{this.datePickerLocalization}}
59
+ />
60
+ </template>
72
61
  }
73
62
 
63
+ type MonthNames = [
64
+ string,
65
+ string,
66
+ string,
67
+ string,
68
+ string,
69
+ string,
70
+ string,
71
+ string,
72
+ string,
73
+ string,
74
+ string,
75
+ string,
76
+ ];
77
+ type DayNames = [string, string, string, string, string, string, string];
74
78
  function getLocalizedMonths(
75
79
  intl: Intl,
76
80
  monthFormat: 'long' | 'numeric' | '2-digit' | 'short' | 'narrow' = 'long',
@@ -79,17 +83,17 @@ function getLocalizedMonths(
79
83
  return [...Array(12).keys()].map((monthIndex) => {
80
84
  const date = new Date(someYear, monthIndex);
81
85
  return intl.formatDate(date, { month: monthFormat });
82
- });
86
+ }) as MonthNames;
83
87
  }
84
88
 
85
89
  function getLocalizedDays(
86
90
  intl: Intl,
87
91
  weekdayFormat: 'long' | 'short' | 'narrow' = 'long',
88
- ) {
92
+ ): DayNames {
89
93
  const someSunday = new Date('2021-01-03');
90
94
  return [...Array(7).keys()].map((index) => {
91
95
  const weekday = new Date(someSunday.getTime());
92
96
  weekday.setDate(someSunday.getDate() + index);
93
97
  return intl.formatDate(weekday, { weekday: weekdayFormat });
94
- });
98
+ }) as DayNames;
95
99
  }
@@ -0,0 +1,42 @@
1
+ import Component from '@glimmer/component';
2
+ import { service } from '@ember/service';
3
+ import { localCopy } from 'tracked-toolbox';
4
+ import Intl from 'ember-intl/services/intl';
5
+
6
+ import DatePicker from '@lblod/ember-rdfa-editor-lblod-plugins/components/variable-plugin/date/date-picker';
7
+ import AuFormRow from '@appuniversum/ember-appuniversum/components/au-form-row';
8
+ import TimePicker from '@lblod/ember-rdfa-editor-lblod-plugins/components/variable-plugin/date/time-picker';
9
+
10
+ type Sig = {
11
+ Args: {
12
+ value?: Date | null;
13
+ onlyDate?: boolean;
14
+ showSeconds?: boolean;
15
+
16
+ onChange: (date: Date) => void;
17
+ };
18
+ Blocks: {
19
+ default: [];
20
+ };
21
+ };
22
+
23
+ export default class DateTimePickerComponent extends Component<Sig> {
24
+ @service declare intl: Intl;
25
+ @localCopy('args.value') declare date?: Date;
26
+
27
+ <template>
28
+ <AuFormRow>
29
+ <DatePicker @onChange={{@onChange}} @value={{this.date}} />
30
+ </AuFormRow>
31
+ {{yield}}
32
+ {{#unless @onlyDate}}
33
+ <AuFormRow>
34
+ <TimePicker
35
+ @showSeconds={{@showSeconds}}
36
+ @onChange={{@onChange}}
37
+ @value={{this.date}}
38
+ />
39
+ </AuFormRow>
40
+ {{/unless}}
41
+ </template>
42
+ }
@@ -32,18 +32,36 @@ import { InfoCircleIcon } from '@appuniversum/ember-appuniversum/components/icon
32
32
  import { CrossIcon } from '@appuniversum/ember-appuniversum/components/icons/cross';
33
33
  import { XSD } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
34
34
  import AuCard from '../../_private/appuniversum-overrides/au-card';
35
+ import { v4 as uuidv4 } from 'uuid';
35
36
 
36
- type Args = {
37
- controller: SayController;
38
- options: DateOptions;
37
+ import AuFormRow from '@appuniversum/ember-appuniversum/components/au-form-row';
38
+ import AuCheckbox from '@appuniversum/ember-appuniversum/components/au-checkbox';
39
+ import AuBadge from '@appuniversum/ember-appuniversum/components/au-badge';
40
+ import AuPill from '@appuniversum/ember-appuniversum/components/au-pill';
41
+ import AuRadioGroup from '@appuniversum/ember-appuniversum/components/au-radio-group';
42
+ import AuButton from '@appuniversum/ember-appuniversum/components/au-button';
43
+ import AuNativeInput from '@lblod/ember-rdfa-editor-lblod-plugins/components/au-native-input';
44
+ import TimePicker from '@lblod/ember-rdfa-editor-lblod-plugins/components/variable-plugin/date/time-picker';
45
+
46
+ import VariablePluginDateHelpModal from '@lblod/ember-rdfa-editor-lblod-plugins/components/variable-plugin/date/help-modal';
47
+ import { hash } from '@ember/helper';
48
+
49
+ import t from 'ember-intl/helpers/t';
50
+ import { on } from '@ember/modifier';
51
+ import { eq, not } from 'ember-truth-helpers';
52
+ import DatePicker from '@lblod/ember-rdfa-editor-lblod-plugins/components/variable-plugin/date/date-picker';
53
+ import { TOC } from '@ember/component/template-only';
54
+
55
+ type Sig = {
56
+ Args: {
57
+ controller: SayController;
58
+ options: DateOptions;
59
+ };
60
+ Element: HTMLDivElement;
39
61
  };
40
- const SECONDS_REGEX = new RegExp('[sStT]|p{2,}');
41
- export default class DateEditComponent extends Component<Args> {
42
- CrossIcon = CrossIcon;
43
- InfoCircleIcon = InfoCircleIcon;
44
- Velcro = Velcro;
45
- AuCard = AuCard;
46
62
 
63
+ const SECONDS_REGEX = new RegExp('[sStT]|p{2,}');
64
+ export class DateEditComponent extends Component<Sig> {
47
65
  @service
48
66
  declare intl: IntlService;
49
67
 
@@ -166,6 +184,10 @@ export default class DateEditComponent extends Component<Args> {
166
184
  }
167
185
  }
168
186
 
187
+ get hasCustomDateFormatError(): boolean {
188
+ return !!this.customDateFormatError;
189
+ }
190
+
169
191
  get humanError(): string | null {
170
192
  if (this.customDateFormatError) {
171
193
  const { error, payload } = this.customDateFormatError;
@@ -191,7 +213,19 @@ export default class DateEditComponent extends Component<Args> {
191
213
  }
192
214
 
193
215
  get pickerDate(): Option<Date> {
194
- return this.documentDate;
216
+ return this.documentDate ?? null;
217
+ }
218
+
219
+ get pickerHours() {
220
+ return this.pickerDate?.getHours();
221
+ }
222
+
223
+ get pickerMinutes() {
224
+ return this.pickerDate?.getMinutes();
225
+ }
226
+
227
+ get pickerSeconds() {
228
+ return this.pickerDate?.getSeconds();
195
229
  }
196
230
 
197
231
  @action
@@ -245,7 +279,8 @@ export default class DateEditComponent extends Component<Args> {
245
279
  }
246
280
 
247
281
  @action
248
- setDateFormatFromKey(formatKey: string) {
282
+ setDateFormatFromKey(formatKey?: string) {
283
+ if (!formatKey) return;
249
284
  const pos = this.documentDatePos;
250
285
  if (isNone(pos)) {
251
286
  return;
@@ -286,4 +321,134 @@ export default class DateEditComponent extends Component<Args> {
286
321
  toggleHelpModal() {
287
322
  this.helpModalOpen = !this.helpModalOpen;
288
323
  }
324
+
325
+ <template>
326
+ {{#if this.showCard}}
327
+ <div class='au-u-flex au-u-flex--column au-u-flex' ...attributes>
328
+ <AuFormRow
329
+ class='au-u-padding-top-small au-u-padding-left-small au-u-padding-right-small au-u-padding-bottom-tiny'
330
+ >
331
+ <DatePicker
332
+ @value={{this.pickerDate}}
333
+ @onChange={{this.changeDate}}
334
+ />
335
+ </AuFormRow>
336
+ <div
337
+ class='au-o-flow au-o-flow--small au-u-flex-shrink au-u-padding-top-tiny au-u-padding-left-small au-u-padding-right-small au-u-padding-bottom-small'
338
+ id='say-date-edit-scrollable-part'
339
+ >
340
+ <AuFormRow @alignment='inline'>
341
+ <AuCheckbox
342
+ @name='include-time'
343
+ @disabled={{eq this.dateFormatType 'custom'}}
344
+ @checked={{not this.onlyDate}}
345
+ @onChange={{this.changeIncludeTime}}
346
+ >
347
+ {{t 'date-plugin.card.include-time'}}
348
+ </AuCheckbox>
349
+ {{#if this.isCustom}}
350
+ <Velcro
351
+ @placement='top'
352
+ @strategy='absolute'
353
+ @offsetOptions={{hash mainAxis=10}}
354
+ as |velcro|
355
+ >
356
+ <AuBadge
357
+ @size='small'
358
+ @icon={{InfoCircleIcon}}
359
+ aria-describedby='date-plugin-time-info-tooltip'
360
+ {{velcro.hook}}
361
+ {{on 'mouseenter' this.showTooltip}}
362
+ {{on 'mouseleave' this.hideTooltip}}
363
+ {{on 'focus' this.showTooltip}}
364
+ {{on 'blur' this.hideTooltip}}
365
+ />
366
+ {{#if this.tooltipOpen}}
367
+ <AuPill
368
+ id='date-plugin-time-info-tooltip'
369
+ role='tooltip'
370
+ {{velcro.loop}}
371
+ >
372
+ {{t 'date-plugin.card.info-custom-time'}}
373
+ </AuPill>
374
+ {{/if}}
375
+ </Velcro>
376
+ {{/if}}
377
+ </AuFormRow>
378
+ {{#unless this.onlyDate}}
379
+ <AuFormRow>
380
+ <TimePicker
381
+ @value={{this.pickerDate}}
382
+ @onChange={{this.changeDate}}
383
+ @showSeconds={{this.showSeconds}}
384
+ />
385
+ </AuFormRow>
386
+ {{/unless}}
387
+ <AuRadioGroup
388
+ @name={{(uuidv4)}}
389
+ @selected={{this.dateFormatType}}
390
+ @onChange={{this.setDateFormatFromKey}}
391
+ as |Group|
392
+ >
393
+ {{#each this.formats as |format|}}
394
+ <Group.Radio @value={{format.key}}>
395
+ {{if
396
+ format.label
397
+ format.label
398
+ (if this.onlyDate format.dateFormat format.dateTimeFormat)
399
+ }}
400
+ </Group.Radio>
401
+ {{/each}}
402
+ {{#if this.isCustomAllowed}}
403
+ <Group.Radio @value='custom'>
404
+ {{t 'date-plugin.card.custom-date'}}
405
+ </Group.Radio>
406
+ {{/if}}
407
+ </AuRadioGroup>
408
+ {{#if (eq this.dateFormatType 'custom')}}
409
+ <AuFormRow @alignment='post'>
410
+ <AuButton
411
+ @skin='secondary'
412
+ @icon='info-circle'
413
+ @hideText={{true}}
414
+ {{on 'click' this.toggleHelpModal}}
415
+ id='say-date-edit-info-modal-button'
416
+ />
417
+ <AuNativeInput
418
+ @error={{this.hasCustomDateFormatError}}
419
+ value={{this.documentDateFormat}}
420
+ {{on 'input' this.setCustomDateFormat}}
421
+ />
422
+ </AuFormRow>
423
+ {{#if this.humanError}}
424
+ <AuPill
425
+ @skin='error'
426
+ @icon={{CrossIcon}}
427
+ >{{this.humanError}}</AuPill>
428
+ {{/if}}
429
+ {{/if}}
430
+ </div>
431
+ </div>
432
+ {{/if}}
433
+ <VariablePluginDateHelpModal
434
+ @modalOpen={{this.helpModalOpen}}
435
+ @closeModal={{this.toggleHelpModal}}
436
+ />
437
+ </template>
289
438
  }
439
+
440
+ const DateEditCardComponent: TOC<Sig> = <template>
441
+ <AuCard
442
+ @shadow={{true}}
443
+ @size='flush'
444
+ {{! @glint-ignore: backwards compat with AU v3, remove if not supported anymore}}
445
+ @disableAuContent={{true}}
446
+ as |c|
447
+ >
448
+ <c.content>
449
+ <DateEditComponent @controller={{@controller}} @options={{@options}} />
450
+ </c.content>
451
+ </AuCard>
452
+ </template>;
453
+
454
+ export default DateEditCardComponent;
@@ -0,0 +1,54 @@
1
+ import Component from '@glimmer/component';
2
+ import FloatingWindow from '@lblod/ember-rdfa-editor/components/popover';
3
+ import { NodeSelection, SayController } from '@lblod/ember-rdfa-editor';
4
+ import { DateEditComponent } from '@lblod/ember-rdfa-editor-lblod-plugins/components/variable-plugin/date/edit';
5
+ import { DateOptions } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/variables';
6
+
7
+ type Signature = {
8
+ Args: {
9
+ controller: SayController;
10
+ options: DateOptions;
11
+ };
12
+ Blocks: {
13
+ default: [];
14
+ };
15
+ };
16
+
17
+ export default class FloatingDateContainer extends Component<Signature> {
18
+ get editorState() {
19
+ return this.args.controller.mainEditorState;
20
+ }
21
+
22
+ get selectedDateNode() {
23
+ const { selection } = this.editorState;
24
+ if (
25
+ selection instanceof NodeSelection &&
26
+ selection.node.type === selection.node.type.schema.nodes['date']
27
+ ) {
28
+ return { value: selection.node, pos: selection.from };
29
+ } else {
30
+ return null;
31
+ }
32
+ }
33
+
34
+ get forSelection() {
35
+ if (!this.selectedDateNode) return null;
36
+
37
+ return NodeSelection.create(
38
+ this.editorState.doc,
39
+ this.selectedDateNode.pos,
40
+ );
41
+ }
42
+
43
+ <template>
44
+ {{#if this.forSelection}}
45
+ <FloatingWindow
46
+ @forSelection={{this.forSelection}}
47
+ @controller={{@controller}}
48
+ class='au-u-flex'
49
+ >
50
+ <DateEditComponent @controller={{@controller}} @options={{@options}} />
51
+ </FloatingWindow>
52
+ {{/if}}
53
+ </template>
54
+ }
@@ -0,0 +1,61 @@
1
+ import Component from '@glimmer/component';
2
+ import { action } from '@ember/object';
3
+ import { service } from '@ember/service';
4
+ import { localCopy } from 'tracked-toolbox';
5
+ import Intl from 'ember-intl/services/intl';
6
+
7
+ import AuTimePicker from '@appuniversum/ember-appuniversum/components/au-time-picker';
8
+ import t from 'ember-intl/helpers/t';
9
+
10
+ type Sig = {
11
+ Args: {
12
+ value?: Date | null;
13
+ showSeconds?: boolean;
14
+ onChange: (date: Date) => void;
15
+ };
16
+ };
17
+
18
+ export default class TimePickerComponent extends Component<Sig> {
19
+ @service declare intl: Intl;
20
+ @localCopy('args.value') declare date?: Date;
21
+
22
+ @action
23
+ onChangeTime(timeObject: {
24
+ hours: number;
25
+ minutes: number;
26
+ seconds: number;
27
+ }) {
28
+ if (!this.date) this.date = new Date();
29
+ this.date.setHours(timeObject.hours);
30
+ this.date.setMinutes(timeObject.minutes);
31
+ this.date.setSeconds(timeObject.seconds);
32
+ this.args.onChange(this.date);
33
+ }
34
+
35
+ get hours() {
36
+ return this.date?.getHours();
37
+ }
38
+
39
+ get minutes() {
40
+ return this.date?.getMinutes();
41
+ }
42
+
43
+ get seconds() {
44
+ return this.date?.getSeconds();
45
+ }
46
+
47
+ <template>
48
+ <AuTimePicker
49
+ @hoursLabel={{t 'date-plugin.card.hours'}}
50
+ @minutesLabel={{t 'date-plugin.card.minutes'}}
51
+ @secondsLabel={{t 'date-plugin.card.seconds'}}
52
+ @nowLabel={{t 'date-plugin.card.now'}}
53
+ @hours={{this.hours}}
54
+ @minutes={{this.minutes}}
55
+ @seconds={{this.seconds}}
56
+ @showSeconds={{@showSeconds}}
57
+ @showNow={{true}}
58
+ @onChange={{this.onChangeTime}}
59
+ />
60
+ </template>
61
+ }
@@ -1,29 +1,19 @@
1
1
  import Component from '@glimmer/component';
2
2
  import { action } from '@ember/object';
3
- import { SayController, PNode } from '@lblod/ember-rdfa-editor';
3
+ import { SayController } from '@lblod/ember-rdfa-editor';
4
4
  import { NodeSelection } from '@lblod/ember-rdfa-editor';
5
+ import { ResolvedPNode } from '@lblod/ember-rdfa-editor/utils/_private/types';
5
6
  import { tracked } from '@glimmer/tracking';
6
7
  import { LmbPluginConfig } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/lmb-plugin';
7
8
  import Electee from '@lblod/ember-rdfa-editor-lblod-plugins/models/electee';
8
9
  import { unwrap } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/option';
9
- import { transactionCombinator } from '@lblod/ember-rdfa-editor/utils/transaction-utils';
10
- import {
11
- addPropertyToNode,
12
- updateSubject,
13
- } from '@lblod/ember-rdfa-editor/plugins/rdfa-info/utils';
14
- import { FOAF } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
15
- import { sayDataFactory } from '@lblod/ember-rdfa-editor/core/say-data-factory';
10
+ import { getReplacePersonTransaction } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/variable-plugin/utils/replace-person';
16
11
 
17
12
  type Args = {
18
13
  controller: SayController;
19
14
  config: LmbPluginConfig;
20
15
  };
21
16
 
22
- type PersonNode = {
23
- node: PNode;
24
- pos: number;
25
- };
26
-
27
17
  export default class PersonEditComponent extends Component<Args> {
28
18
  @tracked showModal = false;
29
19
 
@@ -37,8 +27,8 @@ export default class PersonEditComponent extends Component<Args> {
37
27
  selection instanceof NodeSelection &&
38
28
  selection.node.type === this.controller.schema.nodes.person_variable
39
29
  ) {
40
- const personNode: PersonNode = {
41
- node: selection.node,
30
+ const personNode: ResolvedPNode = {
31
+ value: selection.node,
42
32
  pos: selection.from,
43
33
  };
44
34
  return personNode;
@@ -52,7 +42,7 @@ export default class PersonEditComponent extends Component<Args> {
52
42
 
53
43
  get isEditing() {
54
44
  const personNode = this.selectedPersonNode;
55
- return !!personNode?.node.attrs.value;
45
+ return !!personNode?.value.attrs.value;
56
46
  }
57
47
 
58
48
  @action
@@ -65,34 +55,18 @@ export default class PersonEditComponent extends Component<Args> {
65
55
  closeModal() {
66
56
  this.showModal = false;
67
57
  }
58
+
68
59
  @action
69
60
  onUpdate(electee: Electee) {
70
61
  const personNode = unwrap(this.selectedPersonNode);
71
- this.controller.withTransaction(() => {
72
- return transactionCombinator(this.controller.activeEditorState)([
73
- updateSubject({
74
- pos: personNode.pos,
75
- targetSubject: electee.uri,
76
- keepBacklinks: true,
77
- keepProperties: false,
78
- keepExternalTriples: true,
79
- }),
80
- addPropertyToNode({
81
- resource: electee.uri,
82
- property: {
83
- predicate: FOAF('givenName').full,
84
- object: sayDataFactory.literal(electee.firstName),
85
- },
86
- }),
87
- addPropertyToNode({
88
- resource: electee.uri,
89
- property: {
90
- predicate: FOAF('familyName').full,
91
- object: sayDataFactory.literal(electee.lastName),
92
- },
93
- }),
94
- ]).transaction;
95
- });
62
+ this.controller.withTransaction(
63
+ () =>
64
+ getReplacePersonTransaction(
65
+ this.controller.activeEditorState,
66
+ personNode,
67
+ electee,
68
+ ).transaction,
69
+ );
96
70
  this.closeModal();
97
71
  }
98
72
  }