@lblod/ember-rdfa-editor-lblod-plugins 33.2.0 → 33.3.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @lblod/ember-rdfa-editor-lblod-plugins
2
2
 
3
+ ## 33.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#611](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/611) [`ad9364d`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/ad9364d3d274d241228887356c057f7e2af84918) Thanks [@lagartoverde](https://github.com/lagartoverde)! - Allow the use of draft besluit types
8
+
3
9
  ## 33.2.0
4
10
 
5
11
  ### Minor Changes
@@ -20,14 +20,17 @@ import { getCurrentBesluitRange } from '@lblod/ember-rdfa-editor-lblod-plugins/u
20
20
  import {
21
21
  BesluitTypeInstance,
22
22
  checkBesluitTypeInstance,
23
+ checkForDraftBesluitType,
23
24
  mostSpecificBesluitType,
24
25
  } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/besluit-type-plugin/utils/besluit-type-instances';
25
26
  import BesluitTypeForm from '@lblod/ember-rdfa-editor-lblod-plugins/components/besluit-type-plugin/besluit-type-form';
26
27
  import { setBesluitType } from '@lblod/ember-rdfa-editor-lblod-plugins/plugins/besluit-type-plugin/utils/set-besluit-type';
28
+ import AuButton from '@appuniversum/ember-appuniversum/components/au-button';
27
29
 
28
30
  type Args = {
29
31
  controller: SayController;
30
32
  options: BesluitTypePluginOptions;
33
+ allowForDraftTypes?: boolean;
31
34
  };
32
35
 
33
36
  export default class EditorPluginsToolbarDropdownComponent extends Component<Args> {
@@ -67,7 +70,9 @@ export default class EditorPluginsToolbarDropdownComponent extends Component<Arg
67
70
 
68
71
  setType = (type: BesluitTypeInstance) => {
69
72
  this.selectedTypeInstance = type;
70
- this.insertIfValid();
73
+ if (!this.args.allowForDraftTypes) {
74
+ this.insertIfValid();
75
+ }
71
76
  };
72
77
 
73
78
  updateBesluitTypes = () => {
@@ -84,13 +89,16 @@ export default class EditorPluginsToolbarDropdownComponent extends Component<Arg
84
89
  );
85
90
  if (typeInstance) {
86
91
  this.selectedTypeInstance = typeInstance;
87
- this.cardExpanded = false;
92
+ const isDraftType = checkForDraftBesluitType(
93
+ this.controller.mainEditorState,
94
+ );
95
+ this.cardExpanded = !this.args.allowForDraftTypes && isDraftType;
88
96
  } else {
89
97
  this.cardExpanded = true;
90
98
  }
91
99
  };
92
100
 
