@lblod/ember-rdfa-editor-lblod-plugins 37.2.0 → 37.2.1-dev.60bf09ed2e67f94ff54f71ac46e0e29d5d0b6404

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.
@@ -0,0 +1,5 @@
1
+ ---
2
+ '@lblod/ember-rdfa-editor-lblod-plugins': minor
3
+ ---
4
+
5
+ Adds caching, sticky groups, and offline search for the existing context actions
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @lblod/ember-rdfa-editor-lblod-plugins
2
2
 
3
+ ## 37.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#663](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/pull/663) [`4938095`](https://github.com/lblod/ember-rdfa-editor-lblod-plugins/commit/49380955ce5c33beac6013cea02a684558aa0701) Thanks [@lagartoverde](https://github.com/lagartoverde)! - Use parse slice to not include unneeded paragraphs on the inline locked placeholders parse
8
+
3
9
  ## 37.2.0
4
10
 
5
11
  ### Minor Changes
@@ -8,6 +8,7 @@ import { replaceLocationCommand } from '../utils/replace-location';
8
8
  import { Area, Place } from '../utils/geo-helpers';
9
9
  import { Address } from '../utils/address-helpers';
10
10
  import { getLocationUri } from '../_private/utils/location-helpers';
11
+ import { ContextualActionGroup } from '@lblod/ember-rdfa-editor/plugins/contextual-actions';
11
12
 
12
13
  const otherElementsGroupId =
13
14
  'other-elements-e01f46a0-b323-4add-8035-d81dc2e8578d';
@@ -16,78 +17,85 @@ const recentLocationsGroupId =
16
17
 
17
18
  const SUGGESTION_AMOUNT = 15;
18
19
 
