@gi-tcg/gts-runtime 0.7.4 → 0.7.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/dist/index.d.ts CHANGED
@@ -281,4 +281,19 @@ interface ISimpleViewModel<T, Options extends SimpleViewModelOptions = {}> exten
281
281
  }
282
282
  declare function defineSimpleViewModel<const T extends StandardJSONSchemaV1, const Options extends SimpleViewModelOptions = {}>(schema: T, options?: Options): ISimpleViewModel<StandardJSONSchemaV1.InferInput<T>, Options>;
283
283
  //#endregion
284
- export { type AttributeReturn as AR, type AttributeReturn, type AttributeBlockDefinition, type AttributeDefinition, type IExtendedViewModel, type INarrowedViewModel, type IReboundViewModel, type ISimpleViewModel, type IViewModel, type IViewModelInstance, type NamedAttributesNode, type SimpleAttributeOptions, type SimpleViewModelOptions, type SingleAttributeNode, type View, createBinding, createDefine, defineSimpleViewModel, defineViewModel, extendViewModel, getCurrentContext };
284
+ //#region src/action_view_model.d.ts
285
+ type AnyAction = (fnArg: any) => void;
286
+ declare class ActionModel<Fn extends AnyAction> {
287
+ action!: Fn;
288
+ }
289
+ /**
290
+ * Defines a ViewModel whose only attribute is a direct `~action` that assigned to `ActionModel`'s `action`.
291
+ */
292
+ declare function defineActionViewModel<Signature extends (this: any, actionArg: AnyAction) => AttributeReturn.Done, InitMeta = unknown, ModelActionSig extends AnyAction = OverloadedParameters<Signature>[0]>(): IViewModel<ActionModel<ModelActionSig>, {
293
+ "~action": Signature & {
294
+ required(): true;
295
+ };
296
+ "~meta": InitMeta;
297
+ }, []>;
298
+ //#endregion
299
+ export { type AttributeReturn as AR, type AttributeReturn, ActionModel, type AttributeBlockDefinition, type AttributeDefinition, type IExtendedViewModel, type INarrowedViewModel, type IReboundViewModel, type ISimpleViewModel, type IViewModel, type IViewModelInstance, type NamedAttributesNode, type SimpleAttributeOptions, type SimpleViewModelOptions, type SingleAttributeNode, type View, createBinding, createDefine, defineActionViewModel, defineSimpleViewModel, defineViewModel, extendViewModel, getCurrentContext };
package/dist/index.js CHANGED
@@ -236,4 +236,18 @@ function defineSimpleViewModel(schema, options) {
236
236
  return createSimpleViewModelFromJsonSchema(schema["~standard"].jsonSchema.input({ target: "draft-2020-12" }), resolvedOptions);
237
237
  }
238
238
  //#endregion
239
- export { createBinding, createDefine, defineSimpleViewModel, defineViewModel, extendViewModel, getCurrentContext };
239
+ //#region src/action_view_model.ts
240
+ var ActionModel = class {
241
+ action;
242
+ };
243
+ /**
244
+ * Defines a ViewModel whose only attribute is a direct `~action` that assigned to `ActionModel`'s `action`.
245
+ */
246
+ function defineActionViewModel() {
247
+ return defineViewModel(ActionModel, (helper) => ({ "~action": helper.attribute((model, [actionArg]) => {
248
+ model.action = actionArg;
249
+ }) }), null);
250
+ }
251
+ defineActionViewModel();
252
+ //#endregion
253
+ export { ActionModel, createBinding, createDefine, defineActionViewModel, defineSimpleViewModel, defineViewModel, extendViewModel, getCurrentContext };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gi-tcg/gts-runtime",
3
- "version": "0.7.4",
3
+ "version": "0.7.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/piovium/gts.git"
@@ -0,0 +1,51 @@
1
+ import {
2
+ type AttributeDefinition,
3
+ type AttributeDefHelper,
4
+ defineViewModel,
5
+ type IViewModel,
6
+ type OverloadedParameters,
7
+ } from "./view_model.ts";
8
+ import type { AR } from "./attribute_return.ts";
9
+
10
+ type AnyAction = (fnArg: any) => void;
11
+
12
+ export class ActionModel<Fn extends AnyAction> {
13
+ action!: Fn;
14
+ }
15
+
16
+ /**
17
+ * Defines a ViewModel whose only attribute is a direct `~action` that assigned to `ActionModel`'s `action`.
18
+ */
19
+ export function defineActionViewModel<
20
+ Signature extends (this: any, actionArg: AnyAction) => AR.Done,
21
+ InitMeta = unknown,
22
+ ModelActionSig extends AnyAction = OverloadedParameters<Signature>[0],
23
+ >(): IViewModel<
24
+ ActionModel<ModelActionSig>,
25
+ {
26
+ "~action": Signature & {
27
+ required(): true;
28
+ };
29
+ "~meta": InitMeta;
30
+ },
31
+ []
32
+ > {
33
+ return defineViewModel(
34
+ ActionModel<ModelActionSig>,
35
+ (helper) => ({
36
+ "~action": helper.attribute<Signature & { required(): true }>(
37
+ (model, [actionArg]) => {
38
+ model.action = actionArg as ModelActionSig;
39
+ },
40
+ ),
41
+ }),
42
+ null as InitMeta,
43
+ );
44
+ }
45
+
46
+ type Operation<Meta> = (arg: { meta: Meta }) => void;
47
+
48
+ const VM =
49
+ defineActionViewModel<
50
+ <Meta>(this: AR.This<Meta>, op: Operation<Meta>) => AR.Done
51
+ >();
package/src/index.ts CHANGED
@@ -16,6 +16,7 @@ export {
16
16
  type ISimpleViewModel,
17
17
  type SimpleViewModelOptions,
18
18
  } from "./simple_view_model.ts";
19
+ export { defineActionViewModel, ActionModel } from "./action_view_model.ts";
19
20
  export type { AttributeReturn, AR } from "./attribute_return.ts";
20
21
 
21
22
  export {
package/src/view_model.ts CHANGED
@@ -426,7 +426,7 @@ export interface AttributeDefinition {
426
426
  mergeMeta?(meta: any, subMeta: any): any;
427
427
  }
428
428
 
429
- type OverloadedParameters<T extends (...args: any[]) => any> = T extends {
429
+ export type OverloadedParameters<T extends (...args: any[]) => any> = T extends {
430
430
  (...args: infer A1): any;
431
431
  (...args: infer A2): any;
432
432
  (...args: infer A3): any;