93
- insertIfValid() {
101
+ insertIfValid = () => {
94
102
  this.controller.doCommand((state, dispatch) => {
95
103
  if (!this.selectedTypeInstance || !dispatch) {
96
104
  return false;
@@ -98,6 +106,7 @@ export default class EditorPluginsToolbarDropdownComponent extends Component<Arg
98
106
  const { result, transaction } = setBesluitType(
99
107
  state,
100
108
  this.selectedTypeInstance,
109
+ this.args.allowForDraftTypes,
101
110
  );
102
111
  if (result.every((ok) => ok)) {
103
112
  dispatch(transaction);
@@ -105,7 +114,7 @@ export default class EditorPluginsToolbarDropdownComponent extends Component<Arg
105
114
  }
106
115
  return false;
107
116
  });
108
- }
117
+ };
109
118
 
110
119
  <template>
111
120
  <div
@@ -182,6 +191,11 @@ export default class EditorPluginsToolbarDropdownComponent extends Component<Arg
182
191
  @selectedType={{this.selectedTypeInstance}}
183
192
  @setType={{this.setType}}
184
193
  />
194
+ {{#if @allowForDraftTypes}}
195
+ <AuButton {{on 'click' this.insertIfValid}}>
196
+ {{t 'common.insert'}}
197
+ </AuButton>
198
+ {{/if}}
185
199
  {{/if}}
186
200
  </Modal.Body>
187
201
  </AuModal>
@@ -1,7 +1,10 @@
1
1
  import { type EditorState } from '@lblod/ember-rdfa-editor';
2
2
  import { getOutgoingTripleList } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/namespace';
3
3
  import { getCurrentBesluitRange } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/decision-utils';
4
- import { RDF } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
4
+ import {
5
+ EXT,
6
+ RDF,
7
+ } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
5
8
  import { type BesluitType } from './fetchBesluitTypes';
6
9
  import { type NamedNodeTriple } from '@lblod/ember-rdfa-editor/core/rdfa-processor';
7
10
 
@@ -27,6 +30,20 @@ export function extractBesluitTypeUris(editorState: EditorState): string[] {
27
30
  .map((type: NamedNodeTriple) => type?.object.value);
28
31
  }
29
32
 
33
+ export function checkForDraftBesluitType(editorState: EditorState): boolean {
34
+ const besluitRange = getCurrentBesluitRange(editorState);
35
+ if (!besluitRange) {
36
+ return false;
37
+ }
38
+ return getOutgoingTripleList(
39
+ besluitRange.node.attrs,
40
+ EXT('isDraftDecisionType'),
41
+ ).some(
42
+ (draftTypeTriple: NamedNodeTriple) =>
43
+ draftTypeTriple?.object.value === 'true',
44
+ );
45
+ }
46
+
30
47
  /**
31
48
  * Finds a decision type in the document and checks that it represents a valid decision type
32
49
  * according to the list of types passed in.
@@ -10,21 +10,26 @@ import {
10
10
  import { sayDataFactory } from '@lblod/ember-rdfa-editor/core/say-data-factory';
11
11
  import { getCurrentBesluitURI } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/decision-utils';
12
12
  import {
13
+ checkForDraftBesluitType,
13
14
  extractBesluitTypeUris,
14
15
  isValidTypeChoice,
15
16
  mostSpecificBesluitType,
16
17
  type BesluitTypeInstance,
17
18
  } from './besluit-type-instances';
18
- import { RDF } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
19
+ import {
20
+ EXT,
21
+ RDF,
22
+ } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
19
23
 
20
24
  export function setBesluitType(
21
25
  initialState: EditorState,
22
26
  typeInstance: BesluitTypeInstance,
27
+ isDraftDecisionType?: boolean,
23
28
  ): TransactionCombinatorResult<boolean> {
24
29
  const transaction = initialState.tr;
25
-
26
30
  const resource = getCurrentBesluitURI(initialState);
27
- if (!resource || !isValidTypeChoice(typeInstance)) {
31
+ const isValidType = isValidTypeChoice(typeInstance);
32
+ if (!resource || (!isValidType && !isDraftDecisionType)) {
28
33
  return {
29
34
  result: [false],
30
35
  initialState,
@@ -42,6 +47,17 @@ export function setBesluitType(
42
47
  },
43
48
  });
44
49
  });
50
+ if (checkForDraftBesluitType(initialState)) {
51
+ monads.push(
52
+ removePropertyFromNode({
53
+ resource,
54
+ property: {
55
+ predicate: EXT('isDraftDecisionType').full,
56
+ object: sayDataFactory.literal('true'),
57
+ },
58
+ }),
59
+ );
60
+ }
45
61
  monads.push(
46
62
  addPropertyToNode({
47
63
  resource,
@@ -53,5 +69,16 @@ export function setBesluitType(
53
69
  },
54
70
  }),
55
71
  );
72
+ if (!isValidType && isDraftDecisionType) {
73
+ monads.push(
74
+ addPropertyToNode({
75
+ resource,
76
+ property: {
77
+ predicate: EXT('isDraftDecisionType').full,
78
+ object: sayDataFactory.literal('true'),
79
+ },
80
+ }),
81
+ );
82
+ }
56
83
  return transactionCombinator<boolean>(initialState)(monads);
57
84
  }
@@ -5,6 +5,7 @@ import { BesluitTypeInstance } from '@lblod/ember-rdfa-editor-lblod-plugins/plug
5
5
  type Args = {
6
6
  controller: SayController;
7
7
  options: BesluitTypePluginOptions;
8
+ allowForDraftTypes?: boolean;
8
9
  };
9
10
  export default class EditorPluginsToolbarDropdownComponent extends Component<Args> {
10
11
  selectedTypeInstance?: BesluitTypeInstance;
@@ -17,6 +18,6 @@ export default class EditorPluginsToolbarDropdownComponent extends Component<Arg
17
18
  toggleCard: () => void;
18
19
  setType: (type: BesluitTypeInstance) => void;
19
20
  updateBesluitTypes: () => void;
20
- insertIfValid(): void;
21
+ insertIfValid: () => void;
21
22
  }
22
23
  export {};
@@ -6,6 +6,7 @@ export interface BesluitTypeInstance {
6
6
  subSubType?: BesluitType;
7
7
  }
8
8
  export declare function extractBesluitTypeUris(editorState: EditorState): string[];
9
+ export declare function checkForDraftBesluitType(editorState: EditorState): boolean;
9
10
  /**
10
11
  * Finds a decision type in the document and checks that it represents a valid decision type
11
12
  * according to the list of types passed in.
@@ -1,4 +1,4 @@
1
1
  import { type EditorState } from '@lblod/ember-rdfa-editor';
2
2
  import { type TransactionCombinatorResult } from '@lblod/ember-rdfa-editor/utils/transaction-utils';
3
3
  import { type BesluitTypeInstance } from './besluit-type-instances';
4
- export declare function setBesluitType(initialState: EditorState, typeInstance: BesluitTypeInstance): TransactionCombinatorResult<boolean>;
4
+ export declare function setBesluitType(initialState: EditorState, typeInstance: BesluitTypeInstance, isDraftDecisionType?: boolean): TransactionCombinatorResult<boolean>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lblod/ember-rdfa-editor-lblod-plugins",
3
- "version": "33.2.0",
3
+ "version": "33.3.0",
4
4
  "description": "Ember addon providing lblod specific plugins for the ember-rdfa-editor",
5
5
  "keywords": [
6
6
  "ember-addon",