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

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.2";
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, _i;
218
216
  const template = (component2, vue2) => {
219
217
  return (0, import_vue.createVNode)(
220
218
  "div",
@@ -225,25 +223,23 @@ 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;
233
- if (props.debug) {
234
- console.log("[ReactiveView]:", { props, context, isValid, ready, vue, defer, data, async });
235
- }
236
- if (async && !((_a = vue.vnode.props) == null ? void 0 : _a.hasOwnProperty("defaultData"))) {
237
- console.error("[ReactiveView]: defaultData is required for async data.");
231
+ const vue = (0, import_vue.getCurrentInstance)();
232
+ if ((isPromiseData || isFunctionData) && !("defaultData" in vue.vnode.props)) {
233
+ console.error("[ReactiveView]: defaultData is required for promise or async function data.");
238
234
  }
239
235
  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 : {}
236
+ ((_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
237
  );
242
238
  const datatype = Array.isArray(defaultData) ? [] : {};
243
239
  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
- ),
240
+ data: (0, import_vue.reactive)(import_object_manager.default.on(
241
+ 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
242
+ ).clone()),
247
243
  defaultData: import_object_manager.default.on(defaultData).clone(),
248
244
  notifications: props.notifications,
249
245
  subscriptions: props.subscriptions,
@@ -257,9 +253,11 @@ var ReactiveView_default = {
257
253
  var _a2;
258
254
  const beforeSetData = (_a2 = access(component).beforeSetData) != null ? _a2 : props.beforeSetData;
259
255
  if (typeof beforeSetData === "function") {
260
- const after = import_object_manager.default.on(datatype).set(...params.length ? params : [defaultData]).get();
261
256
  const before = target.getData();
262
- beforeSetData({ before, after }, target);
257
+ const after = (params.length ? import_object_manager.default.on(datatype).set(...params) : import_object_manager.default.on(datatype).set(defaultData)).get();
258
+ if (beforeSetData({ before, after }, target)) {
259
+ target[key](...params);
260
+ }
263
261
  } else {
264
262
  target[key](...params);
265
263
  }
@@ -270,20 +268,20 @@ var ReactiveView_default = {
270
268
  }
271
269
  }
272
270
  });
271
+ const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, isValid } });
272
+ if (props.debug) {
273
+ console.log("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
274
+ }
273
275
  const watchDataProp = (dataProp) => {
274
276
  var _a2, _b2, _c2;
275
277
  const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
276
278
  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)
279
+ 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
280
  };
283
281
  if (context.attrs["data:log"]) {
284
- console.log(`[data:prop]:`, config2);
282
+ console.log(`[ReactiveView]:data`, { config: config2, dataProp });
285
283
  }
286
- (0, import_vue.watch)(typeof dataProp === "function" || (0, import_vue.isRef)(dataProp) || (0, import_vue.isReactive)(dataProp) ? dataProp : () => dataProp, (after, before) => {
284
+ (0, import_vue.watch)(isFunctionData || (0, import_vue.isRef)(dataProp) || (0, import_vue.isReactive)(dataProp) ? dataProp : () => dataProp, (after, before) => {
287
285
  var _a3;
288
286
  const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
289
287
  if (typeof config2.callback === "function") {
@@ -293,25 +291,30 @@ var ReactiveView_default = {
293
291
  }
294
292
  }, config2.options);
295
293
  };
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"]) {
294
+ if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
306
295
  const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
307
- callback: context.attrs["onUpdate:model"]
308
- } : (_g = context.attrs["onUpdate:model"]) != null ? _g : {};
296
+ callback: context.attrs["onUpdate:model"],
297
+ options: Object.assign(__spreadValues(__spreadValues({
298
+ deep: (_g = context.attrs["model:deep"]) != null ? _g : true
299
+ }, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_h = context.attrs["onUpdate:model"]) != null ? _h : {}).options)
300
+ } : (_i = context.attrs["onUpdate:model"]) != null ? _i : {};
301
+ if (context.attrs["model:log"]) {
302
+ console.log(`[ReactiveView]:model`, { config: config2 });
303
+ }
309
304
  (0, import_vue.watch)(() => model.getData(), (after, before) => {
310
305
  const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
311
306
  config2.callback(diff, { component });
312
307
  }, config2.options);
313
308
  }
