@razaman2/reactive-view 0.0.6 → 0.0.7

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.mts CHANGED
@@ -1,4 +1,3 @@
1
- import * as vue from 'vue';
2
1
  import { SetupContext, ComponentPublicInstance, UnwrapRef } from 'vue';
3
2
 
4
3
  type SubscriptionItem = {
@@ -29,7 +28,7 @@ declare const setup: {
29
28
  default: (param1?: {}, param2?: {}) => {};
30
29
  };
31
30
  };
32
- declare const _default$1: {
31
+ declare const _default: {
33
32
  props: {
34
33
  notifications: ObjectConstructor;
35
34
  subscriptions: ObjectConstructor;
@@ -41,7 +40,7 @@ declare const _default$1: {
41
40
  default: (data?: {}) => {};
42
41
  };
43
42
  logging: {
44
- validator: (logging: unknown) => boolean;
43
+ validator: (logging: any) => boolean;
45
44
  };
46
45
  modelName: {
47
46
  type: StringConstructor;
@@ -59,52 +58,51 @@ declare const _default$1: {
59
58
  setup(props: Record<string, any>, context: SetupContext): ($vue: ComponentPublicInstance & any) => any;
60
59
  };
61
60
 
62
- declare const _default: {
63
- props: {
64
- resolve: {
65
- required: boolean;
66
- };
67
- delay: {
68
- type: NumberConstructor;
69
- default: number;
70
- };
71
- timeout: {
72
- type: NumberConstructor;
73
- default: number;
74
- };
75
- loading: {
76
- default: vue.VNode<vue.RendererNode, vue.RendererElement, {
77
- [key: string]: any;
78
- }>;
79
- };
80
- options: {
81
- type: ObjectConstructor;
82
- };
83
- error: {
84
- required: boolean;
85
- };
86
- setup: {
87
- type: FunctionConstructor;
88
- default: (param1?: {}, param2?: {}) => {};
89
- };
90
- };
91
- setup(): ($vue: any) => vue.VNode<vue.RendererNode, vue.RendererElement, {
92
- [key: string]: any;
93
- }>;
94
- };
95
-
96
61
  /**
97
62
  * uppercase the first character of each word in the input string.
63
+ * @deprecated
98
64
  * @description
99
65
  * (test -> Test), (TEST -> Test), (test test -> Test Test)
100
66
  */
101
67
  declare function ucf(string: string): string;
102
68
  /**
103
69
  * uppercase the first character of each word that follows a specified token
70
+ * @deprecated
104
71
  * @description
105
72
  * (test-test -> test-Test), (TEST-TEST -> TEST-Test), (test/test -> test/Test)
106
73
  */
107
74
  declare function ucfat(string: string, tokens: Array<string>): string;
75
+ /**
76
+ * @deprecated
77
+ */
78
+ declare function getRoot(vue: ComponentPublicInstance): any;
79
+ /**
80
+ * @deprecated
81
+ */
82
+ declare function getRef(component: ComponentPublicInstance, ref: UnwrapRef<any>): ComponentPublicInstance;
83
+ /**
84
+ * @deprecated
85
+ */
86
+ declare function expose(vue: any, props: Record<string, any>): Record<string, any>;
87
+ type Accessible = {
88
+ parent: {
89
+ self: Record<string | symbol, any>;
90
+ };
91
+ self: Record<string | symbol, any>;
92
+ access?: Function;
93
+ value?: {
94
+ parent: {
95
+ self: Record<string | symbol, any>;
96
+ };
97
+ self: Record<string | symbol, any>;
98
+ access?: Function;
99
+ };
100
+ };
101
+ type PropOptions = {
102
+ exclude: string | Array<string>;
103
+ include: Record<string, any>;
104
+ };
105
+ type PropExclusions = Array<string> | string;
108
106
  declare function safeRequest(request: {
109
107
  try: () => Promise<any> | any;
110
108
  catch?: ((error: any) => Promise<any> | any) | false;
@@ -117,12 +115,6 @@ declare function safeRequest(request: {
117
115
  message?: string;
118
116
  alternative?: boolean;
119
117
  }): Promise<any>;
120
- declare function getRoot(vue: ComponentPublicInstance): any;
121
- type PropOptions = {
122
- exclude: string | Array<string>;
123
- include: Record<string, any>;
124
- };
125
- type PropExclusions = Array<string> | string;
126
118
  declare function getProps(props: Record<string, any>, exclude: PropExclusions): Record<string, any>;
127
119
  declare function getProps(props: Record<string, any>, options: PropOptions): Record<string, any>;
128
120
  declare function getDate(timestamp: {
@@ -134,8 +126,6 @@ declare function getDate(timestamp: {
134
126
  format?: string;
135
127
  timezone?: string;
136
128
  }): string;
137
- declare function getRef(component: ComponentPublicInstance, ref: UnwrapRef<any>): ComponentPublicInstance;
138
- declare function expose(vue: any, props: Record<string, any>): Record<string, any>;
139
129
  declare function getSubscription(): {
140
130
  addSubscription(name: string, handler?: () => boolean, data?: any): void;
141
131
  replaceSubscription(name: string, handler?: () => boolean, data?: any): void;
@@ -145,20 +135,6 @@ declare function getSubscription(): {
145
135
  subscriptions: any[];
146
136
  subscription: Subscription;
147
137
  };
148
- type Accessible = {
149
- parent: {
150
- self: Record<string | symbol, any>;
151
- };
152
- self: Record<string | symbol, any>;
153
- access?: Function;
154
- value?: {
155
- parent: {
156
- self: Record<string | symbol, any>;
157
- };
158
- self: Record<string | symbol, any>;
159
- access?: Function;
160
- };
161
- };
162
- declare function access<T extends ComponentPublicInstance & Accessible>($vue?: T): any;
138
+ declare function access<T extends ComponentPublicInstance & Accessible>($vue?: T | UnwrapRef<any>): any;
163
139
 
164
- export { _default as AsyncComponent, access, _default$1 as default, expose, getDate, getProps, getRef, getRoot, getSubscription, safeRequest, setup, ucf, ucfat };
140
+ export { access, _default as default, expose, getDate, getProps, getRef, getRoot, getSubscription, safeRequest, setup, ucf, ucfat };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import * as vue from 'vue';
2
1
  import { SetupContext, ComponentPublicInstance, UnwrapRef } from 'vue';
3
2
 
4
3
  type SubscriptionItem = {
@@ -29,7 +28,7 @@ declare const setup: {
29
28
  default: (param1?: {}, param2?: {}) => {};
30
29
  };
31
30
  };
32
- declare const _default$1: {
31
+ declare const _default: {
33
32
  props: {
34
33
  notifications: ObjectConstructor;
35
34
  subscriptions: ObjectConstructor;
@@ -41,7 +40,7 @@ declare const _default$1: {
41
40
  default: (data?: {}) => {};
42
41
  };
43
42
  logging: {
44
- validator: (logging: unknown) => boolean;
43
+ validator: (logging: any) => boolean;
45
44
  };
46
45
  modelName: {
47
46
  type: StringConstructor;
@@ -59,52 +58,51 @@ declare const _default$1: {
59
58
  setup(props: Record<string, any>, context: SetupContext): ($vue: ComponentPublicInstance & any) => any;
60
59
  };
61
60
 
62
- declare const _default: {
63
- props: {
64
- resolve: {
65
- required: boolean;
66
- };
67
- delay: {
68
- type: NumberConstructor;
69
- default: number;
70
- };
71
- timeout: {
72
- type: NumberConstructor;
73
- default: number;
74
- };
75
- loading: {
76
- default: vue.VNode<vue.RendererNode, vue.RendererElement, {
77
- [key: string]: any;
78
- }>;
79
- };
80
- options: {
81
- type: ObjectConstructor;
82
- };
83
- error: {
84
- required: boolean;
85
- };
86
- setup: {
87
- type: FunctionConstructor;
88
- default: (param1?: {}, param2?: {}) => {};
89
- };
90
- };
91
- setup(): ($vue: any) => vue.VNode<vue.RendererNode, vue.RendererElement, {
92
- [key: string]: any;
93
- }>;
94
- };
95
-
96
61
  /**
97
62
  * uppercase the first character of each word in the input string.
63
+ * @deprecated
98
64
  * @description
99
65
  * (test -> Test), (TEST -> Test), (test test -> Test Test)
100
66
  */
101
67
  declare function ucf(string: string): string;
102
68
  /**
103
69
  * uppercase the first character of each word that follows a specified token
70
+ * @deprecated
104
71
  * @description
105
72
  * (test-test -> test-Test), (TEST-TEST -> TEST-Test), (test/test -> test/Test)
106
73
  */
107
74
  declare function ucfat(string: string, tokens: Array<string>): string;
75
+ /**
76
+ * @deprecated
77
+ */
78
+ declare function getRoot(vue: ComponentPublicInstance): any;
79
+ /**
80
+ * @deprecated
81
+ */
82
+ declare function getRef(component: ComponentPublicInstance, ref: UnwrapRef<any>): ComponentPublicInstance;
83
+ /**
84
+ * @deprecated
85
+ */
86
+ declare function expose(vue: any, props: Record<string, any>): Record<string, any>;
87
+ type Accessible = {
88
+ parent: {
89
+ self: Record<string | symbol, any>;
90
+ };
91
+ self: Record<string | symbol, any>;
92
+ access?: Function;
93
+ value?: {
94
+ parent: {
95
+ self: Record<string | symbol, any>;
96
+ };
97
+ self: Record<string | symbol, any>;
98
+ access?: Function;
99
+ };
100
+ };
101
+ type PropOptions = {
102
+ exclude: string | Array<string>;
103
+ include: Record<string, any>;
104
+ };
105
+ type PropExclusions = Array<string> | string;
108
106
  declare function safeRequest(request: {
109
107
  try: () => Promise<any> | any;
110
108
  catch?: ((error: any) => Promise<any> | any) | false;
@@ -117,12 +115,6 @@ declare function safeRequest(request: {
117
115
  message?: string;
118
116
  alternative?: boolean;
119
117
  }): Promise<any>;
120
- declare function getRoot(vue: ComponentPublicInstance): any;
121
- type PropOptions = {
122
- exclude: string | Array<string>;
123
- include: Record<string, any>;
124
- };
125
- type PropExclusions = Array<string> | string;
126
118
  declare function getProps(props: Record<string, any>, exclude: PropExclusions): Record<string, any>;
127
119
  declare function getProps(props: Record<string, any>, options: PropOptions): Record<string, any>;
128
120
  declare function getDate(timestamp: {
@@ -134,8 +126,6 @@ declare function getDate(timestamp: {
134
126
  format?: string;
135
127
  timezone?: string;
136
128
  }): string;
137
- declare function getRef(component: ComponentPublicInstance, ref: UnwrapRef<any>): ComponentPublicInstance;
138
- declare function expose(vue: any, props: Record<string, any>): Record<string, any>;
139
129
  declare function getSubscription(): {
140
130
  addSubscription(name: string, handler?: () => boolean, data?: any): void;
141
131
  replaceSubscription(name: string, handler?: () => boolean, data?: any): void;
@@ -145,20 +135,6 @@ declare function getSubscription(): {
145
135
  subscriptions: any[];
146
136
  subscription: Subscription;
147
137
  };
148
- type Accessible = {
149
- parent: {
150
- self: Record<string | symbol, any>;
151
- };
152
- self: Record<string | symbol, any>;
153
- access?: Function;
154
- value?: {
155
- parent: {
156
- self: Record<string | symbol, any>;
157
- };
158
- self: Record<string | symbol, any>;
159
- access?: Function;
160
- };
161
- };
162
- declare function access<T extends ComponentPublicInstance & Accessible>($vue?: T): any;
138
+ declare function access<T extends ComponentPublicInstance & Accessible>($vue?: T | UnwrapRef<any>): any;
163
139
 
164
- export { _default as AsyncComponent, access, _default$1 as default, expose, getDate, getProps, getRef, getRoot, getSubscription, safeRequest, setup, ucf, ucfat };
140
+ export { access, _default as default, expose, getDate, getProps, getRef, getRoot, getSubscription, safeRequest, setup, ucf, ucfat };
package/dist/index.js CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
- var __defProps = Object.defineProperties;
5
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
8
6
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
7
  var __getProtoOf = Object.getPrototypeOf;
@@ -21,7 +19,6 @@ var __spreadValues = (a, b) => {
21
19
  }
22
20
  return a;
23
21
  };
24
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
22
  var __objRest = (source, exclude) => {
26
23
  var target = {};
27
24
  for (var prop in source)
@@ -55,31 +52,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
55
52
  mod
56
53
  ));
57
54
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
58
- var __async = (__this, __arguments, generator) => {
59
- return new Promise((resolve, reject) => {
60
- var fulfilled = (value) => {
61
- try {
62
- step(generator.next(value));
63
- } catch (e) {
64
- reject(e);
65
- }
66
- };
67
- var rejected = (value) => {
68
- try {
69
- step(generator.throw(value));
70
- } catch (e) {
71
- reject(e);
72
- }
73
- };
74
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
75
- step((generator = generator.apply(__this, __arguments)).next());
76
- });
77
- };
78
55
 
79
56
  // src/index.ts
80
57
  var src_exports = {};
81
58
  __export(src_exports, {
82
- AsyncComponent: () => AsyncComponent_default,
83
59
  access: () => access,
84
60
  default: () => src_default,
85
61
  expose: () => expose,
@@ -187,13 +163,13 @@ var Subscriptions = _Subscriptions;
187
163
  // src/ReactiveView.ts
188
164
  var import_object_manager = __toESM(require("@razaman2/object-manager"));
189
165
  var import_data_manager = __toESM(require("@razaman2/data-manager"));
190
- var import_vue = require("vue");
191
166
 
192
167
  // package.json
193
168
  var name = "@razaman2/reactive-view";
194
- var version = "0.0.6";
169
+ var version = "0.0.7";
195
170
 
196
171
  // src/ReactiveView.ts
172
+ var import_vue = require("vue");
197
173
  var props = {
198
174
  notifications: Object,
199
175
  subscriptions: Object,
@@ -206,7 +182,7 @@ var props = {
206
182
  },
207
183
  logging: {
208
184
  validator: (logging) => {
209
- return typeof logging === "boolean";
185
+ return logging.constructor.name === "Boolean";
210
186
  }
211
187
  },
212
188
  modelName: {
@@ -229,7 +205,7 @@ var setup = {
229
205
  var ReactiveView_default = {
230
206
  props: __spreadValues(__spreadValues({}, setup), props),
231
207
  setup(props2, context) {
232
- var _a, _b, _c, _d, _f;
208
+ var _a, _b, _c, _d, _e;
233
209
  const template = (vue, options2) => {
234
210
  var _a2, _b2, _c2;
235
211
  const vnode = context.slots.default ? (0, import_vue.h)(
@@ -249,27 +225,21 @@ var ReactiveView_default = {
249
225
  Array.isArray(props2.state) ? (_a = props2.defaultData) != null ? _a : [] : (_b = props2.defaultData) != null ? _b : {}
250
226
  );
251
227
  const defaultType = Array.isArray(defaultData) ? [] : {};
252
- const stateRef = (0, import_vue.ref)(import_data_manager.default.transform((_c = props2.state) != null ? _c : defaultType));
228
+ const state = (0, import_vue.reactive)(import_data_manager.default.transform((_c = props2.state) != null ? _c : defaultType));
253
229
  const config = {
254
230
  defaultData,
255
- data: stateRef.value,
231
+ data: state,
256
232
  name: props2.modelName,
257
233
  logging: props2.logging,
258
234
  notifications: props2.notifications
259
235
  };
260
236
  const getState = props2.model ? typeof props2.model === "function" ? props2.model(config) : props2.model : new import_data_manager.default(config);
261
- const options = {
262
- parent: { self: props2 },
263
- self: { template, isValid, getState, stateRef }
264
- };
265
- const setup2 = (_d = props2.setup(options)) != null ? _d : options;
266
- const _e = setup2, { parent = {}, self = {} } = _e, rest = __objRest(_e, ["parent", "self"]);
267
237
  const sync = (0, import_vue.ref)(false);
268
238
  if (context.attrs["onUpdate:modelState"]) {
269
239
  const config2 = typeof context.attrs["onUpdate:modelState"] === "function" ? { callback: context.attrs["onUpdate:modelState"] } : context.attrs["onUpdate:modelState"];
270
- const subscription = (0, import_vue.watch)(() => import_object_manager.default.on(stateRef.value).clone(), (after, before) => {
240
+ (0, import_vue.watch)(() => import_object_manager.default.on(state).clone(), (after, before) => {
271
241
  var _a2;
272
- const transform = (_a2 = config2.transform) != null ? _a2 : access(setup2).$transform;
242
+ const transform = (_a2 = config2.transform) != null ? _a2 : access(setup).$transform;
273
243
  const diff = {
274
244
  before: (before == null ? void 0 : before.hasOwnProperty("")) ? before[""] : before,
275
245
  after: (after == null ? void 0 : after.hasOwnProperty("")) ? after[""] : after
@@ -282,8 +252,8 @@ var ReactiveView_default = {
282
252
  }, config2.options);
283
253
  }
284
254
  if (context.attrs["onUpdate:propsState"] || props2.sync) {
285
- const config2 = (_f = typeof context.attrs["onUpdate:propsState"] === "function" ? { callback: context.attrs["onUpdate:propsState"] } : context.attrs["onUpdate:propsState"]) != null ? _f : {};
286
- const subscription = (0, import_vue.watch)(() => props2.state, (after, before) => {
255
+ const config2 = (_d = typeof context.attrs["onUpdate:propsState"] === "function" ? { callback: context.attrs["onUpdate:propsState"] } : context.attrs["onUpdate:propsState"]) != null ? _d : {};
256
+ (0, import_vue.watch)(() => props2.state, (after, before) => {
287
257
  if (props2.sync && typeof config2.callback !== "function") {
288
258
  getState.replaceData(after);
289
259
  } else if (typeof config2.callback === "function") {
@@ -292,91 +262,28 @@ var ReactiveView_default = {
292
262
  sync.value = true;
293
263
  }, config2.options);
294
264
  }
265
+ const options = {
266
+ parent: {},
267
+ self: { template, isValid, getState }
268
+ };
269
+ const _f = (_e = props2.setup(options)) != null ? _e : options, { parent = options.parent, self = options.self } = _f, rest = __objRest(_f, ["parent", "self"]);
295
270
  return ($vue) => {
296
- const setup3 = { $vue, options: parent };
297
- while (setup3.options) {
298
- Object.defineProperties(setup3.$vue, Object.assign({
271
+ const setup2 = { $vue, options: Object.assign(parent, { parent: { self: $vue } }) };
272
+ while (setup2.options) {
273
+ Object.defineProperties(setup2.$vue, Object.assign({
299
274
  access: {
300
275
  configurable: true,
301
- value: () => {
302
- return access({ parent, self });
303
- }
276
+ value: () => access({ parent, self })
304
277
  }
305
278
  }, rest));
306
- setup3.options = setup3.options.parent;
307
- setup3.$vue = setup3.$vue.$parent;
279
+ setup2.options = setup2.options.parent;
280
+ setup2.$vue = setup2.$vue.$parent;
308
281
  }
309
282
  return access($vue).template($vue, { parent, self });
310
283
  };
311
284
  }
312
285
  };
313
286
 
314
- // src/AsyncComponent.ts
315
- var import_vue2 = require("vue");
316
- var AsyncComponent_default = {
317
- props: __spreadProps(__spreadValues({}, setup), {
318
- resolve: {
319
- required: true
320
- },
321
- delay: {
322
- type: Number,
323
- default: 200
324
- },
325
- timeout: {
326
- type: Number,
327
- default: 2e3
328
- },
329
- loading: {
330
- default: (0, import_vue2.h)("div")
331
- },
332
- options: {
333
- type: Object
334
- },
335
- error: {
336
- required: false
337
- }
338
- }),
339
- setup() {
340
- return ($vue) => {
341
- return (0, import_vue2.h)(
342
- src_default,
343
- {
344
- setup: (parent) => {
345
- const componentRef = (0, import_vue2.ref)($vue.loading);
346
- const template = () => {
347
- var _a, _b, _c;
348
- const vnode = componentRef.value;
349
- return (_c = (_b = (_a = $vue.$slots).template) == null ? void 0 : _b.call(_a, { $vue, vnode })) != null ? _c : vnode;
350
- };
351
- const self = { template };
352
- (0, import_vue2.onMounted)(() => __async(this, null, function* () {
353
- try {
354
- if ($vue.resolve) {
355
- const target = yield $vue.resolve;
356
- target.hasOwnProperty("property") ? (0, import_vue2.watch)((0, import_vue2.isRef)(target.property) || (0, import_vue2.isReactive)(target.property) ? target.property : () => __async(this, null, function* () {
357
- return (yield $vue.resolve).property;
358
- }), (after, before) => {
359
- setTimeout(() => __async(this, null, function* () {
360
- return componentRef.value = yield target.onChange({ before: yield before, after: yield after });
361
- }), $vue.delay);
362
- }, $vue.options) : setTimeout(() => __async(this, null, function* () {
363
- return componentRef.value = target;
364
- }), $vue.delay);
365
- }
366
- } catch (error) {
367
- if ($vue.error) {
368
- componentRef.value = (0, import_vue2.h)(yield $vue.error, { error });
369
- }
370
- }
371
- }));
372
- return { parent, self };
373
- }
374
- }
375
- );
376
- };
377
- }
378
- };
379
-
380
287
  // src/index.ts
381
288
  var src_default = ReactiveView_default;
382
289
  function ucf(string) {
@@ -388,8 +295,25 @@ function ucfat(string, tokens) {
388
295
  const pattern = RegExp(`(?<=(?:${tokens.join("|")}))(\\w)(\\w*)`, "g");
389
296
  return string.replace(pattern, ($1, $2, $3) => `${$2.toUpperCase()}${$3.toLowerCase()}`);
390
297
  }
298
+ function getRoot(vue) {
299
+ var _a, _b, _c;
300
+ return (_c = (_a = typeof vue.$attrs.root === "function" ? vue.$attrs.root() : vue.$attrs.root) != null ? _a : vue.$root) != null ? _c : (_b = vue.$parent) == null ? void 0 : _b.$root;
301
+ }
302
+ function getRef(component, ref2) {
303
+ safeRequest({
304
+ try: async () => component.$props.ref.value = component,
305
+ alternative: false
306
+ });
307
+ return ref2.value = component;
308
+ }
309
+ function expose(vue, props2) {
310
+ Object.entries(Object.getOwnPropertyDescriptors(props2)).forEach(([key, val]) => {
311
+ Object.defineProperty(vue, key, val);
312
+ });
313
+ return props2;
314
+ }
391
315
  function safeRequest(request) {
392
- return new Promise((resolve) => __async(this, null, function* () {
316
+ return new Promise(async (resolve) => {
393
317
  var _a, _b, _c, _d;
394
318
  const { message } = (_a = request.loading) != null ? _a : {};
395
319
  if (request.loading) {
@@ -399,26 +323,22 @@ function safeRequest(request) {
399
323
  }
400
324
  }
401
325
  try {
402
- resolve(yield request.try());
326
+ resolve(await request.try());
403
327
  } catch (e) {
404
328
  if ((_b = request.alternative) != null ? _b : true) {
405
- resolve(request.catch ? yield request.catch(e) : console.log(e));
329
+ resolve(request.catch ? await request.catch(e) : console.log(e));
406
330
  }
407
331
  } finally {
408
- yield (_c = request.finally) == null ? void 0 : _c.call(request);
332
+ await ((_c = request.finally) == null ? void 0 : _c.call(request));
409
333
  if (request.loading) {
410
334
  request.loading.status = false;
411
335
  }
412
336
  if (request.loading && message) {
413
337
  request.loading.message = message;
414
338
  }
415
- yield (_d = request.complete) == null ? void 0 : _d.call(request);
339
+ await ((_d = request.complete) == null ? void 0 : _d.call(request));
416
340
  }
417
- }));
418
- }
419
- function getRoot(vue) {
420
- var _a, _b, _c;
421
- return (_c = (_a = typeof vue.$attrs.root === "function" ? vue.$attrs.root() : vue.$attrs.root) != null ? _a : vue.$root) != null ? _c : (_b = vue.$parent) == null ? void 0 : _b.$root;
341
+ });
422
342
  }
423
343
  function getProps(props2, param2) {
424
344
  var _a;
@@ -449,21 +369,6 @@ function getDate(param1, param2) {
449
369
  };
450
370
  return (0, import_date_fns_tz.formatInTimeZone)(datetime(), options.timezone, options.format);
451
371
  }
452
- function getRef(component, ref3) {
453
- safeRequest({
454
- try: () => __async(this, null, function* () {
455
- return component.$props.ref.value = component;
456
- }),
457
- alternative: false
458
- });
459
- return ref3.value = component;
460
- }
461
- function expose(vue, props2) {
462
- Object.entries(Object.getOwnPropertyDescriptors(props2)).forEach(([key, val]) => {
463
- Object.defineProperty(vue, key, val);
464
- });
465
- return props2;
466
- }
467
372
  function getSubscription() {
468
373
  const subscriptions = [];
469
374
  const subscription = Subscriptions.get();
@@ -492,8 +397,8 @@ function getSubscription() {
492
397
  };
493
398
  }
494
399
  function access($vue = {}) {
495
- var _a, _b;
496
- const target = typeof $vue.access === "function" ? $vue.access() : (_b = (_a = $vue.value && typeof $vue.value.access === "function" ? $vue.value.access() : $vue.value) != null ? _a : $vue) != null ? _b : {};
400
+ var _a, _b, _c;
401
+ const target = typeof ($vue == null ? void 0 : $vue.access) === "function" ? $vue.access() : (_c = (_b = ($vue == null ? void 0 : $vue.value) && typeof ((_a = $vue.value) == null ? void 0 : _a.access) === "function" ? $vue.value.access() : $vue == null ? void 0 : $vue.value) != null ? _b : $vue) != null ? _c : {};
497
402
  return new Proxy(target, {
498
403
  get(target2, key) {
499
404
  var _a2, _b2;
@@ -512,7 +417,6 @@ function access($vue = {}) {
512
417
  }
513
418
  // Annotate the CommonJS export names for ESM import in node:
514
419
  0 && (module.exports = {
515
- AsyncComponent,
516
420
  access,
517
421
  expose,
518
422
  getDate,
package/dist/index.mjs CHANGED
@@ -1,6 +1,4 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
2
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
3
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
4
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -16,7 +14,6 @@ var __spreadValues = (a, b) => {
16
14
  }
17
15
  return a;
18
16
  };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
17
  var __objRest = (source, exclude) => {
21
18
  var target = {};
22
19
  for (var prop in source)
@@ -29,26 +26,6 @@ var __objRest = (source, exclude) => {
29
26
  }
30
27
  return target;
31
28
  };
32
- var __async = (__this, __arguments, generator) => {
33
- return new Promise((resolve, reject) => {
34
- var fulfilled = (value) => {
35
- try {
36
- step(generator.next(value));
37
- } catch (e) {
38
- reject(e);
39
- }
40
- };
41
- var rejected = (value) => {
42
- try {
43
- step(generator.throw(value));
44
- } catch (e) {
45
- reject(e);
46
- }
47
- };
48
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
49
- step((generator = generator.apply(__this, __arguments)).next());
50
- });
51
- };
52
29
 
53
30
  // src/index.ts
54
31
  import { formatInTimeZone } from "date-fns-tz";
@@ -144,13 +121,13 @@ var Subscriptions = _Subscriptions;
144
121
  // src/ReactiveView.ts
145
122
  import ObjectManager from "@razaman2/object-manager";
146
123
  import DataManager from "@razaman2/data-manager";
147
- import { h, ref, watch } from "vue";
148
124
 
149
125
  // package.json
150
126
  var name = "@razaman2/reactive-view";
151
- var version = "0.0.6";
127
+ var version = "0.0.7";
152
128
 
153
129
  // src/ReactiveView.ts
130
+ import { h, ref, reactive, watch } from "vue";
154
131
  var props = {
155
132
  notifications: Object,
156
133
  subscriptions: Object,
@@ -163,7 +140,7 @@ var props = {
163
140
  },
164
141
  logging: {
165
142
  validator: (logging) => {
166
- return typeof logging === "boolean";
143
+ return logging.constructor.name === "Boolean";
167
144
  }
168
145
  },
169
146
  modelName: {
@@ -186,7 +163,7 @@ var setup = {
186
163
  var ReactiveView_default = {
187
164
  props: __spreadValues(__spreadValues({}, setup), props),
188
165
  setup(props2, context) {
189
- var _a, _b, _c, _d, _f;
166
+ var _a, _b, _c, _d, _e;
190
167
  const template = (vue, options2) => {
191
168
  var _a2, _b2, _c2;
192
169
  const vnode = context.slots.default ? h(
@@ -206,27 +183,21 @@ var ReactiveView_default = {
206
183
  Array.isArray(props2.state) ? (_a = props2.defaultData) != null ? _a : [] : (_b = props2.defaultData) != null ? _b : {}
207
184
  );
208
185
  const defaultType = Array.isArray(defaultData) ? [] : {};
209
- const stateRef = ref(DataManager.transform((_c = props2.state) != null ? _c : defaultType));
186
+ const state = reactive(DataManager.transform((_c = props2.state) != null ? _c : defaultType));
210
187
  const config = {
211
188
  defaultData,
212
- data: stateRef.value,
189
+ data: state,
213
190
  name: props2.modelName,
214
191
  logging: props2.logging,
215
192
  notifications: props2.notifications
216
193
  };
217
194
  const getState = props2.model ? typeof props2.model === "function" ? props2.model(config) : props2.model : new DataManager(config);
218
- const options = {
219
- parent: { self: props2 },
220
- self: { template, isValid, getState, stateRef }
221
- };
222
- const setup2 = (_d = props2.setup(options)) != null ? _d : options;
223
- const _e = setup2, { parent = {}, self = {} } = _e, rest = __objRest(_e, ["parent", "self"]);
224
195
  const sync = ref(false);
225
196
  if (context.attrs["onUpdate:modelState"]) {
226
197
  const config2 = typeof context.attrs["onUpdate:modelState"] === "function" ? { callback: context.attrs["onUpdate:modelState"] } : context.attrs["onUpdate:modelState"];
227
- const subscription = watch(() => ObjectManager.on(stateRef.value).clone(), (after, before) => {
198
+ watch(() => ObjectManager.on(state).clone(), (after, before) => {
228
199
  var _a2;
229
- const transform = (_a2 = config2.transform) != null ? _a2 : access(setup2).$transform;
200
+ const transform = (_a2 = config2.transform) != null ? _a2 : access(setup).$transform;
230
201
  const diff = {
231
202
  before: (before == null ? void 0 : before.hasOwnProperty("")) ? before[""] : before,
232
203
  after: (after == null ? void 0 : after.hasOwnProperty("")) ? after[""] : after
@@ -239,8 +210,8 @@ var ReactiveView_default = {
239
210
  }, config2.options);
240
211
  }
241
212
  if (context.attrs["onUpdate:propsState"] || props2.sync) {
242
- const config2 = (_f = typeof context.attrs["onUpdate:propsState"] === "function" ? { callback: context.attrs["onUpdate:propsState"] } : context.attrs["onUpdate:propsState"]) != null ? _f : {};
243
- const subscription = watch(() => props2.state, (after, before) => {
213
+ const config2 = (_d = typeof context.attrs["onUpdate:propsState"] === "function" ? { callback: context.attrs["onUpdate:propsState"] } : context.attrs["onUpdate:propsState"]) != null ? _d : {};
214
+ watch(() => props2.state, (after, before) => {
244
215
  if (props2.sync && typeof config2.callback !== "function") {
245
216
  getState.replaceData(after);
246
217
  } else if (typeof config2.callback === "function") {
@@ -249,91 +220,28 @@ var ReactiveView_default = {
249
220
  sync.value = true;
250
221
  }, config2.options);
251
222
  }
223
+ const options = {
224
+ parent: {},
225
+ self: { template, isValid, getState }
226
+ };
227
+ const _f = (_e = props2.setup(options)) != null ? _e : options, { parent = options.parent, self = options.self } = _f, rest = __objRest(_f, ["parent", "self"]);
252
228
  return ($vue) => {
253
- const setup3 = { $vue, options: parent };
254
- while (setup3.options) {
255
- Object.defineProperties(setup3.$vue, Object.assign({
229
+ const setup2 = { $vue, options: Object.assign(parent, { parent: { self: $vue } }) };
230
+ while (setup2.options) {
231
+ Object.defineProperties(setup2.$vue, Object.assign({
256
232
  access: {
257
233
  configurable: true,
258
- value: () => {
259
- return access({ parent, self });
260
- }
234
+ value: () => access({ parent, self })
261
235
  }
262
236
  }, rest));
263
- setup3.options = setup3.options.parent;
264
- setup3.$vue = setup3.$vue.$parent;
237
+ setup2.options = setup2.options.parent;
238
+ setup2.$vue = setup2.$vue.$parent;
265
239
  }
266
240
  return access($vue).template($vue, { parent, self });
267
241
  };
268
242
  }
269
243
  };
270
244
 
271
- // src/AsyncComponent.ts
272
- import { h as h2, ref as ref2, watch as watch2, isRef, isReactive, onMounted } from "vue";
273
- var AsyncComponent_default = {
274
- props: __spreadProps(__spreadValues({}, setup), {
275
- resolve: {
276
- required: true
277
- },
278
- delay: {
279
- type: Number,
280
- default: 200
281
- },
282
- timeout: {
283
- type: Number,
284
- default: 2e3
285
- },
286
- loading: {
287
- default: h2("div")
288
- },
289
- options: {
290
- type: Object
291
- },
292
- error: {
293
- required: false
294
- }
295
- }),
296
- setup() {
297
- return ($vue) => {
298
- return h2(
299
- src_default,
300
- {
301
- setup: (parent) => {
302
- const componentRef = ref2($vue.loading);
303
- const template = () => {
304
- var _a, _b, _c;
305
- const vnode = componentRef.value;
306
- return (_c = (_b = (_a = $vue.$slots).template) == null ? void 0 : _b.call(_a, { $vue, vnode })) != null ? _c : vnode;
307
- };
308
- const self = { template };
309
- onMounted(() => __async(this, null, function* () {
310
- try {
311
- if ($vue.resolve) {
312
- const target = yield $vue.resolve;
313
- target.hasOwnProperty("property") ? watch2(isRef(target.property) || isReactive(target.property) ? target.property : () => __async(this, null, function* () {
314
- return (yield $vue.resolve).property;
315
- }), (after, before) => {
316
- setTimeout(() => __async(this, null, function* () {
317
- return componentRef.value = yield target.onChange({ before: yield before, after: yield after });
318
- }), $vue.delay);
319
- }, $vue.options) : setTimeout(() => __async(this, null, function* () {
320
- return componentRef.value = target;
321
- }), $vue.delay);
322
- }
323
- } catch (error) {
324
- if ($vue.error) {
325
- componentRef.value = h2(yield $vue.error, { error });
326
- }
327
- }
328
- }));
329
- return { parent, self };
330
- }
331
- }
332
- );
333
- };
334
- }
335
- };
336
-
337
245
  // src/index.ts
338
246
  var src_default = ReactiveView_default;
339
247
  function ucf(string) {
@@ -345,8 +253,25 @@ function ucfat(string, tokens) {
345
253
  const pattern = RegExp(`(?<=(?:${tokens.join("|")}))(\\w)(\\w*)`, "g");
346
254
  return string.replace(pattern, ($1, $2, $3) => `${$2.toUpperCase()}${$3.toLowerCase()}`);
347
255
  }
256
+ function getRoot(vue) {
257
+ var _a, _b, _c;
258
+ return (_c = (_a = typeof vue.$attrs.root === "function" ? vue.$attrs.root() : vue.$attrs.root) != null ? _a : vue.$root) != null ? _c : (_b = vue.$parent) == null ? void 0 : _b.$root;
259
+ }
260
+ function getRef(component, ref2) {
261
+ safeRequest({
262
+ try: async () => component.$props.ref.value = component,
263
+ alternative: false
264
+ });
265
+ return ref2.value = component;
266
+ }
267
+ function expose(vue, props2) {
268
+ Object.entries(Object.getOwnPropertyDescriptors(props2)).forEach(([key, val]) => {
269
+ Object.defineProperty(vue, key, val);
270
+ });
271
+ return props2;
272
+ }
348
273
  function safeRequest(request) {
349
- return new Promise((resolve) => __async(this, null, function* () {
274
+ return new Promise(async (resolve) => {
350
275
  var _a, _b, _c, _d;
351
276
  const { message } = (_a = request.loading) != null ? _a : {};
352
277
  if (request.loading) {
@@ -356,26 +281,22 @@ function safeRequest(request) {
356
281
  }
357
282
  }
358
283
  try {
359
- resolve(yield request.try());
284
+ resolve(await request.try());
360
285
  } catch (e) {
361
286
  if ((_b = request.alternative) != null ? _b : true) {
362
- resolve(request.catch ? yield request.catch(e) : console.log(e));
287
+ resolve(request.catch ? await request.catch(e) : console.log(e));
363
288
  }
364
289
  } finally {
365
- yield (_c = request.finally) == null ? void 0 : _c.call(request);
290
+ await ((_c = request.finally) == null ? void 0 : _c.call(request));
366
291
  if (request.loading) {
367
292
  request.loading.status = false;
368
293
  }
369
294
  if (request.loading && message) {
370
295
  request.loading.message = message;
371
296
  }
372
- yield (_d = request.complete) == null ? void 0 : _d.call(request);
297
+ await ((_d = request.complete) == null ? void 0 : _d.call(request));
373
298
  }
374
- }));
375
- }
376
- function getRoot(vue) {
377
- var _a, _b, _c;
378
- return (_c = (_a = typeof vue.$attrs.root === "function" ? vue.$attrs.root() : vue.$attrs.root) != null ? _a : vue.$root) != null ? _c : (_b = vue.$parent) == null ? void 0 : _b.$root;
299
+ });
379
300
  }
380
301
  function getProps(props2, param2) {
381
302
  var _a;
@@ -406,21 +327,6 @@ function getDate(param1, param2) {
406
327
  };
407
328
  return formatInTimeZone(datetime(), options.timezone, options.format);
408
329
  }
409
- function getRef(component, ref3) {
410
- safeRequest({
411
- try: () => __async(this, null, function* () {
412
- return component.$props.ref.value = component;
413
- }),
414
- alternative: false
415
- });
416
- return ref3.value = component;
417
- }
418
- function expose(vue, props2) {
419
- Object.entries(Object.getOwnPropertyDescriptors(props2)).forEach(([key, val]) => {
420
- Object.defineProperty(vue, key, val);
421
- });
422
- return props2;
423
- }
424
330
  function getSubscription() {
425
331
  const subscriptions = [];
426
332
  const subscription = Subscriptions.get();
@@ -449,8 +355,8 @@ function getSubscription() {
449
355
  };
450
356
  }
451
357
  function access($vue = {}) {
452
- var _a, _b;
453
- const target = typeof $vue.access === "function" ? $vue.access() : (_b = (_a = $vue.value && typeof $vue.value.access === "function" ? $vue.value.access() : $vue.value) != null ? _a : $vue) != null ? _b : {};
358
+ var _a, _b, _c;
359
+ const target = typeof ($vue == null ? void 0 : $vue.access) === "function" ? $vue.access() : (_c = (_b = ($vue == null ? void 0 : $vue.value) && typeof ((_a = $vue.value) == null ? void 0 : _a.access) === "function" ? $vue.value.access() : $vue == null ? void 0 : $vue.value) != null ? _b : $vue) != null ? _c : {};
454
360
  return new Proxy(target, {
455
361
  get(target2, key) {
456
362
  var _a2, _b2;
@@ -468,7 +374,6 @@ function access($vue = {}) {
468
374
  });
469
375
  }
470
376
  export {
471
- AsyncComponent_default as AsyncComponent,
472
377
  access,
473
378
  src_default as default,
474
379
  expose,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@razaman2/reactive-view",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "This library enables you to build vue apps in an object oriented way. It provides a convenient approach to extend and override ui components. It provides a built in eventing system along with component data management.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",