@vortexm/vjt 0.1.10 → 0.1.11

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.js CHANGED
@@ -4939,6 +4939,12 @@ var ActionRuntime = class {
4939
4939
  }
4940
4940
  return this.resolveReference(reference, context.currentValue, context.responseValue);
4941
4941
  }
4942
+ if (name.startsWith("getFirst ")) {
4943
+ return this.getCollectionBoundary(name.slice(9), "first");
4944
+ }
4945
+ if (name.startsWith("getLast ")) {
4946
+ return this.getCollectionBoundary(name.slice(8), "last");
4947
+ }
4942
4948
  if (name.startsWith("count ")) {
4943
4949
  return this.countValue(this.resolveReference(name.slice(6), context.currentValue, context.responseValue));
4944
4950
  }
@@ -4972,6 +4978,12 @@ var ActionRuntime = class {
4972
4978
  if (name === "dec") {
4973
4979
  return this.toNumber(inputValue) - 1;
4974
4980
  }
4981
+ if (name === "trim") {
4982
+ return this.stringifyValue(inputValue).trim();
4983
+ }
4984
+ if (name === "dedupLineBreaks") {
4985
+ return this.stringifyValue(inputValue).replaceAll(/\r\n/g, "\n").replaceAll(/\n{3,}/g, "\n\n");
4986
+ }
4975
4987
  if (name.startsWith("equals ")) {
4976
4988
  return this.resolveReference(name.slice(7), context.currentValue, context.responseValue) === action.args;
4977
4989
  }
@@ -4998,6 +5010,12 @@ var ActionRuntime = class {
4998
5010
  this.assignReference(name.slice(4), inputValue, context.currentValue, args);
4999
5011
  return inputValue;
5000
5012
  }
5013
+ if (name.startsWith("setFirst ")) {
5014
+ return this.setCollectionBoundary(name.slice(9), inputValue, "first");
5015
+ }
5016
+ if (name.startsWith("setLast ")) {
5017
+ return this.setCollectionBoundary(name.slice(8), inputValue, "last");
5018
+ }
5001
5019
  if (name.startsWith("append ")) {
5002
5020
  const reference = name.slice(7);
5003
5021
  const currentText = this.resolveReference(reference, context.currentValue, context.responseValue);
@@ -5128,6 +5146,47 @@ var ActionRuntime = class {
5128
5146
  }
5129
5147
  return JSON.stringify(value);
5130
5148
  }
5149
+ getCollectionBoundary(widgetId, boundary) {
5150
+ const state = this.stateById.get(widgetId) ?? this.stateByKey.get(widgetId);
5151
+ const collection = this.getWidgetCollection(state);
5152
+ if (!collection || collection.length === 0) {
5153
+ return null;
5154
+ }
5155
+ const index = boundary === "first" ? 0 : collection.length - 1;
5156
+ const value = collection[index];
5157
+ return isListElementLike(value) ? this.unwrapListValue(value) : value;
5158
+ }
5159
+ setCollectionBoundary(widgetId, inputValue, boundary) {
5160
+ const state = this.stateById.get(widgetId) ?? this.stateByKey.get(widgetId);
5161
+ if (!state) {
5162
+ return inputValue;
5163
+ }
5164
+ const collection = this.getWidgetCollection(state);
5165
+ if (!collection || collection.length === 0) {
5166
+ return inputValue;
5167
+ }
5168
+ const index = boundary === "first" ? 0 : collection.length - 1;
5169
+ collection[index] = this.cloneValue(this.unwrapListValue(inputValue));
5170
+ if (state.widget === "list" || state.widget === "grid-view") {
5171
+ this.clearListElementState(state.key);
5172
+ }
5173
+ return inputValue;
5174
+ }
5175
+ getWidgetCollection(state) {
5176
+ if (!state) {
5177
+ return null;
5178
+ }
5179
+ if (state.widget === "list" || state.widget === "grid-view") {
5180
+ return state.elements ?? null;
5181
+ }
5182
+ if (state.widget === "listbox") {
5183
+ return state.listboxElements ?? null;
5184
+ }
5185
+ if (state.widget === "combobox") {
5186
+ return state.comboboxElements ?? null;
5187
+ }
5188
+ return null;
5189
+ }
5131
5190
  isCurrentScopedReference(reference) {
5132
5191
  return reference === "current" || reference.startsWith("current.") || reference.startsWith("this.") || reference === "this";
5133
5192
  }
@@ -7479,7 +7538,11 @@ var RuntimeRenderer = class {
7479
7538
  const nextIsMobile = isMobileViewport();
7480
7539
  if (nextIsMobile !== previousIsMobile) {
7481
7540
  previousIsMobile = nextIsMobile;
7482
- renderSync();
7541
+ void this.handleLayoutSwitch(nextIsMobile).catch((error) => {
7542
+ logRuntimeError("handleLayoutSwitch", error, {
7543
+ nextIsMobile
7544
+ });
7545
+ });
7483
7546
  }
7484
7547
  };
7485
7548
  window.addEventListener("resize", handleResize);
@@ -7544,6 +7607,11 @@ var RuntimeRenderer = class {
7544
7607
  }
7545
7608
  return Promise.resolve();
7546
7609
  }
7610
+ async handleLayoutSwitch(nextIsMobile) {
7611
+ await this.rerenderRoot();
7612
+ await this.runSystemEvent(nextIsMobile ? "onLayoutSwitchToMobile" : "onLayoutSwitchToDesktop");
7613
+ await this.rerenderRoot();
7614
+ }
7547
7615
  async runSystemEvent(eventName) {
7548
7616
  const actions = this.systemEvents[eventName];
7549
7617
  if (!actions?.length) {
@@ -124,6 +124,9 @@ export declare class ActionRuntime {
124
124
  private getCurrentListState;
125
125
  private cloneValue;
126
126
  private stringifyValue;
127
+ private getCollectionBoundary;
128
+ private setCollectionBoundary;
129
+ private getWidgetCollection;
127
130
  private isCurrentScopedReference;
128
131
  private countValue;
129
132
  private toNumber;
@@ -4,7 +4,7 @@ export type TextAlign = 'left' | 'center' | 'right';
4
4
  export type VerticalAlign = 'top' | 'center' | 'bottom';
5
5
  export type HeadingTag = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
6
6
  export type WidgetEventName = 'onClick' | 'onUserValueChange' | 'onRefresh' | 'onEnter' | 'onShiftEnter' | 'onControlEnter' | 'onPaste';
7
- export type SystemEventName = 'onBeforeRender' | 'onAfterRender' | 'onBeforeNavigate' | 'onAfterNavigate' | 'onSpeechDetected' | 'onRecordingStarted' | 'onRecordingStopped' | 'onRecordingError' | 'onListeningError' | 'onListeringError' | 'onPlayFinished' | 'onPlayingStopped';
7
+ export type SystemEventName = 'onBeforeRender' | 'onAfterRender' | 'onBeforeNavigate' | 'onAfterNavigate' | 'onLayoutSwitchToMobile' | 'onLayoutSwitchToDesktop' | 'onSpeechDetected' | 'onRecordingStarted' | 'onRecordingStopped' | 'onRecordingError' | 'onListeningError' | 'onListeringError' | 'onPlayFinished' | 'onPlayingStopped';
8
8
  export type PrimitiveRequestType = 'int' | 'float' | 'boolean' | 'string';
9
9
  export type RouteDefinition = {
10
10
  path: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vortexm/vjt",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",