314
- const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, isValid } });
309
+ setTimeout(async () => {
310
+ var _a2;
311
+ const [data] = await Promise.all([isAsyncFunctionData ? props.data() : props.data, (_a2 = defer.value) != null ? _a2 : true]);
312
+ watchDataProp(data);
313
+ });
314
+ setTimeout(async () => {
315
+ var _a2;
316
+ isReady.value = (_a2 = await defer.value) != null ? _a2 : true;
317
+ });
315
318
  component.value = [access(component)].reduce((options, parent) => {
316
319
  var _a2;
317
320
  while (parent) {
@@ -331,7 +334,7 @@ var ReactiveView_default = {
331
334
  props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
332
335
  return (vue2) => {
333
336
  var _a2, _b2;
334
- if (ready.value) {
337
+ if (isReady.value) {
335
338
  return access(component).template(component, vue2);
336
339
  } else {
337
340
  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.2";
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, _i;
175
173
  const template = (component2, vue2) => {
176
174
  return createVNode(
177
175
  "div",
@@ -182,25 +180,23 @@ 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;
190
- if (props.debug) {
191
- console.log("[ReactiveView]:", { props, context, isValid, ready, vue, defer, data, async });
192
- }
193
- if (async && !((_a = vue.vnode.props) == null ? void 0 : _a.hasOwnProperty("defaultData"))) {
194
- console.error("[ReactiveView]: defaultData is required for async data.");
188
+ const vue = getCurrentInstance();
189
+ if ((isPromiseData || isFunctionData) && !("defaultData" in vue.vnode.props)) {
190
+ console.error("[ReactiveView]: defaultData is required for promise or async function data.");
195
191
  }
196
192
  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 : {}
193
+ ((_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
194
  );
199
195
  const datatype = Array.isArray(defaultData) ? [] : {};
200
196
  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
- ),
197
+ data: reactive(ObjectManager.on(
198
+ isPromiseData || isFunctionData || isRef(props.data) || isReactive(props.data) ? datatype : ((_f = vue.vnode.props) == null ? void 0 : _f.hasOwnProperty("data")) ? props.data : datatype
199
+ ).clone()),
204
200
  defaultData: ObjectManager.on(defaultData).clone(),
205
201
  notifications: props.notifications,
206
202
  subscriptions: props.subscriptions,
@@ -214,9 +210,11 @@ var ReactiveView_default = {
214
210
  var _a2;
215
211
  const beforeSetData = (_a2 = access(component).beforeSetData) != null ? _a2 : props.beforeSetData;
216
212
  if (typeof beforeSetData === "function") {
217
- const after = ObjectManager.on(datatype).set(...params.length ? params : [defaultData]).get();
218
213
  const before = target.getData();
219
- beforeSetData({ before, after }, target);
214
+ const after = (params.length ? ObjectManager.on(datatype).set(...params) : ObjectManager.on(datatype).set(defaultData)).get();
215
+ if (beforeSetData({ before, after }, target)) {
216
+ target[key](...params);
217
+ }
220
218
  } else {
221
219
  target[key](...params);
222
220
  }
@@ -227,20 +225,20 @@ var ReactiveView_default = {
227
225
  }
228
226
  }
229
227
  });
228
+ const component = ref({ parent: { self: vue.proxy }, self: { template, model, isValid } });
229
+ if (props.debug) {
230
+ console.log("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
231
+ }
230
232
  const watchDataProp = (dataProp) => {
231
233
  var _a2, _b2, _c2;
232
234
  const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
233
235
  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)
236
+ 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
237
  };
240
238
  if (context.attrs["data:log"]) {
241
- console.log(`[data:prop]:`, config2);
239
+ console.log(`[ReactiveView]:data`, { config: config2, dataProp });
242
240
  }
243
- watch(typeof dataProp === "function" || isRef(dataProp) || isReactive(dataProp) ? dataProp : () => dataProp, (after, before) => {
241
+ watch(isFunctionData || isRef(dataProp) || isReactive(dataProp) ? dataProp : () => dataProp, (after, before) => {
244
242
  var _a3;
245
243
  const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
246
244
  if (typeof config2.callback === "function") {
@@ -250,25 +248,30 @@ var ReactiveView_default = {
250
248
  }
251
249
  }, config2.options);
252
250
  };
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"]) {
251
+ if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
263
252
  const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
264
- callback: context.attrs["onUpdate:model"]
265
- } : (_g = context.attrs["onUpdate:model"]) != null ? _g : {};
253
+ callback: context.attrs["onUpdate:model"],
254
+ options: Object.assign(__spreadValues(__spreadValues({
255
+ deep: (_g = context.attrs["model:deep"]) != null ? _g : true
256
+ }, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_h = context.attrs["onUpdate:model"]) != null ? _h : {}).options)
257
+ } : (_i = context.attrs["onUpdate:model"]) != null ? _i : {};
258
+ if (context.attrs["model:log"]) {
259
+ console.log(`[ReactiveView]:model`, { config: config2 });
260
+ }
266
261
  watch(() => model.getData(), (after, before) => {
267
262
  const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
268
263
  config2.callback(diff, { component });
269
264
  }, config2.options);
270
265
  }
271
- const component = ref({ parent: { self: vue.proxy }, self: { template, model, isValid } });
266
+ setTimeout(async () => {
267
+ var _a2;
268
+ const [data] = await Promise.all([isAsyncFunctionData ? props.data() : props.data, (_a2 = defer.value) != null ? _a2 : true]);
269
+ watchDataProp(data);
270
+ });
271
+ setTimeout(async () => {
272
+ var _a2;
273
+ isReady.value = (_a2 = await defer.value) != null ? _a2 : true;
274
+ });
272
275
  component.value = [access(component)].reduce((options, parent) => {
273
276
  var _a2;
274
277
  while (parent) {
@@ -288,7 +291,7 @@ var ReactiveView_default = {
288
291
  props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
289
292
  return (vue2) => {
290
293
  var _a2, _b2;
291
- if (ready.value) {
294
+ if (isReady.value) {
292
295
  return access(component).template(component, vue2);
293
296
  } else {
294
297
  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.2",
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"