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

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
@@ -53,7 +53,9 @@ declare const _default: {
53
53
  notifications: ObjectConstructor;
54
54
  subscriptions: ObjectConstructor;
55
55
  beforeSetData: FunctionConstructor;
56
- data: {};
56
+ data: {
57
+ default: () => {};
58
+ };
57
59
  defaultData: {};
58
60
  getDefaultData: {
59
61
  type: FunctionConstructor;
@@ -72,6 +74,7 @@ declare const _default: {
72
74
  type: BooleanConstructor;
73
75
  default: boolean;
74
76
  };
77
+ state: {};
75
78
  };
76
79
  setup(props: Record<string, any>, context: SetupContext): (vue: ComponentPublicInstance) => any;
77
80
  };
@@ -115,5 +118,8 @@ declare function useSubscription(): {
115
118
  declare function StyleParser(styles?: Array<string> | Record<string, boolean> | string): {};
116
119
  declare function MergeStyles(...params: any): any;
117
120
  declare const extendVnode: (component: Record<string, any>, element: any) => Record<string, (props?: Record<string, any>, slots?: Record<string, any> | ((slots: Record<string, any>) => Record<string, any>)) => any>;
121
+ declare const getData: (component: any, path: number | string, alternative: any) => any;
122
+ declare const setData: (component: any, data: any, path?: string) => any;
123
+ declare const dataPath: (component: any, path: string | number) => any;
118
124
 
119
- export { MergeStyles, StyleParser, access, _default as default, extendVnode, getDate, getProps, getReactiveViewComponent, safeRequest, setup, useSubscription };
125
+ export { MergeStyles, StyleParser, access, dataPath, _default as default, extendVnode, getData, getDate, getProps, getReactiveViewComponent, safeRequest, setData, setup, useSubscription };
package/dist/index.d.ts CHANGED
@@ -53,7 +53,9 @@ declare const _default: {
53
53
  notifications: ObjectConstructor;
54
54
  subscriptions: ObjectConstructor;
55
55
  beforeSetData: FunctionConstructor;
56
- data: {};
56
+ data: {
57
+ default: () => {};
58
+ };
57
59
  defaultData: {};
58
60
  getDefaultData: {
59
61
  type: FunctionConstructor;
@@ -72,6 +74,7 @@ declare const _default: {
72
74
  type: BooleanConstructor;
73
75
  default: boolean;
74
76
  };
77
+ state: {};
75
78
  };
76
79
  setup(props: Record<string, any>, context: SetupContext): (vue: ComponentPublicInstance) => any;
77
80
  };
@@ -115,5 +118,8 @@ declare function useSubscription(): {
115
118
  declare function StyleParser(styles?: Array<string> | Record<string, boolean> | string): {};
116
119
  declare function MergeStyles(...params: any): any;
117
120
  declare const extendVnode: (component: Record<string, any>, element: any) => Record<string, (props?: Record<string, any>, slots?: Record<string, any> | ((slots: Record<string, any>) => Record<string, any>)) => any>;
121
+ declare const getData: (component: any, path: number | string, alternative: any) => any;
122
+ declare const setData: (component: any, data: any, path?: string) => any;
123
+ declare const dataPath: (component: any, path: string | number) => any;
118
124
 
119
- export { MergeStyles, StyleParser, access, _default as default, extendVnode, getDate, getProps, getReactiveViewComponent, safeRequest, setup, useSubscription };
125
+ export { MergeStyles, StyleParser, access, dataPath, _default as default, extendVnode, getData, getDate, getProps, getReactiveViewComponent, safeRequest, setData, setup, useSubscription };
package/dist/index.js CHANGED
@@ -59,16 +59,20 @@ __export(index_exports, {
59
59
  MergeStyles: () => MergeStyles,
60
60
  StyleParser: () => StyleParser,
61
61
  access: () => access,
62
+ dataPath: () => dataPath,
62
63
  default: () => index_default,
63
64
  extendVnode: () => extendVnode,
65
+ getData: () => getData,
64
66
  getDate: () => getDate,
65
67
  getProps: () => getProps,
66
68
  getReactiveViewComponent: () => getReactiveViewComponent,
67
69
  safeRequest: () => safeRequest,
70
+ setData: () => setData,
68
71
  setup: () => setup,
69
72
  useSubscription: () => useSubscription
70
73
  });
71
74
  module.exports = __toCommonJS(index_exports);
75
+ var import_object_manager2 = __toESM(require("@razaman2/object-manager"));
72
76
 
73
77
  // src/Subscription.ts
74
78
  var Subscription = class _Subscription {
@@ -168,7 +172,7 @@ var import_vue = require("vue");
168
172
 
169
173
  // package.json
170
174
  var name = "@razaman2/reactive-view";
171
- var version = "0.0.34-beta.1";
175
+ var version = "0.0.34-beta.10";
172
176
 
173
177
  // src/ReactiveView.ts
174
178
  var setup = {
@@ -189,7 +193,9 @@ var ReactiveView_default = {
189
193
  notifications: Object,
190
194
  subscriptions: Object,
191
195
  beforeSetData: Function,
192
- data: {},
196
+ data: {
197
+ default: () => ({})
198
+ },
193
199
  defaultData: {},
194
200
  getDefaultData: {
195
201
  type: Function,
@@ -209,10 +215,27 @@ var ReactiveView_default = {
209
215
  debug: {
210
216
  type: Boolean,
211
217
  default: false
212
- }
218
+ },
219
+ state: {}
213
220
  },
214
221
  setup(props, context) {
215
- var _a, _b, _c, _d, _e, _f, _g, _h;
222
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
223
+ const diff = (before, after) => {
224
+ const change = after.paths().reduce((change2, path) => {
225
+ if (before.get(path) !== after.get(path)) {
226
+ change2.set(path, after.get(path));
227
+ }
228
+ return change2;
229
+ }, import_object_manager.default.on({}));
230
+ return { before: before.get(), after: after.get(), change: change.get() };
231
+ };
232
+ const dataPath2 = (path) => {
233
+ try {
234
+ return context.attrs["data:path"](path);
235
+ } catch (e) {
236
+ return path;
237
+ }
238
+ };
216
239
  const template = (component2, vue2) => {
217
240
  return (0, import_vue.createVNode)(
218
241
  "div",
@@ -224,14 +247,11 @@ var ReactiveView_default = {
224
247
  };
225
248
  const isValid = (0, import_vue.ref)(false);
226
249
  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;
250
+ const isFunctionData = ["Function"].includes((_a = props.data) == null ? void 0 : _a.constructor.name);
251
+ const isAsyncFunctionData = ["AsyncFunction"].includes((_b = props.data) == null ? void 0 : _b.constructor.name);
252
+ const isPromiseData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
230
253
  const defer = (0, import_vue.ref)(typeof props.defer === "function" ? props.defer() : props.defer);
231
254
  const vue = (0, import_vue.getCurrentInstance)();
232
- if (props.debug) {
233
- console.log("[ReactiveView]:", { props, context, vue, defer, data: props.data, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
234
- }
235
255
  if ((isPromiseData || isFunctionData) && !("defaultData" in vue.vnode.props)) {
236
256
  console.error("[ReactiveView]: defaultData is required for promise or async function data.");
237
257
  }
@@ -256,9 +276,11 @@ var ReactiveView_default = {
256
276
  var _a2;
257
277
  const beforeSetData = (_a2 = access(component).beforeSetData) != null ? _a2 : props.beforeSetData;
258
278
  if (typeof beforeSetData === "function") {
259
- const after = import_object_manager.default.on(datatype).set(...params.length ? params : [defaultData]).get();
260
279
  const before = target.getData();
261
- beforeSetData({ before, after }, target);
280
+ const after = params.length ? import_object_manager.default.on(datatype).set(...params) : import_object_manager.default.on(datatype).set(defaultData);
281
+ if (beforeSetData(diff(import_object_manager.default.on(before), after), target)) {
282
+ target[key](...params);
283
+ }
262
284
  } else {
263
285
  target[key](...params);
264
286
  }
@@ -269,21 +291,25 @@ var ReactiveView_default = {
269
291
  }
270
292
  }
271
293
  });
272
- const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, isValid } });
294
+ const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, dataPath: dataPath2, isValid } });
295
+ if (props.debug) {
296
+ console.log("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
297
+ }
273
298
  const watchDataProp = (dataProp) => {
274
- var _a2, _b2, _c2;
299
+ var _a2, _b2, _c2, _d2;
275
300
  const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
276
301
  callback: (_b2 = ((_a2 = context.attrs["onUpdate:data"]) != null ? _a2 : {}).callback) != null ? _b2 : context.attrs["data:callback"],
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)
302
+ options: Object.assign(__spreadValues(__spreadValues({
303
+ deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true
304
+ }, context.attrs["data:immediate"] ? { immediate: context.attrs["data:immediate"] } : {}), context.attrs["data:once"] ? { once: context.attrs["data:once"] } : {}), ((_d2 = context.attrs["onUpdate:data"]) != null ? _d2 : {}).options)
278
305
  };
279
306
  if (context.attrs["data:log"]) {
280
307
  console.log(`[ReactiveView]:data`, { config: config2, dataProp });
281
308
  }
282
309
  (0, import_vue.watch)(isFunctionData || (0, import_vue.isRef)(dataProp) || (0, import_vue.isReactive)(dataProp) ? dataProp : () => dataProp, (after, before) => {
283
310
  var _a3;
284
- const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
285
311
  if (typeof config2.callback === "function") {
286
- model.replaceData((_a3 = config2.callback(diff, { component })) != null ? _a3 : after);
312
+ model.replaceData((_a3 = config2.callback(diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component })) != null ? _a3 : after);
287
313
  } else {
288
314
  model.replaceData(after);
289
315
  }
@@ -292,14 +318,15 @@ var ReactiveView_default = {
292
318
  if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
293
319
  const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
294
320
  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 : {};
321
+ options: Object.assign(__spreadValues(__spreadValues({
322
+ deep: (_g = context.attrs["model:deep"]) != null ? _g : true
323
+ }, 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)
324
+ } : (_i = context.attrs["onUpdate:model"]) != null ? _i : {};
297
325
  if (context.attrs["model:log"]) {
298
326
  console.log(`[ReactiveView]:model`, { config: config2 });
299
327
  }
300
328
  (0, import_vue.watch)(() => model.getData(), (after, before) => {
301
- const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
302
- config2.callback(diff, { component });
329
+ config2.callback(diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component });
303
330
  }, config2.options);
304
331
  }
305
332
  setTimeout(async () => {
@@ -342,6 +369,7 @@ var ReactiveView_default = {
342
369
  // src/index.ts
343
370
  var import_vue2 = require("vue");
344
371
  var import_date_fns_tz = require("date-fns-tz");
372
+ var import_tailwind_merge = require("tailwind-merge");
345
373
  var index_default = ReactiveView_default;
346
374
  function safeRequest(request) {
347
375
  return new Promise(async (resolve) => {
@@ -371,7 +399,7 @@ function safeRequest(request) {
371
399
  }
372
400
  });
373
401
  }
374
- function getProps(props, param2) {
402
+ function getProps(props = {}, param2) {
375
403
  var _a;
376
404
  const exclude = Array.isArray(param2) || typeof param2 === "string" ? param2 : param2.exclude;
377
405
  const exclusions = (Array.isArray(exclude) ? exclude : [exclude]).join("|");
@@ -416,7 +444,7 @@ function getDate(param1, param2) {
416
444
  }
417
445
  function access(view = {}, alternative) {
418
446
  const resolve = (target) => {
419
- return new Proxy(target, {
447
+ return new Proxy((0, import_vue2.toRaw)(target), {
420
448
  get(target2, key) {
421
449
  const component = { tree: target2 };
422
450
  do {
@@ -523,36 +551,47 @@ var extendVnode = (component, element) => {
523
551
  return (props = {}, slots) => {
524
552
  var _a;
525
553
  const _b = getProps((_a = vnode.props) != null ? _a : {}, []), { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
526
- const finalClasses = MergeStyles(classes, typeof props.class === "function" ? props.class(classes) : props.class);
554
+ const finalClasses = (0, import_tailwind_merge.twMerge)(MergeStyles(classes).string, MergeStyles(typeof props.class === "function" ? props.class(classes) : props.class).string);
555
+ const finalStyles = MergeStyles(styles, typeof props.style === "function" ? props.style(styles) : props.style);
527
556
  const functionalProps = Object.entries(props).reduce((props2, [key2, value]) => {
528
- if (![
529
- "class"
530
- /*, "style"*/
531
- ].includes(key2) && typeof value === "function") {
532
- props2[key2] = value(vnode.props[key2]);
557
+ var _a2;
558
+ if (!["class", "style"].includes(key2) && typeof value === "function") {
559
+ props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
533
560
  }
534
561
  return props2;
535
562
  }, props);
536
- const finalProps = Object.assign(rest, functionalProps, {
537
- class: finalClasses
538
- /*, style: finalStyles*/
539
- });
540
- const finalSlots = typeof slots === "function" ? slots(vnode.children) : vnode.children;
541
- return (0, import_vue2.h)(["string", "undefined"].includes(typeof element) ? vnode : element, finalProps, finalSlots);
563
+ const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
564
+ const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
565
+ return (0, import_vue2.h)(["undefined"].includes(typeof element) ? vnode.type : element, finalProps, finalSlots);
542
566
  };
543
567
  }
544
568
  });
545
569
  };
570
+ var getData = (component, path, alternative) => {
571
+ return import_object_manager2.default.on((0, import_vue2.unref)(component.state)).get(dataPath(component, path), alternative);
572
+ };
573
+ var setData = (component, data, path) => {
574
+ return component.$emit("update:state", {
575
+ before: import_object_manager2.default.on((0, import_vue2.unref)(component.state)).clone(),
576
+ after: path ? import_object_manager2.default.on({}).set(dataPath(component, path), data).get() : data
577
+ });
578
+ };
579
+ var dataPath = (component, path) => {
580
+ return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
581
+ };
546
582
  // Annotate the CommonJS export names for ESM import in node:
547
583
  0 && (module.exports = {
548
584
  MergeStyles,
549
585
  StyleParser,
550
586
  access,
587
+ dataPath,
551
588
  extendVnode,
589
+ getData,
552
590
  getDate,
553
591
  getProps,
554
592
  getReactiveViewComponent,
555
593
  safeRequest,
594
+ setData,
556
595
  setup,
557
596
  useSubscription
558
597
  });
package/dist/index.mjs CHANGED
@@ -27,6 +27,9 @@ var __objRest = (source, exclude) => {
27
27
  return target;
28
28
  };
29
29
 
30
+ // src/index.ts
31
+ import ObjectManager2 from "@razaman2/object-manager";
32
+
30
33
  // src/Subscription.ts
31
34
  var Subscription = class _Subscription {
32
35
  constructor() {
@@ -125,7 +128,7 @@ import { ref, reactive, watch, isRef, isReactive, createVNode, getCurrentInstanc
125
128
 
126
129
  // package.json
127
130
  var name = "@razaman2/reactive-view";
128
- var version = "0.0.34-beta.1";
131
+ var version = "0.0.34-beta.10";
129
132
 
130
133
  // src/ReactiveView.ts
131
134
  var setup = {
@@ -146,7 +149,9 @@ var ReactiveView_default = {
146
149
  notifications: Object,
147
150
  subscriptions: Object,
148
151
  beforeSetData: Function,
149
- data: {},
152
+ data: {
153
+ default: () => ({})
154
+ },
150
155
  defaultData: {},
151
156
  getDefaultData: {
152
157
  type: Function,
@@ -166,10 +171,27 @@ var ReactiveView_default = {
166
171
  debug: {
167
172
  type: Boolean,
168
173
  default: false
169
- }
174
+ },
175
+ state: {}
170
176
  },
171
177
  setup(props, context) {
172
- var _a, _b, _c, _d, _e, _f, _g, _h;
178
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
179
+ const diff = (before, after) => {
180
+ const change = after.paths().reduce((change2, path) => {
181
+ if (before.get(path) !== after.get(path)) {
182
+ change2.set(path, after.get(path));
183
+ }
184
+ return change2;
185
+ }, ObjectManager.on({}));
186
+ return { before: before.get(), after: after.get(), change: change.get() };
187
+ };
188
+ const dataPath2 = (path) => {
189
+ try {
190
+ return context.attrs["data:path"](path);
191
+ } catch (e) {
192
+ return path;
193
+ }
194
+ };
173
195
  const template = (component2, vue2) => {
174
196
  return createVNode(
175
197
  "div",
@@ -181,14 +203,11 @@ var ReactiveView_default = {
181
203
  };
182
204
  const isValid = ref(false);
183
205
  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;
206
+ const isFunctionData = ["Function"].includes((_a = props.data) == null ? void 0 : _a.constructor.name);
207
+ const isAsyncFunctionData = ["AsyncFunction"].includes((_b = props.data) == null ? void 0 : _b.constructor.name);
208
+ const isPromiseData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
187
209
  const defer = ref(typeof props.defer === "function" ? props.defer() : props.defer);
188
210
  const vue = getCurrentInstance();
189
- if (props.debug) {
190
- console.log("[ReactiveView]:", { props, context, vue, defer, data: props.data, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
191
- }
192
211
  if ((isPromiseData || isFunctionData) && !("defaultData" in vue.vnode.props)) {
193
212
  console.error("[ReactiveView]: defaultData is required for promise or async function data.");
194
213
  }
@@ -213,9 +232,11 @@ var ReactiveView_default = {
213
232
  var _a2;
214
233
  const beforeSetData = (_a2 = access(component).beforeSetData) != null ? _a2 : props.beforeSetData;
215
234
  if (typeof beforeSetData === "function") {
216
- const after = ObjectManager.on(datatype).set(...params.length ? params : [defaultData]).get();
217
235
  const before = target.getData();
218
- beforeSetData({ before, after }, target);
236
+ const after = params.length ? ObjectManager.on(datatype).set(...params) : ObjectManager.on(datatype).set(defaultData);
237
+ if (beforeSetData(diff(ObjectManager.on(before), after), target)) {
238
+ target[key](...params);
239
+ }
219
240
  } else {
220
241
  target[key](...params);
221
242
  }
@@ -226,21 +247,25 @@ var ReactiveView_default = {
226
247
  }
227
248
  }
228
249
  });
229
- const component = ref({ parent: { self: vue.proxy }, self: { template, model, isValid } });
250
+ const component = ref({ parent: { self: vue.proxy }, self: { template, model, dataPath: dataPath2, isValid } });
251
+ if (props.debug) {
252
+ console.log("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
253
+ }
230
254
  const watchDataProp = (dataProp) => {
231
- var _a2, _b2, _c2;
255
+ var _a2, _b2, _c2, _d2;
232
256
  const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
233
257
  callback: (_b2 = ((_a2 = context.attrs["onUpdate:data"]) != null ? _a2 : {}).callback) != null ? _b2 : context.attrs["data:callback"],
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)
258
+ options: Object.assign(__spreadValues(__spreadValues({
259
+ deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true
260
+ }, context.attrs["data:immediate"] ? { immediate: context.attrs["data:immediate"] } : {}), context.attrs["data:once"] ? { once: context.attrs["data:once"] } : {}), ((_d2 = context.attrs["onUpdate:data"]) != null ? _d2 : {}).options)
235
261
  };
236
262
  if (context.attrs["data:log"]) {
237
263
  console.log(`[ReactiveView]:data`, { config: config2, dataProp });
238
264
  }
239
265
  watch(isFunctionData || isRef(dataProp) || isReactive(dataProp) ? dataProp : () => dataProp, (after, before) => {
240
266
  var _a3;
241
- const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
242
267
  if (typeof config2.callback === "function") {
243
- model.replaceData((_a3 = config2.callback(diff, { component })) != null ? _a3 : after);
268
+ model.replaceData((_a3 = config2.callback(diff(ObjectManager.on(before), ObjectManager.on(after)), { component })) != null ? _a3 : after);
244
269
  } else {
245
270
  model.replaceData(after);
246
271
  }
@@ -249,14 +274,15 @@ var ReactiveView_default = {
249
274
  if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
250
275
  const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
251
276
  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 : {};
277
+ options: Object.assign(__spreadValues(__spreadValues({
278
+ deep: (_g = context.attrs["model:deep"]) != null ? _g : true
279
+ }, 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)
280
+ } : (_i = context.attrs["onUpdate:model"]) != null ? _i : {};
254
281
  if (context.attrs["model:log"]) {
255
282
  console.log(`[ReactiveView]:model`, { config: config2 });
256
283
  }
257
284
  watch(() => model.getData(), (after, before) => {
258
- const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
259
- config2.callback(diff, { component });
285
+ config2.callback(diff(ObjectManager.on(before), ObjectManager.on(after)), { component });
260
286
  }, config2.options);
261
287
  }
262
288
  setTimeout(async () => {
@@ -297,8 +323,9 @@ var ReactiveView_default = {
297
323
  };
298
324
 
299
325
  // src/index.ts
300
- import { createVNode as createVNode2, isRef as isRef2, h } from "vue";
326
+ import { h, unref as unref2, isRef as isRef2, toRaw, createVNode as createVNode2 } from "vue";
301
327
  import { formatInTimeZone } from "date-fns-tz";
328
+ import { twMerge } from "tailwind-merge";
302
329
  var index_default = ReactiveView_default;
303
330
  function safeRequest(request) {
304
331
  return new Promise(async (resolve) => {
@@ -328,7 +355,7 @@ function safeRequest(request) {
328
355
  }
329
356
  });
330
357
  }
331
- function getProps(props, param2) {
358
+ function getProps(props = {}, param2) {
332
359
  var _a;
333
360
  const exclude = Array.isArray(param2) || typeof param2 === "string" ? param2 : param2.exclude;
334
361
  const exclusions = (Array.isArray(exclude) ? exclude : [exclude]).join("|");
@@ -373,7 +400,7 @@ function getDate(param1, param2) {
373
400
  }
374
401
  function access(view = {}, alternative) {
375
402
  const resolve = (target) => {
376
- return new Proxy(target, {
403
+ return new Proxy(toRaw(target), {
377
404
  get(target2, key) {
378
405
  const component = { tree: target2 };
379
406
  do {
@@ -480,36 +507,47 @@ var extendVnode = (component, element) => {
480
507
  return (props = {}, slots) => {
481
508
  var _a;
482
509
  const _b = getProps((_a = vnode.props) != null ? _a : {}, []), { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
483
- const finalClasses = MergeStyles(classes, typeof props.class === "function" ? props.class(classes) : props.class);
510
+ const finalClasses = twMerge(MergeStyles(classes).string, MergeStyles(typeof props.class === "function" ? props.class(classes) : props.class).string);
511
+ const finalStyles = MergeStyles(styles, typeof props.style === "function" ? props.style(styles) : props.style);
484
512
  const functionalProps = Object.entries(props).reduce((props2, [key2, value]) => {
485
- if (![
486
- "class"
487
- /*, "style"*/
488
- ].includes(key2) && typeof value === "function") {
489
- props2[key2] = value(vnode.props[key2]);
513
+ var _a2;
514
+ if (!["class", "style"].includes(key2) && typeof value === "function") {
515
+ props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
490
516
  }
491
517
  return props2;
492
518
  }, props);
493
- const finalProps = Object.assign(rest, functionalProps, {
494
- class: finalClasses
495
- /*, style: finalStyles*/
496
- });
497
- const finalSlots = typeof slots === "function" ? slots(vnode.children) : vnode.children;
498
- return h(["string", "undefined"].includes(typeof element) ? vnode : element, finalProps, finalSlots);
519
+ const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
520
+ const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
521
+ return h(["undefined"].includes(typeof element) ? vnode.type : element, finalProps, finalSlots);
499
522
  };
500
523
  }
501
524
  });
502
525
  };
526
+ var getData = (component, path, alternative) => {
527
+ return ObjectManager2.on(unref2(component.state)).get(dataPath(component, path), alternative);
528
+ };
529
+ var setData = (component, data, path) => {
530
+ return component.$emit("update:state", {
531
+ before: ObjectManager2.on(unref2(component.state)).clone(),
532
+ after: path ? ObjectManager2.on({}).set(dataPath(component, path), data).get() : data
533
+ });
534
+ };
535
+ var dataPath = (component, path) => {
536
+ return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
537
+ };
503
538
  export {
504
539
  MergeStyles,
505
540
  StyleParser,
506
541
  access,
542
+ dataPath,
507
543
  index_default as default,
508
544
  extendVnode,
545
+ getData,
509
546
  getDate,
510
547
  getProps,
511
548
  getReactiveViewComponent,
512
549
  safeRequest,
550
+ setData,
513
551
  setup,
514
552
  useSubscription
515
553
  };
package/package.json CHANGED
@@ -1,46 +1,47 @@
1
- {
2
- "name": "@razaman2/reactive-view",
3
- "version": "0.0.34-beta.1",
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
- "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
- "types": "dist/index.d.ts",
8
- "scripts": {
9
- "prepublishOnly": "npm run build",
10
- "build": "tsup src/index.ts --format cjs,esm --dts",
11
- "lint": "tsc",
12
- "test": "cd tests/vue-ts && npm run dev"
13
- },
14
- "keywords": [
15
- "vue",
16
- "vue-helper",
17
- "reactive-view",
18
- "vue-class-component",
19
- "reactive-ui"
20
- ],
21
- "author": "razaman2",
22
- "license": "MIT",
23
- "dependencies": {
24
- "@razaman2/data-manager": "^3.2.12",
25
- "@razaman2/event-emitter": "^2.1.1",
26
- "@razaman2/object-manager": "^3.4.2",
27
- "date-fns": "^4.1.0",
28
- "date-fns-tz": "^3.2.0",
29
- "uuid": "^11.1.0"
30
- },
31
- "peerDependencies": {
32
- "vue": "^3.5.18"
33
- },
34
- "devDependencies": {
35
- "@types/uuid": "^10.0.0",
36
- "tsup": "^8.5.0",
37
- "typescript": "^5.9.2",
38
- "vitest": "^3.2.4"
39
- },
40
- "publishConfig": {
41
- "access": "public"
42
- },
43
- "files": [
44
- "dist"
45
- ]
46
- }
1
+ {
2
+ "name": "@razaman2/reactive-view",
3
+ "version": "0.0.34-beta.10",
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
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "prepublishOnly": "npm run build",
10
+ "build": "tsup src/index.ts --format cjs,esm --dts",
11
+ "lint": "tsc",
12
+ "test": "cd tests/vue-ts && npm run dev"
13
+ },
14
+ "keywords": [
15
+ "vue",
16
+ "vue-helper",
17
+ "reactive-view",
18
+ "vue-class-component",
19
+ "reactive-ui"
20
+ ],
21
+ "author": "razaman2",
22
+ "license": "MIT",
23
+ "dependencies": {
24
+ "@razaman2/data-manager": "^3.2.12",
25
+ "@razaman2/event-emitter": "^2.1.1",
26
+ "@razaman2/object-manager": "^3.4.5",
27
+ "date-fns": "^4.1.0",
28
+ "date-fns-tz": "^3.2.0",
29
+ "tailwind-merge": "^3.3.1",
30
+ "uuid": "^11.1.0"
31
+ },
32
+ "peerDependencies": {
33
+ "vue": "^3.5.20"
34
+ },
35
+ "devDependencies": {
36
+ "@types/uuid": "^10.0.0",
37
+ "tsup": "^8.5.0",
38
+ "typescript": "^5.9.2",
39
+ "vitest": "^3.2.4"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "files": [
45
+ "dist"
46
+ ]
47
+ }