@razaman2/reactive-view 0.0.33 → 0.0.34-beta.1

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
@@ -48,14 +48,12 @@ declare const _default: {
48
48
  default: boolean;
49
49
  };
50
50
  instance: {
51
- default: vue.Ref<any, any>;
51
+ default: () => vue.Ref<any, any>;
52
52
  };
53
53
  notifications: ObjectConstructor;
54
54
  subscriptions: ObjectConstructor;
55
55
  beforeSetData: FunctionConstructor;
56
- data: {
57
- default: {};
58
- };
56
+ data: {};
59
57
  defaultData: {};
60
58
  getDefaultData: {
61
59
  type: FunctionConstructor;
package/dist/index.d.ts CHANGED
@@ -48,14 +48,12 @@ declare const _default: {
48
48
  default: boolean;
49
49
  };
50
50
  instance: {
51
- default: vue.Ref<any, any>;
51
+ default: () => vue.Ref<any, any>;
52
52
  };
53
53
  notifications: ObjectConstructor;
54
54
  subscriptions: ObjectConstructor;
55
55
  beforeSetData: FunctionConstructor;
56
- data: {
57
- default: {};
58
- };
56
+ data: {};
59
57
  defaultData: {};
60
58
  getDefaultData: {
61
59
  type: FunctionConstructor;
package/dist/index.js CHANGED
@@ -168,7 +168,7 @@ var import_vue = require("vue");
168
168
 
169
169
  // package.json
170
170
  var name = "@razaman2/reactive-view";
171
- var version = "0.0.33";
171
+ var version = "0.0.34-beta.1";
172
172
 
173
173
  // src/ReactiveView.ts
174
174
  var setup = {
@@ -184,14 +184,12 @@ var ReactiveView_default = {
184
184
  default: true
185
185
  },
186
186
  instance: {
187
- default: (0, import_vue.ref)()
187
+ default: () => (0, import_vue.ref)()
188
188
  },
189
189
  notifications: Object,
190
190
  subscriptions: Object,
191
191
  beforeSetData: Function,
192
- data: {
193
- default: {}
194
- },
192
+ data: {},
195
193
  defaultData: {},
196
194
  getDefaultData: {
197
195
  type: Function,
@@ -214,7 +212,7 @@ var ReactiveView_default = {
214
212
  }
215
213
  },
216
214
  setup(props, context) {
217
- var _a, _b, _c, _d, _e, _f, _g;
215
+ var _a, _b, _c, _d, _e, _f, _g, _h;
218
216
  const template = (component2, vue2) => {
219
217
  return (0, import_vue.createVNode)(
220
218
  "div",
@@ -225,25 +223,26 @@ var ReactiveView_default = {
225
223
  );
226
224
  };
227
225
  const isValid = (0, import_vue.ref)(false);
228
- const ready = (0, import_vue.ref)(false);
229
- const vue = (0, import_vue.getCurrentInstance)();
226
+ const isReady = (0, import_vue.ref)(false);
227
+ const isFunctionData = ["Function"].includes(((_a = props.data) != null ? _a : {}).constructor.name);
228
+ const isAsyncFunctionData = ["AsyncFunction"].includes(((_b = props.data) != null ? _b : {}).constructor.name);
229
+ const isPromiseData = ["Promise"].includes(((_c = props.data) != null ? _c : {}).constructor.name) || isAsyncFunctionData;
230
230
  const defer = (0, import_vue.ref)(typeof props.defer === "function" ? props.defer() : props.defer);
231
- const data = typeof props.data === "function" ? props.data() : props.data;
232
- const async = data instanceof Promise;
231
+ const vue = (0, import_vue.getCurrentInstance)();
233
232
  if (props.debug) {
234
- console.log("[ReactiveView]:", { props, context, isValid, ready, vue, defer, data, async });
233
+ console.log("[ReactiveView]:", { props, context, vue, defer, data: props.data, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
235
234
  }
236
- if (async && !((_a = vue.vnode.props) == null ? void 0 : _a.hasOwnProperty("defaultData"))) {
237
- console.error("[ReactiveView]: defaultData is required for async data.");
235
+ if ((isPromiseData || isFunctionData) && !("defaultData" in vue.vnode.props)) {
236
+ console.error("[ReactiveView]: defaultData is required for promise or async function data.");
238
237
  }
239
238
  const defaultData = props.getDefaultData(
240
- ((_b = vue.vnode.props) == null ? void 0 : _b.hasOwnProperty("defaultData")) ? vue.vnode.props.defaultData : typeof ((_c = vue.vnode.props) == null ? void 0 : _c.data) === "object" ? Array.isArray(vue.vnode.props.data) ? [] : {} : ((_d = vue.vnode.props) == null ? void 0 : _d.hasOwnProperty("data")) ? (_e = vue.vnode.props) == null ? void 0 : _e.data : {}
239
+ ((_d = vue.vnode.props) == null ? void 0 : _d.hasOwnProperty("defaultData")) ? vue.vnode.props.defaultData : ((_e = vue.vnode.props) == null ? void 0 : _e.hasOwnProperty("data")) ? Array.isArray(vue.vnode.props.data) ? [] : {} : {}
241
240
  );
242
241
  const datatype = Array.isArray(defaultData) ? [] : {};
243
242
  const config = {
244
- data: (0, import_vue.reactive)(
245
- import_object_manager.default.on(async ? datatype : ((_f = vue.vnode.props) == null ? void 0 : _f.hasOwnProperty("data")) ? typeof data === "function" ? datatype : data : datatype).clone()
246
- ),
243
+ data: (0, import_vue.reactive)(import_object_manager.default.on(
244
+ isPromiseData || isFunctionData || (0, import_vue.isRef)(props.data) || (0, import_vue.isReactive)(props.data) ? datatype : ((_f = vue.vnode.props) == null ? void 0 : _f.hasOwnProperty("data")) ? props.data : datatype
245
+ ).clone()),
247
246
  defaultData: import_object_manager.default.on(defaultData).clone(),
248
247
  notifications: props.notifications,
249
248
  subscriptions: props.subscriptions,
@@ -270,20 +269,17 @@ var ReactiveView_default = {
270
269
  }
271
270
  }
272
271
  });
272
+ const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, isValid } });
273
273
  const watchDataProp = (dataProp) => {
274
274
  var _a2, _b2, _c2;
275
275
  const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
276
276
  callback: (_b2 = ((_a2 = context.attrs["onUpdate:data"]) != null ? _a2 : {}).callback) != null ? _b2 : context.attrs["data:callback"],
277
- options: Object.assign({
278
- immediate: context.attrs["data:immediate"],
279
- deep: context.attrs["data:deep"],
280
- once: context.attrs["data:once"]
281
- }, ((_c2 = context.attrs["onUpdate:data"]) != null ? _c2 : {}).options)
277
+ options: Object.assign(__spreadValues(__spreadValues(__spreadValues({}, context.attrs["data:immediate"] ? { immediate: context.attrs["data:immediate"] } : {}), context.attrs["data:deep"] ? { deep: context.attrs["data:deep"] } : {}), context.attrs["data:once"] ? { once: context.attrs["data:once"] } : {}), ((_c2 = context.attrs["onUpdate:data"]) != null ? _c2 : {}).options)
282
278
  };
283
279
  if (context.attrs["data:log"]) {
284
- console.log(`[data:prop]:`, config2);
280
+ console.log(`[ReactiveView]:data`, { config: config2, dataProp });
285
281
  }
286
- (0, import_vue.watch)(typeof dataProp === "function" || (0, import_vue.isRef)(dataProp) || (0, import_vue.isReactive)(dataProp) ? dataProp : () => dataProp, (after, before) => {
282
+ (0, import_vue.watch)(isFunctionData || (0, import_vue.isRef)(dataProp) || (0, import_vue.isReactive)(dataProp) ? dataProp : () => dataProp, (after, before) => {
287
283
  var _a3;
288
284
  const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
289
285
  if (typeof config2.callback === "function") {
@@ -293,25 +289,28 @@ var ReactiveView_default = {
293
289
  }
294
290
  }, config2.options);
295
291
  };
296
- setTimeout(async () => {
297
- var _a2;
298
- const [dataProp] = await Promise.all([data, (_a2 = defer.value) != null ? _a2 : true]);
299
- watchDataProp(dataProp);
300
- });
301
- setTimeout(async () => {
302
- var _a2;
303
- ready.value = (_a2 = await defer.value) != null ? _a2 : true;
304
- });
305
- if (context.attrs["onUpdate:model"]) {
292
+ if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
306
293
  const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
307
- callback: context.attrs["onUpdate:model"]
308
- } : (_g = context.attrs["onUpdate:model"]) != null ? _g : {};
294
+ callback: context.attrs["onUpdate:model"],
295
+ options: Object.assign(__spreadValues(__spreadValues(__spreadValues({}, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:deep"] ? { deep: context.attrs["model:deep"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_g = context.attrs["onUpdate:model"]) != null ? _g : {}).options)
296
+ } : (_h = context.attrs["onUpdate:model"]) != null ? _h : {};
297
+ if (context.attrs["model:log"]) {
298
+ console.log(`[ReactiveView]:model`, { config: config2 });
299
+ }
309
300
  (0, import_vue.watch)(() => model.getData(), (after, before) => {
310
301
  const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
311
302
  config2.callback(diff, { component });
312
303
  }, config2.options);
313
304
  }
314
- const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, isValid } });
305
+ setTimeout(async () => {
306
+ var _a2;
307
+ const [data] = await Promise.all([isAsyncFunctionData ? props.data() : props.data, (_a2 = defer.value) != null ? _a2 : true]);
308
+ watchDataProp(data);
309
+ });
310
+ setTimeout(async () => {
311
+ var _a2;
312
+ isReady.value = (_a2 = await defer.value) != null ? _a2 : true;
313
+ });
315
314
  component.value = [access(component)].reduce((options, parent) => {
316
315
  var _a2;
317
316
  while (parent) {
@@ -331,7 +330,7 @@ var ReactiveView_default = {
331
330
  props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
332
331
  return (vue2) => {
333
332
  var _a2, _b2;
334
- if (ready.value) {
333
+ if (isReady.value) {
335
334
  return access(component).template(component, vue2);
336
335
  } else {
337
336
  return (_b2 = (_a2 = context.slots).loading) == null ? void 0 : _b2.call(_a2, { component });
package/dist/index.mjs CHANGED
@@ -125,7 +125,7 @@ import { ref, reactive, watch, isRef, isReactive, createVNode, getCurrentInstanc
125
125
 
126
126
  // package.json
127
127
  var name = "@razaman2/reactive-view";
128
- var version = "0.0.33";
128
+ var version = "0.0.34-beta.1";
129
129
 
130
130
  // src/ReactiveView.ts
131
131
  var setup = {
@@ -141,14 +141,12 @@ var ReactiveView_default = {
141
141
  default: true
142
142
  },
143
143
  instance: {
144
- default: ref()
144
+ default: () => ref()
145
145
  },
146
146
  notifications: Object,
147
147
  subscriptions: Object,
148
148
  beforeSetData: Function,
149
- data: {
150
- default: {}
151
- },
149
+ data: {},
152
150
  defaultData: {},
153
151
  getDefaultData: {
154
152
  type: Function,
@@ -171,7 +169,7 @@ var ReactiveView_default = {
171
169
  }
172
170
  },
173
171
  setup(props, context) {
174
- var _a, _b, _c, _d, _e, _f, _g;
172
+ var _a, _b, _c, _d, _e, _f, _g, _h;
175
173
  const template = (component2, vue2) => {
176
174
  return createVNode(
177
175
  "div",
@@ -182,25 +180,26 @@ var ReactiveView_default = {
182
180
  );
183
181
  };
184
182
  const isValid = ref(false);
185
- const ready = ref(false);
186
- const vue = getCurrentInstance();
183
+ const isReady = ref(false);
184
+ const isFunctionData = ["Function"].includes(((_a = props.data) != null ? _a : {}).constructor.name);
185
+ const isAsyncFunctionData = ["AsyncFunction"].includes(((_b = props.data) != null ? _b : {}).constructor.name);
186
+ const isPromiseData = ["Promise"].includes(((_c = props.data) != null ? _c : {}).constructor.name) || isAsyncFunctionData;
187
187
  const defer = ref(typeof props.defer === "function" ? props.defer() : props.defer);
188
- const data = typeof props.data === "function" ? props.data() : props.data;
189
- const async = data instanceof Promise;
188
+ const vue = getCurrentInstance();
190
189
  if (props.debug) {
191
- console.log("[ReactiveView]:", { props, context, isValid, ready, vue, defer, data, async });
190
+ console.log("[ReactiveView]:", { props, context, vue, defer, data: props.data, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
192
191
  }
193
- if (async && !((_a = vue.vnode.props) == null ? void 0 : _a.hasOwnProperty("defaultData"))) {
194
- console.error("[ReactiveView]: defaultData is required for async data.");
192
+ if ((isPromiseData || isFunctionData) && !("defaultData" in vue.vnode.props)) {
193
+ console.error("[ReactiveView]: defaultData is required for promise or async function data.");
195
194
  }
196
195
  const defaultData = props.getDefaultData(
197
- ((_b = vue.vnode.props) == null ? void 0 : _b.hasOwnProperty("defaultData")) ? vue.vnode.props.defaultData : typeof ((_c = vue.vnode.props) == null ? void 0 : _c.data) === "object" ? Array.isArray(vue.vnode.props.data) ? [] : {} : ((_d = vue.vnode.props) == null ? void 0 : _d.hasOwnProperty("data")) ? (_e = vue.vnode.props) == null ? void 0 : _e.data : {}
196
+ ((_d = vue.vnode.props) == null ? void 0 : _d.hasOwnProperty("defaultData")) ? vue.vnode.props.defaultData : ((_e = vue.vnode.props) == null ? void 0 : _e.hasOwnProperty("data")) ? Array.isArray(vue.vnode.props.data) ? [] : {} : {}
198
197
  );
199
198
  const datatype = Array.isArray(defaultData) ? [] : {};
200
199
  const config = {
201
- data: reactive(
202
- ObjectManager.on(async ? datatype : ((_f = vue.vnode.props) == null ? void 0 : _f.hasOwnProperty("data")) ? typeof data === "function" ? datatype : data : datatype).clone()
203
- ),
200
+ data: reactive(ObjectManager.on(
201
+ isPromiseData || isFunctionData || isRef(props.data) || isReactive(props.data) ? datatype : ((_f = vue.vnode.props) == null ? void 0 : _f.hasOwnProperty("data")) ? props.data : datatype
202
+ ).clone()),
204
203
  defaultData: ObjectManager.on(defaultData).clone(),
205
204
  notifications: props.notifications,
206
205
  subscriptions: props.subscriptions,
@@ -227,20 +226,17 @@ var ReactiveView_default = {
227
226
  }
228
227
  }
229
228
  });
229
+ const component = ref({ parent: { self: vue.proxy }, self: { template, model, isValid } });
230
230
  const watchDataProp = (dataProp) => {
231
231
  var _a2, _b2, _c2;
232
232
  const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
233
233
  callback: (_b2 = ((_a2 = context.attrs["onUpdate:data"]) != null ? _a2 : {}).callback) != null ? _b2 : context.attrs["data:callback"],
234
- options: Object.assign({
235
- immediate: context.attrs["data:immediate"],
236
- deep: context.attrs["data:deep"],
237
- once: context.attrs["data:once"]
238
- }, ((_c2 = context.attrs["onUpdate:data"]) != null ? _c2 : {}).options)
234
+ options: Object.assign(__spreadValues(__spreadValues(__spreadValues({}, context.attrs["data:immediate"] ? { immediate: context.attrs["data:immediate"] } : {}), context.attrs["data:deep"] ? { deep: context.attrs["data:deep"] } : {}), context.attrs["data:once"] ? { once: context.attrs["data:once"] } : {}), ((_c2 = context.attrs["onUpdate:data"]) != null ? _c2 : {}).options)
239
235
  };
240
236
  if (context.attrs["data:log"]) {
241
- console.log(`[data:prop]:`, config2);
237
+ console.log(`[ReactiveView]:data`, { config: config2, dataProp });
242
238
  }
243
- watch(typeof dataProp === "function" || isRef(dataProp) || isReactive(dataProp) ? dataProp : () => dataProp, (after, before) => {
239
+ watch(isFunctionData || isRef(dataProp) || isReactive(dataProp) ? dataProp : () => dataProp, (after, before) => {
244
240
  var _a3;
245
241
  const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
246
242
  if (typeof config2.callback === "function") {
@@ -250,25 +246,28 @@ var ReactiveView_default = {
250
246
  }
251
247
  }, config2.options);
252
248
  };
253
- setTimeout(async () => {
254
- var _a2;
255
- const [dataProp] = await Promise.all([data, (_a2 = defer.value) != null ? _a2 : true]);
256
- watchDataProp(dataProp);
257
- });
258
- setTimeout(async () => {
259
- var _a2;
260
- ready.value = (_a2 = await defer.value) != null ? _a2 : true;
261
- });
262
- if (context.attrs["onUpdate:model"]) {
249
+ if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
263
250
  const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
264
- callback: context.attrs["onUpdate:model"]
265
- } : (_g = context.attrs["onUpdate:model"]) != null ? _g : {};
251
+ callback: context.attrs["onUpdate:model"],
252
+ options: Object.assign(__spreadValues(__spreadValues(__spreadValues({}, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:deep"] ? { deep: context.attrs["model:deep"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_g = context.attrs["onUpdate:model"]) != null ? _g : {}).options)
253
+ } : (_h = context.attrs["onUpdate:model"]) != null ? _h : {};
254
+ if (context.attrs["model:log"]) {
255
+ console.log(`[ReactiveView]:model`, { config: config2 });
256
+ }
266
257
  watch(() => model.getData(), (after, before) => {
267
258
  const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
268
259
  config2.callback(diff, { component });
269
260
  }, config2.options);
270
261
  }
271
- const component = ref({ parent: { self: vue.proxy }, self: { template, model, isValid } });
262
+ setTimeout(async () => {
263
+ var _a2;
264
+ const [data] = await Promise.all([isAsyncFunctionData ? props.data() : props.data, (_a2 = defer.value) != null ? _a2 : true]);
265
+ watchDataProp(data);
266
+ });
267
+ setTimeout(async () => {
268
+ var _a2;
269
+ isReady.value = (_a2 = await defer.value) != null ? _a2 : true;
270
+ });
272
271
  component.value = [access(component)].reduce((options, parent) => {
273
272
  var _a2;
274
273
  while (parent) {
@@ -288,7 +287,7 @@ var ReactiveView_default = {
288
287
  props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
289
288
  return (vue2) => {
290
289
  var _a2, _b2;
291
- if (ready.value) {
290
+ if (isReady.value) {
292
291
  return access(component).template(component, vue2);
293
292
  } else {
294
293
  return (_b2 = (_a2 = context.slots).loading) == null ? void 0 : _b2.call(_a2, { component });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@razaman2/reactive-view",
3
- "version": "0.0.33",
3
+ "version": "0.0.34-beta.1",
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",
@@ -29,13 +29,13 @@
29
29
  "uuid": "^11.1.0"
30
30
  },
31
31
  "peerDependencies": {
32
- "vue": "^3.5.16"
32
+ "vue": "^3.5.18"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@types/uuid": "^10.0.0",
36
36
  "tsup": "^8.5.0",
37
- "typescript": "^5.8.3",
38
- "vitest": "^3.2.3"
37
+ "typescript": "^5.9.2",
38
+ "vitest": "^3.2.4"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public"