@istar-ts/actions 0.15.0-beta.1 → 0.15.0-beta.2

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/dist/index.cjs CHANGED
@@ -186,6 +186,36 @@ function contextActionsFor(palette, metamodel) {
186
186
  groups: palette.groups
187
187
  };
188
188
  }
189
+ /**
190
+ * A minimal palette for a metamodel with none of its own: one toolbar entry per visible kind
191
+ * (declaration order, actors first), labelled from the kind's own `label`. Kinds generated for
192
+ * an n-ary link (a hub, leg or end — `role` set) are hidden, as a hand-written palette would
193
+ * hide them (`KAOS_PALETTE`'s `RefinementLinkHub: false`, for instance). The fallback
194
+ * `createActionDispatcher` and `contributionFor` (`@istar-ts/glsp`) both use when no palette
195
+ * was given.
196
+ */
197
+ function paletteFromMetamodel(metamodel) {
198
+ const elements = {};
199
+ let order = 0;
200
+ for (const definition of metamodel.elements.values()) elements[definition.kind] = definition.role !== void 0 ? false : {
201
+ label: definition.label,
202
+ order: order++,
203
+ section: definition.category === "actor" ? "actors" : "elements",
204
+ ...definition.category === "actor" ? { group: "actors" } : {}
205
+ };
206
+ const links = {};
207
+ order = 0;
208
+ for (const definition of metamodel.links.values()) links[definition.kind] = definition.role !== void 0 ? false : [{
209
+ label: definition.label,
210
+ order: order++,
211
+ section: "elements"
212
+ }];
213
+ return {
214
+ elements,
215
+ links,
216
+ groups: { actors: { label: "Actor" } }
217
+ };
218
+ }
189
219
  //#endregion
190
220
  //#region src/markers.ts
191
221
  /** A `GoalDiagnostic` as a GLSP marker: `kind` is its severity, `label` its message. */
@@ -277,7 +307,11 @@ function createActionDispatcher(store, options = {}) {
277
307
  const s = store;
278
308
  const guards = options.guards ?? [];
279
309
  const postGuards = options.postGuards ?? [];
280
- const palette = options.palette ?? _istar_ts_core.DEFAULT_PALETTE;
310
+ const resolvePalette = (meta) => {
311
+ const option = options.palette;
312
+ if (typeof option === "function") return option();
313
+ return option ?? paletteFromMetamodel(meta);
314
+ };
281
315
  const sourceModelName = options.sourceModelName ?? "";
282
316
  const listeners = /* @__PURE__ */ new Set();
283
317
  let saved = s.getModel();
@@ -699,11 +733,14 @@ function createActionDispatcher(store, options = {}) {
699
733
  ...typeHintsFor(metaOf(model))
700
734
  };
701
735
  case "requestCheckEdge": return checkEdge(action);
702
- case "requestContextActions": return {
703
- kind: "setContextActions",
704
- responseId: action.requestId,
705
- ...contextActionsFor(palette, metaOf(model))
706
- };
736
+ case "requestContextActions": {
737
+ const meta = metaOf(model);
738
+ return {
739
+ kind: "setContextActions",
740
+ responseId: action.requestId,
741
+ ...contextActionsFor(resolvePalette(meta), meta)
742
+ };
743
+ }
707
744
  case "requestMarkers": return markers(action);
708
745
  default: return;
709
746
  }
@@ -1164,6 +1201,7 @@ exports.hostToolContext = hostToolContext;
1164
1201
  exports.isOperation = isOperation;
1165
1202
  exports.isRequestAction = isRequestAction;
1166
1203
  exports.markerToDiagnostic = markerToDiagnostic;
1204
+ exports.paletteFromMetamodel = paletteFromMetamodel;
1167
1205
  exports.readOnlyDispatcher = readOnlyDispatcher;
1168
1206
  exports.typeHintsFor = typeHintsFor;
1169
1207