19
- export function getContextualActions() {
20
- return function (state: EditorState, searchQuery?: string) {
21
- const t = getTranslationFunction(state);
22
- const { selection } = state;
23
- if (!(selection instanceof NodeSelection)) return [];
24
- const selectedNode = selection.node;
25
- if (selectedNode.type.name !== 'oslo_location') return [];
20
+ function getLocationSuggestionOptions(state: EditorState) {
21
+ const { selection } = state;
22
+ if (!(selection instanceof NodeSelection)) return [];
23
+ const selectedNode = selection.node;
24
+ if (selectedNode.type.name !== 'oslo_location') return [];
26
25
 
27
- const selectedLocation = selectedNode.attrs.value as
28
- | Address
29
- | Place
30
- | Area
31
- | undefined;
26
+ const selectedLocation = selectedNode.attrs.value as
27
+ | Address
28
+ | Place
29
+ | Area
30
+ | undefined;
32
31
 
33
- const locationSuggestionOptions = getDocumentLocations(state)
34
- .filter(
35
- (location) =>
36
- !selectedLocation ||
37
- getLocationUri(selectedLocation) !== getLocationUri(location),
38
- )
39
- .slice(0, SUGGESTION_AMOUNT)
40
- .map((location) => ({
41
- label: location.formatted,
42
- id: uuidv4(),
43
- group: recentLocationsGroupId,
44
- command: replaceLocationCommand(
45
- { value: selection.node, pos: selection.from },
46
- location,
47
- ),
48
- }));
32
+ return getDocumentLocations(state)
33
+ .filter(
34
+ (location) =>
35
+ !selectedLocation ||
36
+ getLocationUri(selectedLocation) !== getLocationUri(location),
37
+ )
38
+ .slice(0, SUGGESTION_AMOUNT)
39
+ .map((location) => ({
40
+ label: location.formatted,
41
+ id: uuidv4(),
42
+ group: recentLocationsGroupId,
43
+ command: replaceLocationCommand(
44
+ { value: selection.node, pos: selection.from },
45
+ location,
46
+ ),
47
+ }));
48
+ }
49
49
 
50
- const otherElementsOptions = [
51
- {
52
- label: t(
53
- 'location-plugin.context-actions.insert-address',
54
- 'Adres invoegen',
55
- ),
56
- locationType: 'address' as LocationType,
57
- icon: 'location',
58
- },
59
- {
60
- label: t(
61
- 'location-plugin.context-actions.insert-point-on-map',
62
- 'Punt op de kaart invoegen',
63
- ),
64
- locationType: 'place' as LocationType,
65
- icon: 'location-gps',
66
- },
67
- {
68
- label: t(
69
- 'location-plugin.context-actions.insert-area',
70
- 'Gebied invoegen',
71
- ),
72
- locationType: 'area' as LocationType,
73
- icon: 'area',
74
- },
75
- ].map((option) => {
76
- return {
77
- ...option,
78
- id: uuidv4(),
79
- group: otherElementsGroupId,
80
- command: openLocationModalCommand(option.locationType),
81
- };
82
- });
50
+ function getOtherElementsOptions(state: EditorState) {
51
+ const t = getTranslationFunction(state);
83
52
 
84
- return locationSuggestionOptions
85
- .concat(otherElementsOptions)
86
- .filter(
87
- (option) =>
88
- !searchQuery ||
89
- option.label.toLocaleLowerCase().includes(searchQuery.toLowerCase()),
90
- );
53
+ return [
54
+ {
55
+ label: t(
56
+ 'location-plugin.context-actions.insert-address',
57
+ 'Adres invoegen',
58
+ ),
59
+ locationType: 'address' as LocationType,
60
+ icon: 'location',
61
+ },
62
+ {
63
+ label: t(
64
+ 'location-plugin.context-actions.insert-point-on-map',
65
+ 'Punt op de kaart invoegen',
66
+ ),
67
+ locationType: 'place' as LocationType,
68
+ icon: 'location-gps',
69
+ },
70
+ {
71
+ label: t(
72
+ 'location-plugin.context-actions.insert-area',
73
+ 'Gebied invoegen',
74
+ ),
75
+ locationType: 'area' as LocationType,
76
+ icon: 'area',
77
+ },
78
+ ].map((option) => {
79
+ return {
80
+ ...option,
81
+ id: uuidv4(),
82
+ group: otherElementsGroupId,
83
+ command: openLocationModalCommand(option.locationType),
84
+ };
85
+ });
86
+ }
87
+
88
+ export function getContextualActions(type: 'suggestions' | 'other_elements') {
89
+ return function (state: EditorState, searchQuery?: string) {
90
+ const options =
91
+ type === 'suggestions'
92
+ ? getLocationSuggestionOptions(state)
93
+ : getOtherElementsOptions(state);
94
+ return options.filter(
95
+ (option) =>
96
+ !searchQuery ||
97
+ option.label.toLocaleLowerCase().includes(searchQuery.toLowerCase()),
98
+ );
91
99
  };
92
100
  }
93
101
 
@@ -100,7 +108,7 @@ function contextualGroupIsVisible(state: EditorState) {
100
108
  }
101
109
 
102
110
  export function getContextualActionGroups() {
103
- return function (state: EditorState) {
111
+ return function (state: EditorState): ContextualActionGroup[] {
104
112
  if (!contextualGroupIsVisible(state)) return [];
105
113
  return [
106
114
  {
@@ -109,14 +117,12 @@ export function getContextualActionGroups() {
109
117
  'location-plugin.context-actions.location-suggestions',
110
118
  'Locatiesuggesties',
111
119
  ),
120
+ getActions: getContextualActions('suggestions'),
112
121
  },
113
122
  {
114
123
  id: otherElementsGroupId,
115
- label: getTranslationFunction(state)(
116
- 'location-plugin.context-actions.other-elements',
117
- 'Andere elementen',
118
- ),
119
124
  sticky: 'bottom',
125
+ getActions: getContextualActions('other_elements'),
120
126
  },
121
127
  ];
122
128
  };
@@ -8,6 +8,7 @@ import {
8
8
  TextSelection,
9
9
  PNode,
10
10
  Selection,
11
+ Command,
11
12
  } from '@lblod/ember-rdfa-editor';
12
13
  import type { FullTriple } from '@lblod/ember-rdfa-editor/core/rdfa-processor';
13
14
  import { PROV } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/constants';
@@ -39,8 +40,10 @@ function moveNodeSelectionForward(selection: Selection, doc: PNode) {
39
40
  export function replaceLocationCommand(
40
41
  node: ResolvedPNode,
41
42
  location: Address | Place | Area,
42
- ) {
43
- return function (state: EditorState, dispatch: (tr: Transaction) => void) {
43
+ ): Command {
44
+ return function (state: EditorState, dispatch?: (tr: Transaction) => void) {
45
+ if (!dispatch) return false;
46
+
44
47
  const df = new SayDataFactory();
45
48
  const { pos, value: locNode } = node;
46
49
  // The location's subject has likely changed, so we should update the external links too
@@ -79,5 +82,6 @@ export function replaceLocationCommand(
79
82
  );
80
83
  setLocationTr.setSelection(newSelection);
81
84
  dispatch(setLocationTr);
85
+ return true;
82
86
  };
83
87
  }
@@ -67,7 +67,7 @@ function replacePlaceholderWithHtml(
67
67
  ) {
68
68
  return (state: EditorState) => {
69
69
  const domParser = new DOMParser();
70
- const contentFragment = ProseParser.fromSchema(state.schema).parse(
70
+ const contentFragment = ProseParser.fromSchema(state.schema).parseSlice(
71
71
  domParser.parseFromString(value, 'text/html'),
72
72
  ).content;
73
73
  const tr = state.tr;
@@ -24,10 +24,18 @@ import { getActiveEditableNode } from '@lblod/ember-rdfa-editor/plugins/editable
24
24
  import { isRdfaAttrs } from '@lblod/ember-rdfa-editor/core/rdfa-types';
25
25
  import { v4 as uuidv4 } from 'uuid';
26
26
  import { getTranslationFunction } from '@lblod/ember-rdfa-editor-lblod-plugins/utils/translation';
27
+ import { type CodeListOptions } from '../utils/fetch-data';
28
+ import { ContextualActionGroup } from '@lblod/ember-rdfa-editor/plugins/contextual-actions';
27
29
 
28
30
  const plaatsbepalingGroupId =
29
31
  'plaatsbepaling-1d8563d6-bfd8-487f-a2a0-6d7a6ab01cb5';
30
32
 
33
+ const placeDescriptionCodelistCache: {
34
+ placeDescriptions: CodeListOptions | null;
35
+ } = {
36
+ placeDescriptions: null,
37
+ };
38
+
31
39
  function getSelectedLocation(state: EditorState) {
32
40
  const { selection } = state;
33
41
  if (
@@ -131,27 +139,47 @@ function createInsertPlaceDescriptionCommand(label: string) {
131
139
  };
132
140
  }
133
141
 
134
- export function getContextualActions({
135
- zonalLocationCodelistUri,
136
- nonZonalLocationCodelistUri,
137
- endpoint,
138
- }: GetContextualActionsAttrs) {
139
- return async function (state: EditorState) {
140
- const source = getSource(state, endpoint);
141
- const isZonal = getIsZonal(state);
142
- const result = await fetchCodeListOptions(
142
+ async function getPlaceDescriptionsCached(
143
+ state: EditorState,
144
+ {
145
+ zonalLocationCodelistUri,
146
+ nonZonalLocationCodelistUri,
147
+ endpoint,
148
+ }: GetContextualActionsAttrs,
149
+ ) {
150
+ const source = getSource(state, endpoint);
151
+ const isZonal = getIsZonal(state);
152
+ let options;
153
+ if (!placeDescriptionCodelistCache.placeDescriptions) {
154
+ options = await fetchCodeListOptions(
143
155
  source,
144
156
  isZonal ? zonalLocationCodelistUri : nonZonalLocationCodelistUri,
145
157
  );
158
+ placeDescriptionCodelistCache.placeDescriptions = options;
159
+ } else {
160
+ options = placeDescriptionCodelistCache.placeDescriptions;
161
+ }
146
162
 
147
- return result.options.map((option) => {
148
- return {
149
- id: uuidv4(),
150
- label: humanReadableLabel(option.label),
151
- group: plaatsbepalingGroupId,
152
- command: createInsertPlaceDescriptionCommand(option.label),
153
- };
154
- });
163
+ return options;
164
+ }
165
+
166
+ export function getContextualActions(attrs: GetContextualActionsAttrs) {
167
+ return async function (state: EditorState, searchQuery?: string) {
168
+ const result = await getPlaceDescriptionsCached(state, attrs);
169
+ return result.options
170
+ .filter(
171
+ (option) =>
172
+ !searchQuery ||
173
+ option.label.toLowerCase().includes(searchQuery.toLowerCase()),
174
+ )
175
+ .map((option) => {
176
+ return {
177
+ id: uuidv4(),
178
+ label: humanReadableLabel(option.label),
179
+ group: plaatsbepalingGroupId,
180
+ command: createInsertPlaceDescriptionCommand(option.label),
181
+ };
182
+ });
155
183
  };
156
184
  }
157
185
 
@@ -171,8 +199,8 @@ function contextualGroupIsVisible(state: EditorState) {
171
199
  );
172
200
  }
173
201
 
174
- export function getContextualActionGroups() {
175
- return function (state: EditorState) {
202
+ export function getContextualActionGroups(attrs: GetContextualActionsAttrs) {
203
+ return function (state: EditorState): ContextualActionGroup[] {
176
204
  return contextualGroupIsVisible(state)
177
205
  ? [
178
206
  {
@@ -181,6 +209,7 @@ export function getContextualActionGroups() {
181
209
  'variable.location.label',
182
210
  'Plaatsbeschrijving',
183
211
  ),
212
+ getActions: getContextualActions(attrs),
184
213
  },
185
214
  ]
186
215
  : [];
@@ -1,16 +1,9 @@
1
1
  import { EditorState } from '@lblod/ember-rdfa-editor';
2
- export declare function getContextualActions(): (state: EditorState, searchQuery?: string) => {
2
+ import { ContextualActionGroup } from '@lblod/ember-rdfa-editor/plugins/contextual-actions';
3
+ export declare function getContextualActions(type: 'suggestions' | 'other_elements'): (state: EditorState, searchQuery?: string) => {
3
4
  label: string;
4
5
  id: string;
5
6
  group: string;
6
- command: (state: EditorState, dispatch: (tr: import("@lblod/ember-rdfa-editor").Transaction) => void) => void;
7
+ command: import("@lblod/ember-rdfa-editor").Command;
7
8
  }[];
8
- export declare function getContextualActionGroups(): (state: EditorState) => ({
9
- id: string;
10
- label: string;
11
- sticky?: undefined;
12
- } | {
13
- id: string;
14
- label: string;
15
- sticky: string;
16
- })[];
9
+ export declare function getContextualActionGroups(): (state: EditorState) => ContextualActionGroup[];
@@ -1,5 +1,5 @@
1
1
  import { ResolvedPNode } from '@lblod/ember-rdfa-editor/utils/_private/types';
2
2
  import { Address } from './address-helpers';
3
3
  import { Area, Place } from './geo-helpers';
4
- import { EditorState, Transaction } from '@lblod/ember-rdfa-editor';
5
- export declare function replaceLocationCommand(node: ResolvedPNode, location: Address | Place | Area): (state: EditorState, dispatch: (tr: Transaction) => void) => void;
4
+ import { Command } from '@lblod/ember-rdfa-editor';
5
+ export declare function replaceLocationCommand(node: ResolvedPNode, location: Address | Place | Area): Command;
@@ -1,17 +1,15 @@
1
1
  import { EditorState, Transaction } from '@lblod/ember-rdfa-editor';
2
+ import { ContextualActionGroup } from '@lblod/ember-rdfa-editor/plugins/contextual-actions';
2
3
  type GetContextualActionsAttrs = {
3
4
  zonalLocationCodelistUri: string;
4
5
  nonZonalLocationCodelistUri: string;
5
6
  endpoint?: string;
6
7
  };
7
- export declare function getContextualActions({ zonalLocationCodelistUri, nonZonalLocationCodelistUri, endpoint, }: GetContextualActionsAttrs): (state: EditorState) => Promise<{
8
+ export declare function getContextualActions(attrs: GetContextualActionsAttrs): (state: EditorState, searchQuery?: string) => Promise<{
8
9
  id: string;
9
10
  label: string;
10
11
  group: string;
11
12
  command: (state: EditorState, dispatch?: (tr: Transaction) => void) => boolean;
12
13
  }[]>;
13
- export declare function getContextualActionGroups(): (state: EditorState) => {
14
- id: string;
15
- label: string;
16
- }[];
14
+ export declare function getContextualActionGroups(attrs: GetContextualActionsAttrs): (state: EditorState) => ContextualActionGroup[];
17
15
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lblod/ember-rdfa-editor-lblod-plugins",
3
- "version": "37.2.0",
3
+ "version": "37.2.1-dev.60bf09ed2e67f94ff54f71ac46e0e29d5d0b6404",
4
4
  "description": "Ember addon providing lblod specific plugins for the ember-rdfa-editor",
5
5
  "keywords": [
6
6
  "ember-addon",
@@ -111,7 +111,7 @@
111
111
  "@glint/ember-tsc": "^1.5.0",
112
112
  "@glint/environment-ember-loose": "^1.5.0",
113
113
  "@glint/environment-ember-template-imports": "^1.5.0",
114
- "@lblod/ember-rdfa-editor": "13.10.0",
114
+ "@lblod/ember-rdfa-editor": "13.10.2-dev.e26309571bb5b422640bb0281f659239799f642c",
115
115
  "@glint/template": "^1.7.7",
116
116
  "@rdfjs/to-ntriples": "^3.0.1",
117
117
  "@rdfjs/types": "^1.1.0",
@@ -216,7 +216,7 @@
216
216
  "node": ">= 18"
217
217
  },
218
218
  "volta": {
219
- "node": "20.11.0"
219
+ "node": "22.22.0"
220
220
  },
221
221
  "ember": {
222
222
  "edition": "octane"