@navette-js/actions 1.0.0-beta.4 → 1.0.0-beta.5

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/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type ColorManager, type Lazy } from '@navette-js/support';
1
+ import { type HtmlString, type ColorManager, type Lazy } from '@navette-js/support';
2
2
  import type { ComponentContext, Renderable } from '@navette-js/schemas';
3
3
  /** Render hook slots of an action modal. Hooks receive the action as `data.action`. */
4
4
  export declare const ActionsRenderHook: {
@@ -51,6 +51,7 @@ export declare class Action implements Renderable {
51
51
  private _modalHeading;
52
52
  private _modalDescription;
53
53
  private _modalSubmitActionLabel;
54
+ private _lazySubmitLabel;
54
55
  private _modalIcon;
55
56
  private _icon;
56
57
  private _alpineClick;
@@ -77,6 +78,8 @@ export declare class Action implements Renderable {
77
78
  /** Navigation action, rendered as `<a href wire:navigate>`. */
78
79
  url(url: string | null | ((ctx: ComponentContext) => string | null)): this;
79
80
  /** A string: host component method called on click (`wire:click`). A function: the action handler, mounted through `mountAction()` (with its modal, if any). */
81
+ /** On click, dispatches a Livewire event (to a listener of the page or of another component), with parameters. */
82
+ dispatch(event: string, params?: unknown[] | Record<string, unknown>): this;
80
83
  action(action: string | ((ctx: ActionCallContext) => unknown | Promise<unknown>) | null): this;
81
84
  icon(name: string | null | ((ctx: ComponentContext) => string | null | Promise<string | null>)): this;
82
85
  /** Icon used when the action is a table row link. */
@@ -86,8 +89,10 @@ export declare class Action implements Renderable {
86
89
  groupedIcon(name: string | null): this;
87
90
  requiresConfirmation(condition?: boolean): this;
88
91
  modalHeading(heading: Lazy<string | null, ActionCallContext>): this;
89
- modalDescription(description: Lazy<string | null, ActionCallContext>): this;
90
- modalSubmitActionLabel(label: string | null): this;
92
+ /** Text under the heading; an `HtmlString` is inserted as is (build it from escaped values). */
93
+ modalDescription(description: Lazy<string | HtmlString | null, ActionCallContext>): this;
94
+ /** Label of the submit button; a function receives the action context (its arguments…). */
95
+ modalSubmitActionLabel(label: string | null | ((ctx: ActionCallContext) => string | null)): this;
91
96
  modalIcon(name: string | null): this;
92
97
  private _badge;
93
98
  private _badgeColor;
@@ -170,6 +175,9 @@ export declare class Action implements Renderable {
170
175
  * `steps` are `Step` components of `@navette-js/forms`.
171
176
  */
172
177
  steps(steps: any[] | null): this;
178
+ private _modifyWizard;
179
+ /** Changes the wizard built by `steps()` (`(wizard) => wizard.hiddenHeader()`). */
180
+ modifyWizardUsing(callback: ((wizard: any) => any) | null): this;
173
181
  isWizard(): boolean;
174
182
  /** Runs the action without its modal (e.g. no confirmation for some records). */
175
183
  modalHidden(condition?: Lazy<boolean, ActionCallContext>): this;
package/lib/index.js CHANGED
@@ -40,6 +40,7 @@ export class Action {
40
40
  _modalHeading = null;
41
41
  _modalDescription = null;
42
42
  _modalSubmitActionLabel = null;
43
+ _lazySubmitLabel = null;
43
44
  _modalIcon = null;
44
45
  _icon = null;
45
46
  _alpineClick = null;
@@ -76,6 +77,8 @@ export class Action {
76
77
  this._lazyUrl = null;
77
78
  } return this; }
78
79
  /** A string: host component method called on click (`wire:click`). A function: the action handler, mounted through `mountAction()` (with its modal, if any). */
80
+ /** On click, dispatches a Livewire event (to a listener of the page or of another component), with parameters. */
81
+ dispatch(event, params = []) { return this.action(`$dispatch(${js(event)}${Array.isArray(params) ? params.map((param) => `, ${js(param)}`).join('') : `, ${js(params)}`})`); }
79
82
  action(action) {
80
83
  if (typeof action === 'function') {
81
84
  this._handler = action;
@@ -100,8 +103,17 @@ export class Action {
100
103
  groupedIcon(name) { this._groupedIcon = name; return this; }
101
104
  requiresConfirmation(condition = true) { this._requiresConfirmation = condition; return this; }
102
105
  modalHeading(heading) { this._modalHeading = heading; return this; }
106
+ /** Text under the heading; an `HtmlString` is inserted as is (build it from escaped values). */
103
107
  modalDescription(description) { this._modalDescription = description; return this; }
104
- modalSubmitActionLabel(label) { this._modalSubmitActionLabel = label; return this; }
108
+ /** Label of the submit button; a function receives the action context (its arguments…). */
109
+ modalSubmitActionLabel(label) { if (typeof label === 'function') {
110
+ this._lazySubmitLabel = label;
111
+ this._modalSubmitActionLabel = null;
112
+ }
113
+ else {
114
+ this._modalSubmitActionLabel = label;
115
+ this._lazySubmitLabel = null;
116
+ } return this; }
105
117
  modalIcon(name) { this._modalIcon = name; return this; }
106
118
  _badge = null;
107
119
  _badgeColor = 'primary';
@@ -212,10 +224,14 @@ export class Action {
212
224
  const submitLabel = this._modalSubmitActionLabel ?? t('filament-actions::modal.actions.submit.label');
213
225
  const submit = Action.make('submit').label(submitLabel).color(this._color === 'gray' ? 'primary' : this._color).submit('callMountedAction');
214
226
  const cancel = Action.make('cancel').label(this._cancelLabel ?? t('filament-actions::modal.actions.cancel.label')).color('gray').alpineClickHandler('close()');
215
- return schema.components([Action.stepsRenderer(steps, submit, cancel)]);
227
+ const wizard = Action.stepsRenderer(steps, submit, cancel);
228
+ return schema.components([this._modifyWizard?.(wizard) ?? wizard]);
216
229
  };
217
230
  return this;
218
231
  }
232
+ _modifyWizard = null;
233
+ /** Changes the wizard built by `steps()` (`(wizard) => wizard.hiddenHeader()`). */
234
+ modifyWizardUsing(callback) { this._modifyWizard = callback; return this; }
219
235
  isWizard() { return this._steps !== null; }
220
236
  /** Runs the action without its modal (e.g. no confirmation for some records). */
221
237
  modalHidden(condition = true) { this._modalHidden = condition; return this; }
@@ -390,7 +406,7 @@ export class Action {
390
406
  const confirmation = this._requiresConfirmation;
391
407
  // A confirmation is centered (md); a form is start-aligned (4xl), except at small widths.
392
408
  const width = this._modalWidth ?? (confirmation ? 'md' : '4xl');
393
- const submitLabel = this._modalSubmitActionLabel ?? t(confirmation ? 'filament-actions::modal.actions.confirm.label' : 'filament-actions::modal.actions.submit.label');
409
+ const submitLabel = this._lazySubmitLabel?.(ctx) ?? this._modalSubmitActionLabel ?? t(confirmation ? 'filament-actions::modal.actions.confirm.label' : 'filament-actions::modal.actions.submit.label');
394
410
  // Hook order: custom content, schema, content footer, each between its before/after slots.
395
411
  const scopes = ctx.livewire.getRenderHookScopes?.() ?? [];
396
412
  const hook = (name) => renderHook(name, scopes, { action: this });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navette-js/actions",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.0-beta.5",
4
4
  "description": "Actions and modals for Navette admin panels.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -38,8 +38,8 @@
38
38
  "node"
39
39
  ],
40
40
  "dependencies": {
41
- "@navette-js/support": "1.0.0-beta.4",
42
- "@navette-js/schemas": "1.0.0-beta.4"
41
+ "@navette-js/support": "1.0.0-beta.5",
42
+ "@navette-js/schemas": "1.0.0-beta.5"
43
43
  },
44
44
  "publishConfig": {
45
45
  "access": "public",
package/views/modal.ejs CHANGED
@@ -32,7 +32,7 @@
32
32
 
33
33
  <% if (description) { %>
34
34
  <p id="<%= id %>.description" class="fi-modal-description">
35
- <%= description %>
35
+ <% if (description && typeof description === 'object' && typeof description.html === 'string') { %><%- description.html %><% } else { %><%= description %><% } %>
36
36
  </p>
37
37
  <% } %>
38
38
  </div>