@razaman2/reactive-view 0.0.34-beta.3 → 0.0.34-beta.30

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,5 +1,5 @@
1
1
  import * as vue from 'vue';
2
- import { SetupContext, ComponentPublicInstance, UnwrapRef } from 'vue';
2
+ import { SetupContext, ComponentPublicInstance, UnwrapRef, defineComponent } from 'vue';
3
3
 
4
4
  type ComponentExtension = {
5
5
  parent?: ComponentExtension;
@@ -43,6 +43,7 @@ declare const setup: {
43
43
  declare const _default: {
44
44
  props: {
45
45
  setup: {};
46
+ beta: BooleanConstructor;
46
47
  ReactiveView: {
47
48
  type: BooleanConstructor;
48
49
  default: boolean;
@@ -74,6 +75,9 @@ declare const _default: {
74
75
  type: BooleanConstructor;
75
76
  default: boolean;
76
77
  };
78
+ state: {
79
+ default: () => {};
80
+ };
77
81
  };
78
82
  setup(props: Record<string, any>, context: SetupContext): (vue: ComponentPublicInstance) => any;
79
83
  };
@@ -117,5 +121,17 @@ declare function useSubscription(): {
117
121
  declare function StyleParser(styles?: Array<string> | Record<string, boolean> | string): {};
118
122
  declare function MergeStyles(...params: any): any;
119
123
  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>;
124
+ declare function defineReactiveView(): ReturnType<typeof defineComponent>;
125
+ declare function defineReactiveView(options: Record<string, any>): ReturnType<typeof defineComponent>;
126
+ declare function defineReactiveView(options: Record<string, any>, component: typeof _default): ReturnType<typeof defineComponent>;
127
+ declare function showComponent(component: any, options?: {
128
+ container?: string;
129
+ key?: string;
130
+ router?: any;
131
+ plugins?: Array<any>;
132
+ }): any;
133
+ declare const getData: (component: any, path: number | string, alternative: any) => any;
134
+ declare const setData: (component: any, data: any, path?: string) => any;
135
+ declare const dataPath: (component: any, path: string | number) => any;
120
136
 
121
- export { MergeStyles, StyleParser, access, _default as default, extendVnode, getDate, getProps, getReactiveViewComponent, safeRequest, setup, useSubscription };
137
+ export { MergeStyles, StyleParser, access, dataPath, _default as default, defineReactiveView, extendVnode, getData, getDate, getProps, getReactiveViewComponent, safeRequest, setData, setup, showComponent, useSubscription };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as vue from 'vue';
2
- import { SetupContext, ComponentPublicInstance, UnwrapRef } from 'vue';
2
+ import { SetupContext, ComponentPublicInstance, UnwrapRef, defineComponent } from 'vue';
3
3
 
4
4
  type ComponentExtension = {
5
5
  parent?: ComponentExtension;
@@ -43,6 +43,7 @@ declare const setup: {
43
43
  declare const _default: {
44
44
  props: {
45
45
  setup: {};
46
+ beta: BooleanConstructor;
46
47
  ReactiveView: {
47
48
  type: BooleanConstructor;
48
49
  default: boolean;
@@ -74,6 +75,9 @@ declare const _default: {
74
75
  type: BooleanConstructor;
75
76
  default: boolean;
76
77
  };
78
+ state: {
79
+ default: () => {};
80
+ };
77
81
  };
78
82
  setup(props: Record<string, any>, context: SetupContext): (vue: ComponentPublicInstance) => any;
79
83
  };
@@ -117,5 +121,17 @@ declare function useSubscription(): {
117
121
  declare function StyleParser(styles?: Array<string> | Record<string, boolean> | string): {};
118
122
  declare function MergeStyles(...params: any): any;
119
123
  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>;
124
+ declare function defineReactiveView(): ReturnType<typeof defineComponent>;
125
+ declare function defineReactiveView(options: Record<string, any>): ReturnType<typeof defineComponent>;
126
+ declare function defineReactiveView(options: Record<string, any>, component: typeof _default): ReturnType<typeof defineComponent>;
127
+ declare function showComponent(component: any, options?: {
128
+ container?: string;
129
+ key?: string;
130
+ router?: any;
131
+ plugins?: Array<any>;
132
+ }): any;
133
+ declare const getData: (component: any, path: number | string, alternative: any) => any;
134
+ declare const setData: (component: any, data: any, path?: string) => any;
135
+ declare const dataPath: (component: any, path: string | number) => any;
120
136
 
121
- export { MergeStyles, StyleParser, access, _default as default, extendVnode, getDate, getProps, getReactiveViewComponent, safeRequest, setup, useSubscription };
137
+ export { MergeStyles, StyleParser, access, dataPath, _default as default, defineReactiveView, extendVnode, getData, getDate, getProps, getReactiveViewComponent, safeRequest, setData, setup, showComponent, useSubscription };
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
7
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
8
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
9
  var __getProtoOf = Object.getPrototypeOf;
@@ -19,6 +21,7 @@ var __spreadValues = (a, b) => {
19
21
  }
20
22
  return a;
21
23
  };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
25
  var __objRest = (source, exclude) => {
23
26
  var target = {};
24
27
  for (var prop in source)
@@ -59,16 +62,22 @@ __export(index_exports, {
59
62
  MergeStyles: () => MergeStyles,
60
63
  StyleParser: () => StyleParser,
61
64
  access: () => access,
65
+ dataPath: () => dataPath,
62
66
  default: () => index_default,
67
+ defineReactiveView: () => defineReactiveView,
63
68
  extendVnode: () => extendVnode,
69
+ getData: () => getData,
64
70
  getDate: () => getDate,
65
71
  getProps: () => getProps,
66
72
  getReactiveViewComponent: () => getReactiveViewComponent,
67
73
  safeRequest: () => safeRequest,
74
+ setData: () => setData,
68
75
  setup: () => setup,
76
+ showComponent: () => showComponent,
69
77
  useSubscription: () => useSubscription
70
78
  });
71
79
  module.exports = __toCommonJS(index_exports);
80
+ var import_object_manager2 = __toESM(require("@razaman2/object-manager"));
72
81
 
73
82
  // src/Subscription.ts
74
83
  var Subscription = class _Subscription {
@@ -168,7 +177,7 @@ var import_vue = require("vue");
168
177
 
169
178
  // package.json
170
179
  var name = "@razaman2/reactive-view";
171
- var version = "0.0.34-beta.3";
180
+ var version = "0.0.34-beta.30";
172
181
 
173
182
  // src/ReactiveView.ts
174
183
  var setup = {
@@ -179,19 +188,16 @@ var setup = {
179
188
  var ReactiveView_default = {
180
189
  props: {
181
190
  setup: {},
191
+ beta: Boolean,
182
192
  ReactiveView: {
183
193
  type: Boolean,
184
194
  default: true
185
195
  },
186
- instance: {
187
- default: () => (0, import_vue.ref)()
188
- },
196
+ instance: { default: () => (0, import_vue.ref)() },
189
197
  notifications: Object,
190
198
  subscriptions: Object,
191
199
  beforeSetData: Function,
192
- data: {
193
- default: () => ({})
194
- },
200
+ data: { default: () => (0, import_vue.reactive)({}) },
195
201
  defaultData: {},
196
202
  getDefaultData: {
197
203
  type: Function,
@@ -211,10 +217,27 @@ var ReactiveView_default = {
211
217
  debug: {
212
218
  type: Boolean,
213
219
  default: false
214
- }
220
+ },
221
+ state: { default: () => (0, import_vue.reactive)({}) }
215
222
  },
216
223
  setup(props, context) {
217
- var _a, _b, _c, _d, _e, _f;
224
+ var _a, _b, _c, _d, _e, _f, _g;
225
+ const diff = (before, after) => {
226
+ const change = after.paths().reduce((change2, path) => {
227
+ if (before.get(path) !== after.get(path)) {
228
+ change2.set(path, after.get(path));
229
+ }
230
+ return change2;
231
+ }, import_object_manager.default.on({}));
232
+ return { before: before.get(), after: after.get(), change: change.get() };
233
+ };
234
+ const dataPath2 = (path) => {
235
+ try {
236
+ return context.attrs["data:path"](path);
237
+ } catch (e) {
238
+ return path;
239
+ }
240
+ };
218
241
  const template = (component2, vue2) => {
219
242
  return (0, import_vue.createVNode)(
220
243
  "div",
@@ -226,38 +249,61 @@ var ReactiveView_default = {
226
249
  };
227
250
  const isValid = (0, import_vue.ref)(false);
228
251
  const isReady = (0, import_vue.ref)(false);
229
- const isFunctionData = ["Function"].includes(props.data.constructor.name);
230
- const isAsyncFunctionData = ["AsyncFunction"].includes(props.data.constructor.name);
231
- const isPromiseData = ["Promise"].includes(props.data.constructor.name) || isAsyncFunctionData;
252
+ const isFunctionData = ["Function"].includes((_a = props.data) == null ? void 0 : _a.constructor.name);
253
+ const isAsyncFunctionData = ["AsyncFunction"].includes((_b = props.data) == null ? void 0 : _b.constructor.name);
254
+ const isPromiseData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
232
255
  const defer = (0, import_vue.ref)(typeof props.defer === "function" ? props.defer() : props.defer);
233
256
  const vue = (0, import_vue.getCurrentInstance)();
234
- if ((isPromiseData || isFunctionData) && !("defaultData" in vue.vnode.props)) {
235
- console.error("[ReactiveView]: defaultData is required for promise or async function data.");
257
+ if ((isFunctionData || isPromiseData) && !("defaultData" in vue.vnode.props)) {
258
+ console.warn("[ReactiveView]: defaultData is required for promise or async function data.", props.data);
236
259
  }
237
260
  const defaultData = props.getDefaultData(
238
- ((_a = vue.vnode.props) == null ? void 0 : _a.hasOwnProperty("defaultData")) ? vue.vnode.props.defaultData : ((_b = vue.vnode.props) == null ? void 0 : _b.hasOwnProperty("data")) ? Array.isArray(vue.vnode.props.data) ? [] : {} : {}
261
+ "defaultData" in vue.vnode.props ? vue.vnode.props.defaultData : "data" in vue.vnode.props ? Array.isArray((0, import_vue.isRef)(vue.vnode.props.data) ? (0, import_vue.unref)(vue.vnode.props.data) : vue.vnode.props.data) ? [] : {} : {}
239
262
  );
240
263
  const datatype = Array.isArray(defaultData) ? [] : {};
264
+ const normalize = (data) => {
265
+ if (props.debug) {
266
+ console.warn(`[ReactiveView]: using beta props data in [${props.modelName}] component`, { vue, data, defaultData, isRef: (0, import_vue.isRef)(data), isReactive: (0, import_vue.isReactive)(data) });
267
+ }
268
+ if ((0, import_vue.isReactive)(data)) {
269
+ return data;
270
+ } else {
271
+ if ((0, import_vue.isRef)(data) || isFunctionData || isPromiseData) {
272
+ return (0, import_vue.reactive)(datatype);
273
+ } else {
274
+ const props2 = "data" in vue.vnode.props;
275
+ try {
276
+ if (["Array", "Object"].includes(data.constructor.name)) {
277
+ return (0, import_vue.reactive)(props2 ? data : datatype);
278
+ } else {
279
+ return (0, import_vue.reactive)(props2 ? { "": data } : datatype);
280
+ }
281
+ } catch (e) {
282
+ return (0, import_vue.reactive)(props2 ? { "": data } : datatype);
283
+ }
284
+ }
285
+ }
286
+ };
241
287
  const config = {
242
- data: (0, import_vue.reactive)(import_object_manager.default.on(
243
- isPromiseData || isFunctionData || (0, import_vue.isRef)(props.data) || (0, import_vue.isReactive)(props.data) ? datatype : ((_c = vue.vnode.props) == null ? void 0 : _c.hasOwnProperty("data")) ? props.data : datatype
288
+ data: props.beta ? normalize((_d = vue.vnode.props) == null ? void 0 : _d.data) : (0, import_vue.reactive)(import_object_manager.default.on(
289
+ isPromiseData || isFunctionData || (0, import_vue.isRef)(props.data) || (0, import_vue.isReactive)(props.data) ? datatype : "data" in vue.vnode.props ? props.data : datatype
244
290
  ).clone()),
245
291
  defaultData: import_object_manager.default.on(defaultData).clone(),
246
292
  notifications: props.notifications,
247
293
  subscriptions: props.subscriptions,
248
- logging: props.logging,
249
- name: props.modelName
294
+ name: props.modelName,
295
+ logging: props.logging
250
296
  };
251
297
  const model = new Proxy(props.model ? typeof props.model === "function" ? props.model(config) : props.model : new import_data_manager.default(config), {
252
298
  get(target, key, receiver) {
253
- if (key === "setData" || key === "replaceData") {
299
+ if (["setData", "replaceData"].includes(key.toString())) {
254
300
  return (...params) => {
255
301
  var _a2;
256
302
  const beforeSetData = (_a2 = access(component).beforeSetData) != null ? _a2 : props.beforeSetData;
257
303
  if (typeof beforeSetData === "function") {
258
- const before = target.getData();
259
- const after = (params.length ? import_object_manager.default.on(datatype).set(...params) : import_object_manager.default.on(datatype).set(defaultData)).get();
260
- if (beforeSetData({ before, after }, target)) {
304
+ const before = import_object_manager.default.on(target.getData());
305
+ const after = params.length ? import_object_manager.default.on(datatype).set(...params) : import_object_manager.default.on(datatype).set(defaultData);
306
+ if (beforeSetData(access(component).diff(before, after), target)) {
261
307
  target[key](...params);
262
308
  }
263
309
  } else {
@@ -270,24 +316,25 @@ var ReactiveView_default = {
270
316
  }
271
317
  }
272
318
  });
273
- const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, isValid } });
319
+ const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, diff, dataPath: dataPath2, isValid } });
274
320
  if (props.debug) {
275
- console.log("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
321
+ console.warn("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
276
322
  }
277
323
  const watchDataProp = (dataProp) => {
278
- var _a2, _b2, _c2;
324
+ var _a2, _b2, _c2, _d2;
279
325
  const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
280
326
  callback: (_b2 = ((_a2 = context.attrs["onUpdate:data"]) != null ? _a2 : {}).callback) != null ? _b2 : context.attrs["data:callback"],
281
- 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)
327
+ options: Object.assign(__spreadValues(__spreadValues({
328
+ deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true
329
+ }, 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)
282
330
  };
283
331
  if (context.attrs["data:log"]) {
284
- console.log(`[ReactiveView]:data`, { config: config2, dataProp });
332
+ console.warn(`[ReactiveView]:data`, { config: config2, dataProp });
285
333
  }
286
334
  (0, import_vue.watch)(isFunctionData || (0, import_vue.isRef)(dataProp) || (0, import_vue.isReactive)(dataProp) ? dataProp : () => dataProp, (after, before) => {
287
335
  var _a3;
288
- const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
289
336
  if (typeof config2.callback === "function") {
290
- model.replaceData((_a3 = config2.callback(diff, { component })) != null ? _a3 : after);
337
+ model.replaceData((_a3 = config2.callback(access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component })) != null ? _a3 : after);
291
338
  } else {
292
339
  model.replaceData(after);
293
340
  }
@@ -297,22 +344,53 @@ var ReactiveView_default = {
297
344
  const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
298
345
  callback: context.attrs["onUpdate:model"],
299
346
  options: Object.assign(__spreadValues(__spreadValues({
300
- deep: (_d = context.attrs["model:deep"]) != null ? _d : true
301
- }, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_e = context.attrs["onUpdate:model"]) != null ? _e : {}).options)
302
- } : (_f = context.attrs["onUpdate:model"]) != null ? _f : {};
347
+ deep: (_e = context.attrs["model:deep"]) != null ? _e : true
348
+ }, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_f = context.attrs["onUpdate:model"]) != null ? _f : {}).options)
349
+ } : (_g = context.attrs["onUpdate:model"]) != null ? _g : {};
303
350
  if (context.attrs["model:log"]) {
304
- console.log(`[ReactiveView]:model`, { config: config2 });
351
+ console.warn(`[ReactiveView]:model`, { config: config2 });
305
352
  }
306
- (0, import_vue.watch)(() => model.getData(), (after, before) => {
307
- const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
308
- config2.callback(diff, { component });
353
+ (0, import_vue.watch)(() => import_object_manager.default.on(model.getData()).clone(), (after, before) => {
354
+ config2.callback(access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component });
309
355
  }, config2.options);
310
356
  }
311
- setTimeout(async () => {
312
- var _a2;
313
- const [data] = await Promise.all([isAsyncFunctionData ? props.data() : props.data, (_a2 = defer.value) != null ? _a2 : true]);
314
- watchDataProp(data);
315
- });
357
+ if (props.beta) {
358
+ const isRefData = (0, import_vue.isRef)(props.data);
359
+ if (isRefData || isFunctionData || isPromiseData) {
360
+ setTimeout(async () => {
361
+ var _a2, _b2, _c2;
362
+ const [data] = isPromiseData ? await Promise.all([
363
+ isAsyncFunctionData ? props.data() : props.data,
364
+ (_a2 = defer.value) != null ? _a2 : true
365
+ ]) : [props.data];
366
+ (0, import_vue.watch)(isRefData ? data : isFunctionData ? data : typeof data === "function" ? data : () => data, (after, before) => {
367
+ var _a3;
368
+ if (before !== void 0 || after !== void 0) {
369
+ const callback = context.attrs["data:callback"];
370
+ if (typeof callback === "function") {
371
+ const diff2 = access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after));
372
+ model.replaceData((_a3 = callback(diff2, { component })) != null ? _a3 : after);
373
+ } else {
374
+ model.replaceData(after);
375
+ }
376
+ }
377
+ }, {
378
+ immediate: (_b2 = context.attrs["data:immediate"]) != null ? _b2 : true,
379
+ deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true,
380
+ once: context.attrs["data:once"]
381
+ });
382
+ });
383
+ }
384
+ } else {
385
+ setTimeout(async () => {
386
+ var _a2;
387
+ const [data] = await Promise.all([
388
+ isAsyncFunctionData ? props.data() : props.data,
389
+ (_a2 = defer.value) != null ? _a2 : true
390
+ ]);
391
+ watchDataProp(data);
392
+ });
393
+ }
316
394
  setTimeout(async () => {
317
395
  var _a2;
318
396
  isReady.value = (_a2 = await defer.value) != null ? _a2 : true;
@@ -348,6 +426,8 @@ var ReactiveView_default = {
348
426
  // src/index.ts
349
427
  var import_vue2 = require("vue");
350
428
  var import_date_fns_tz = require("date-fns-tz");
429
+ var import_tailwind_merge = require("tailwind-merge");
430
+ console.log(`%c[ReactiveView]: ${version}`, "background-color: red; color: yellow;");
351
431
  var index_default = ReactiveView_default;
352
432
  function safeRequest(request) {
353
433
  return new Promise(async (resolve) => {
@@ -377,7 +457,7 @@ function safeRequest(request) {
377
457
  }
378
458
  });
379
459
  }
380
- function getProps(props, param2) {
460
+ function getProps(props = {}, param2) {
381
461
  var _a;
382
462
  const exclude = Array.isArray(param2) || typeof param2 === "string" ? param2 : param2.exclude;
383
463
  const exclusions = (Array.isArray(exclude) ? exclude : [exclude]).join("|");
@@ -421,8 +501,9 @@ function getDate(param1, param2) {
421
501
  return (0, import_date_fns_tz.formatInTimeZone)(datetime(), options.timezone, options.format);
422
502
  }
423
503
  function access(view = {}, alternative) {
504
+ var _a;
424
505
  const resolve = (target) => {
425
- return new Proxy(target, {
506
+ return new Proxy((0, import_vue2.toRaw)(target), {
426
507
  get(target2, key) {
427
508
  const component = { tree: target2 };
428
509
  do {
@@ -443,9 +524,8 @@ function access(view = {}, alternative) {
443
524
  });
444
525
  };
445
526
  try {
446
- const component = typeof view === "function" ? view() : view;
447
- const ref2 = (0, import_vue2.isRef)(component) ? component.value : component;
448
- return resolve(ref2.ReactiveView ? access(ref2.instance) : ref2);
527
+ const component = (_a = (0, import_vue2.unref)(typeof view === "function" ? view() : view)) != null ? _a : {};
528
+ return resolve("instance" in component ? component.instance : component);
449
529
  } catch (e) {
450
530
  return resolve(view);
451
531
  }
@@ -528,37 +608,125 @@ var extendVnode = (component, element) => {
528
608
  const vnode = getVnode();
529
609
  return (props = {}, slots) => {
530
610
  var _a;
531
- const _b = getProps((_a = vnode.props) != null ? _a : {}, []), { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
532
- const finalClasses = MergeStyles(classes, typeof props.class === "function" ? props.class(classes) : props.class);
611
+ const isFunctionClass = typeof props.class === "function";
612
+ const isFunctionStyle = typeof props.style === "function";
613
+ const _b = (_a = vnode.props) != null ? _a : {}, { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
614
+ const finalClasses = (0, import_tailwind_merge.twMerge)(isFunctionClass ? "" : classes, MergeStyles(isFunctionClass ? props.class(classes) : props.class).string);
615
+ const finalStyles = MergeStyles(styles, isFunctionStyle ? props.style(styles) : props.style);
533
616
  const functionalProps = Object.entries(props).reduce((props2, [key2, value]) => {
534
- if (![
535
- "class"
536
- /*, "style"*/
537
- ].includes(key2) && typeof value === "function") {
538
- props2[key2] = value(vnode.props[key2]);
617
+ var _a2;
618
+ if (!["class", "style", "setup"].includes(key2) && typeof value === "function") {
619
+ props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
539
620
  }
540
621
  return props2;
541
622
  }, props);
542
- const finalProps = Object.assign(rest, functionalProps, {
543
- class: finalClasses
544
- /*, style: finalStyles*/
545
- });
546
- const finalSlots = typeof slots === "function" ? slots(vnode.children) : vnode.children;
547
- return (0, import_vue2.h)(["string", "undefined"].includes(typeof element) ? vnode : element, finalProps, finalSlots);
623
+ const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
624
+ const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
625
+ const finalElement = ["undefined"].includes(typeof element) ? vnode.type : element;
626
+ return (0, import_vue2.h)(finalElement, finalProps, finalSlots);
548
627
  };
549
628
  }
550
629
  });
551
630
  };
631
+ function defineReactiveView(param1, param2) {
632
+ const instance = (0, import_vue2.ref)();
633
+ return (0, import_vue2.defineComponent)({
634
+ name: param1 == null ? void 0 : param1.modelName,
635
+ props: __spreadValues({ setup }, param1 ? param1.props : {}),
636
+ setup() {
637
+ const _a = param1 != null ? param1 : {}, { setup: setup2, props } = _a, rest = __objRest(_a, ["setup", "props"]);
638
+ return (component) => {
639
+ const props2 = Object.entries(rest).reduce((props3, [key, val]) => {
640
+ return Object.assign(props3, { [key]: typeof val === "function" ? val(component, instance) : val });
641
+ }, {});
642
+ const slots = typeof (param1 == null ? void 0 : param1.slots) === "function" ? param1.slots(component) : Array.isArray(param1 == null ? void 0 : param1.slots) ? () => param1.slots : param1 == null ? void 0 : param1.slots;
643
+ return (0, import_vue2.createVNode)(param2 != null ? param2 : ReactiveView_default, __spreadProps(__spreadValues(__spreadValues({}, props2), Object.assign({}, props2, typeof setup2 === "function" ? {
644
+ setup: (self, parent) => setup2(self, parent, component)
645
+ } : {})), {
646
+ instance
647
+ }), slots);
648
+ };
649
+ }
650
+ });
651
+ }
652
+ function showComponent(component, options = {}) {
653
+ var _a;
654
+ if (options.router) {
655
+ console.warn("[ReactiveView]: Deprecated {router} option used with {showComponent()}. \nUse {plugins} option instead.");
656
+ }
657
+ if (!options.key || !document.getElementById(options.key)) {
658
+ const container = options.container || "app-dialogs";
659
+ const dialogs = document.getElementById(container) || document.createElement("div");
660
+ if (!dialogs.hasAttribute("id")) {
661
+ dialogs.setAttribute("id", container);
662
+ document.body.appendChild(dialogs);
663
+ }
664
+ const dialog = document.createElement("div");
665
+ const id = (_a = options.key) != null ? _a : `dialog_${dialogs.children.length + 1}`;
666
+ dialog.setAttribute("id", id);
667
+ dialogs.appendChild(dialog);
668
+ const app = (0, import_vue2.createApp)(
669
+ {
670
+ setup() {
671
+ return () => component;
672
+ }
673
+ },
674
+ {
675
+ __cleanup__: () => {
676
+ document.querySelectorAll(`#${id}`).forEach((element) => element.remove());
677
+ app.unmount();
678
+ }
679
+ }
680
+ );
681
+ if (options.router) {
682
+ return app.use(options.router).mount(`#${id}`);
683
+ } else if (options.plugins) {
684
+ return options.plugins.reduce((app2, plugin) => {
685
+ return app2.use(...Array.isArray(plugin) ? plugin : [plugin]);
686
+ }, app).mount(`#${id}`);
687
+ } else {
688
+ return app.mount(`#${id}`);
689
+ }
690
+ }
691
+ }
692
+ var getData = (component, path, alternative) => {
693
+ const vue = access(component);
694
+ const data = import_object_manager2.default.on(componentState(vue));
695
+ if (path) {
696
+ return data.get(dataPath(vue, path), alternative);
697
+ } else {
698
+ return data.get();
699
+ }
700
+ };
701
+ var setData = (component, data, path) => {
702
+ const vue = access(component);
703
+ const diff = {
704
+ before: import_object_manager2.default.on(componentState(vue)).clone(),
705
+ after: path ? import_object_manager2.default.on(componentState(vue)).set(dataPath(vue, path), data).get() : import_object_manager2.default.on(componentState(vue)).set(data).get()
706
+ };
707
+ return "state" in vue ? diff : vue.$emit("update:state", diff);
708
+ };
709
+ var componentState = (component) => {
710
+ return (0, import_vue2.unref)("state" in component ? component.state : component.$attrs.state);
711
+ };
712
+ var dataPath = (component, path) => {
713
+ return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
714
+ };
552
715
  // Annotate the CommonJS export names for ESM import in node:
553
716
  0 && (module.exports = {
554
717
  MergeStyles,
555
718
  StyleParser,
556
719
  access,
720
+ dataPath,
721
+ defineReactiveView,
557
722
  extendVnode,
723
+ getData,
558
724
  getDate,
559
725
  getProps,
560
726
  getReactiveViewComponent,
561
727
  safeRequest,
728
+ setData,
562
729
  setup,
730
+ showComponent,
563
731
  useSubscription
564
732
  });
package/dist/index.mjs CHANGED
@@ -1,4 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
2
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
4
6
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -14,6 +16,7 @@ var __spreadValues = (a, b) => {
14
16
  }
15
17
  return a;
16
18
  };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
17
20
  var __objRest = (source, exclude) => {
18
21
  var target = {};
19
22
  for (var prop in source)
@@ -27,6 +30,9 @@ var __objRest = (source, exclude) => {
27
30
  return target;
28
31
  };
29
32
 
33
+ // src/index.ts
34
+ import ObjectManager2 from "@razaman2/object-manager";
35
+
30
36
  // src/Subscription.ts
31
37
  var Subscription = class _Subscription {
32
38
  constructor() {
@@ -121,11 +127,11 @@ var Subscriptions = _Subscriptions;
121
127
  // src/ReactiveView.ts
122
128
  import ObjectManager from "@razaman2/object-manager";
123
129
  import DataManager from "@razaman2/data-manager";
124
- import { ref, reactive, watch, isRef, isReactive, createVNode, getCurrentInstance } from "vue";
130
+ import { ref, reactive, watch, isRef, isReactive, createVNode, getCurrentInstance, unref } from "vue";
125
131
 
126
132
  // package.json
127
133
  var name = "@razaman2/reactive-view";
128
- var version = "0.0.34-beta.3";
134
+ var version = "0.0.34-beta.30";
129
135
 
130
136
  // src/ReactiveView.ts
131
137
  var setup = {
@@ -136,19 +142,16 @@ var setup = {
136
142
  var ReactiveView_default = {
137
143
  props: {
138
144
  setup: {},
145
+ beta: Boolean,
139
146
  ReactiveView: {
140
147
  type: Boolean,
141
148
  default: true
142
149
  },
143
- instance: {
144
- default: () => ref()
145
- },
150
+ instance: { default: () => ref() },
146
151
  notifications: Object,
147
152
  subscriptions: Object,
148
153
  beforeSetData: Function,
149
- data: {
150
- default: () => ({})
151
- },
154
+ data: { default: () => reactive({}) },
152
155
  defaultData: {},
153
156
  getDefaultData: {
154
157
  type: Function,
@@ -168,10 +171,27 @@ var ReactiveView_default = {
168
171
  debug: {
169
172
  type: Boolean,
170
173
  default: false
171
- }
174
+ },
175
+ state: { default: () => reactive({}) }
172
176
  },
173
177
  setup(props, context) {
174
- var _a, _b, _c, _d, _e, _f;
178
+ var _a, _b, _c, _d, _e, _f, _g;
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
+ };
175
195
  const template = (component2, vue2) => {
176
196
  return createVNode(
177
197
  "div",
@@ -183,38 +203,61 @@ var ReactiveView_default = {
183
203
  };
184
204
  const isValid = ref(false);
185
205
  const isReady = ref(false);
186
- const isFunctionData = ["Function"].includes(props.data.constructor.name);
187
- const isAsyncFunctionData = ["AsyncFunction"].includes(props.data.constructor.name);
188
- const isPromiseData = ["Promise"].includes(props.data.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;
189
209
  const defer = ref(typeof props.defer === "function" ? props.defer() : props.defer);
190
210
  const vue = getCurrentInstance();
191
- if ((isPromiseData || isFunctionData) && !("defaultData" in vue.vnode.props)) {
192
- console.error("[ReactiveView]: defaultData is required for promise or async function data.");
211
+ if ((isFunctionData || isPromiseData) && !("defaultData" in vue.vnode.props)) {
212
+ console.warn("[ReactiveView]: defaultData is required for promise or async function data.", props.data);
193
213
  }
194
214
  const defaultData = props.getDefaultData(
195
- ((_a = vue.vnode.props) == null ? void 0 : _a.hasOwnProperty("defaultData")) ? vue.vnode.props.defaultData : ((_b = vue.vnode.props) == null ? void 0 : _b.hasOwnProperty("data")) ? Array.isArray(vue.vnode.props.data) ? [] : {} : {}
215
+ "defaultData" in vue.vnode.props ? vue.vnode.props.defaultData : "data" in vue.vnode.props ? Array.isArray(isRef(vue.vnode.props.data) ? unref(vue.vnode.props.data) : vue.vnode.props.data) ? [] : {} : {}
196
216
  );
197
217
  const datatype = Array.isArray(defaultData) ? [] : {};
218
+ const normalize = (data) => {
219
+ if (props.debug) {
220
+ console.warn(`[ReactiveView]: using beta props data in [${props.modelName}] component`, { vue, data, defaultData, isRef: isRef(data), isReactive: isReactive(data) });
221
+ }
222
+ if (isReactive(data)) {
223
+ return data;
224
+ } else {
225
+ if (isRef(data) || isFunctionData || isPromiseData) {
226
+ return reactive(datatype);
227
+ } else {
228
+ const props2 = "data" in vue.vnode.props;
229
+ try {
230
+ if (["Array", "Object"].includes(data.constructor.name)) {
231
+ return reactive(props2 ? data : datatype);
232
+ } else {
233
+ return reactive(props2 ? { "": data } : datatype);
234
+ }
235
+ } catch (e) {
236
+ return reactive(props2 ? { "": data } : datatype);
237
+ }
238
+ }
239
+ }
240
+ };
198
241
  const config = {
199
- data: reactive(ObjectManager.on(
200
- isPromiseData || isFunctionData || isRef(props.data) || isReactive(props.data) ? datatype : ((_c = vue.vnode.props) == null ? void 0 : _c.hasOwnProperty("data")) ? props.data : datatype
242
+ data: props.beta ? normalize((_d = vue.vnode.props) == null ? void 0 : _d.data) : reactive(ObjectManager.on(
243
+ isPromiseData || isFunctionData || isRef(props.data) || isReactive(props.data) ? datatype : "data" in vue.vnode.props ? props.data : datatype
201
244
  ).clone()),
202
245
  defaultData: ObjectManager.on(defaultData).clone(),
203
246
  notifications: props.notifications,
204
247
  subscriptions: props.subscriptions,
205
- logging: props.logging,
206
- name: props.modelName
248
+ name: props.modelName,
249
+ logging: props.logging
207
250
  };
208
251
  const model = new Proxy(props.model ? typeof props.model === "function" ? props.model(config) : props.model : new DataManager(config), {
209
252
  get(target, key, receiver) {
210
- if (key === "setData" || key === "replaceData") {
253
+ if (["setData", "replaceData"].includes(key.toString())) {
211
254
  return (...params) => {
212
255
  var _a2;
213
256
  const beforeSetData = (_a2 = access(component).beforeSetData) != null ? _a2 : props.beforeSetData;
214
257
  if (typeof beforeSetData === "function") {
215
- const before = target.getData();
216
- const after = (params.length ? ObjectManager.on(datatype).set(...params) : ObjectManager.on(datatype).set(defaultData)).get();
217
- if (beforeSetData({ before, after }, target)) {
258
+ const before = ObjectManager.on(target.getData());
259
+ const after = params.length ? ObjectManager.on(datatype).set(...params) : ObjectManager.on(datatype).set(defaultData);
260
+ if (beforeSetData(access(component).diff(before, after), target)) {
218
261
  target[key](...params);
219
262
  }
220
263
  } else {
@@ -227,24 +270,25 @@ var ReactiveView_default = {
227
270
  }
228
271
  }
229
272
  });
230
- const component = ref({ parent: { self: vue.proxy }, self: { template, model, isValid } });
273
+ const component = ref({ parent: { self: vue.proxy }, self: { template, model, diff, dataPath: dataPath2, isValid } });
231
274
  if (props.debug) {
232
- console.log("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
275
+ console.warn("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
233
276
  }
234
277
  const watchDataProp = (dataProp) => {
235
- var _a2, _b2, _c2;
278
+ var _a2, _b2, _c2, _d2;
236
279
  const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
237
280
  callback: (_b2 = ((_a2 = context.attrs["onUpdate:data"]) != null ? _a2 : {}).callback) != null ? _b2 : context.attrs["data:callback"],
238
- 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)
281
+ options: Object.assign(__spreadValues(__spreadValues({
282
+ deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true
283
+ }, 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)
239
284
  };
240
285
  if (context.attrs["data:log"]) {
241
- console.log(`[ReactiveView]:data`, { config: config2, dataProp });
286
+ console.warn(`[ReactiveView]:data`, { config: config2, dataProp });
242
287
  }
243
288
  watch(isFunctionData || isRef(dataProp) || isReactive(dataProp) ? dataProp : () => dataProp, (after, before) => {
244
289
  var _a3;
245
- const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
246
290
  if (typeof config2.callback === "function") {
247
- model.replaceData((_a3 = config2.callback(diff, { component })) != null ? _a3 : after);
291
+ model.replaceData((_a3 = config2.callback(access(component).diff(ObjectManager.on(before), ObjectManager.on(after)), { component })) != null ? _a3 : after);
248
292
  } else {
249
293
  model.replaceData(after);
250
294
  }
@@ -254,22 +298,53 @@ var ReactiveView_default = {
254
298
  const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
255
299
  callback: context.attrs["onUpdate:model"],
256
300
  options: Object.assign(__spreadValues(__spreadValues({
257
- deep: (_d = context.attrs["model:deep"]) != null ? _d : true
258
- }, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_e = context.attrs["onUpdate:model"]) != null ? _e : {}).options)
259
- } : (_f = context.attrs["onUpdate:model"]) != null ? _f : {};
301
+ deep: (_e = context.attrs["model:deep"]) != null ? _e : true
302
+ }, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_f = context.attrs["onUpdate:model"]) != null ? _f : {}).options)
303
+ } : (_g = context.attrs["onUpdate:model"]) != null ? _g : {};
260
304
  if (context.attrs["model:log"]) {
261
- console.log(`[ReactiveView]:model`, { config: config2 });
305
+ console.warn(`[ReactiveView]:model`, { config: config2 });
262
306
  }
263
- watch(() => model.getData(), (after, before) => {
264
- const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
265
- config2.callback(diff, { component });
307
+ watch(() => ObjectManager.on(model.getData()).clone(), (after, before) => {
308
+ config2.callback(access(component).diff(ObjectManager.on(before), ObjectManager.on(after)), { component });
266
309
  }, config2.options);
267
310
  }
268
- setTimeout(async () => {
269
- var _a2;
270
- const [data] = await Promise.all([isAsyncFunctionData ? props.data() : props.data, (_a2 = defer.value) != null ? _a2 : true]);
271
- watchDataProp(data);
272
- });
311
+ if (props.beta) {
312
+ const isRefData = isRef(props.data);
313
+ if (isRefData || isFunctionData || isPromiseData) {
314
+ setTimeout(async () => {
315
+ var _a2, _b2, _c2;
316
+ const [data] = isPromiseData ? await Promise.all([
317
+ isAsyncFunctionData ? props.data() : props.data,
318
+ (_a2 = defer.value) != null ? _a2 : true
319
+ ]) : [props.data];
320
+ watch(isRefData ? data : isFunctionData ? data : typeof data === "function" ? data : () => data, (after, before) => {
321
+ var _a3;
322
+ if (before !== void 0 || after !== void 0) {
323
+ const callback = context.attrs["data:callback"];
324
+ if (typeof callback === "function") {
325
+ const diff2 = access(component).diff(ObjectManager.on(before), ObjectManager.on(after));
326
+ model.replaceData((_a3 = callback(diff2, { component })) != null ? _a3 : after);
327
+ } else {
328
+ model.replaceData(after);
329
+ }
330
+ }
331
+ }, {
332
+ immediate: (_b2 = context.attrs["data:immediate"]) != null ? _b2 : true,
333
+ deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true,
334
+ once: context.attrs["data:once"]
335
+ });
336
+ });
337
+ }
338
+ } else {
339
+ setTimeout(async () => {
340
+ var _a2;
341
+ const [data] = await Promise.all([
342
+ isAsyncFunctionData ? props.data() : props.data,
343
+ (_a2 = defer.value) != null ? _a2 : true
344
+ ]);
345
+ watchDataProp(data);
346
+ });
347
+ }
273
348
  setTimeout(async () => {
274
349
  var _a2;
275
350
  isReady.value = (_a2 = await defer.value) != null ? _a2 : true;
@@ -303,8 +378,10 @@ var ReactiveView_default = {
303
378
  };
304
379
 
305
380
  // src/index.ts
306
- import { createVNode as createVNode2, isRef as isRef2, h } from "vue";
381
+ import { h, ref as ref2, unref as unref2, toRaw, createApp, createVNode as createVNode2, defineComponent } from "vue";
307
382
  import { formatInTimeZone } from "date-fns-tz";
383
+ import { twMerge } from "tailwind-merge";
384
+ console.log(`%c[ReactiveView]: ${version}`, "background-color: red; color: yellow;");
308
385
  var index_default = ReactiveView_default;
309
386
  function safeRequest(request) {
310
387
  return new Promise(async (resolve) => {
@@ -334,7 +411,7 @@ function safeRequest(request) {
334
411
  }
335
412
  });
336
413
  }
337
- function getProps(props, param2) {
414
+ function getProps(props = {}, param2) {
338
415
  var _a;
339
416
  const exclude = Array.isArray(param2) || typeof param2 === "string" ? param2 : param2.exclude;
340
417
  const exclusions = (Array.isArray(exclude) ? exclude : [exclude]).join("|");
@@ -378,8 +455,9 @@ function getDate(param1, param2) {
378
455
  return formatInTimeZone(datetime(), options.timezone, options.format);
379
456
  }
380
457
  function access(view = {}, alternative) {
458
+ var _a;
381
459
  const resolve = (target) => {
382
- return new Proxy(target, {
460
+ return new Proxy(toRaw(target), {
383
461
  get(target2, key) {
384
462
  const component = { tree: target2 };
385
463
  do {
@@ -400,9 +478,8 @@ function access(view = {}, alternative) {
400
478
  });
401
479
  };
402
480
  try {
403
- const component = typeof view === "function" ? view() : view;
404
- const ref2 = isRef2(component) ? component.value : component;
405
- return resolve(ref2.ReactiveView ? access(ref2.instance) : ref2);
481
+ const component = (_a = unref2(typeof view === "function" ? view() : view)) != null ? _a : {};
482
+ return resolve("instance" in component ? component.instance : component);
406
483
  } catch (e) {
407
484
  return resolve(view);
408
485
  }
@@ -485,37 +562,125 @@ var extendVnode = (component, element) => {
485
562
  const vnode = getVnode();
486
563
  return (props = {}, slots) => {
487
564
  var _a;
488
- const _b = getProps((_a = vnode.props) != null ? _a : {}, []), { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
489
- const finalClasses = MergeStyles(classes, typeof props.class === "function" ? props.class(classes) : props.class);
565
+ const isFunctionClass = typeof props.class === "function";
566
+ const isFunctionStyle = typeof props.style === "function";
567
+ const _b = (_a = vnode.props) != null ? _a : {}, { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
568
+ const finalClasses = twMerge(isFunctionClass ? "" : classes, MergeStyles(isFunctionClass ? props.class(classes) : props.class).string);
569
+ const finalStyles = MergeStyles(styles, isFunctionStyle ? props.style(styles) : props.style);
490
570
  const functionalProps = Object.entries(props).reduce((props2, [key2, value]) => {
491
- if (![
492
- "class"
493
- /*, "style"*/
494
- ].includes(key2) && typeof value === "function") {
495
- props2[key2] = value(vnode.props[key2]);
571
+ var _a2;
572
+ if (!["class", "style", "setup"].includes(key2) && typeof value === "function") {
573
+ props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
496
574
  }
497
575
  return props2;
498
576
  }, props);
499
- const finalProps = Object.assign(rest, functionalProps, {
500
- class: finalClasses
501
- /*, style: finalStyles*/
502
- });
503
- const finalSlots = typeof slots === "function" ? slots(vnode.children) : vnode.children;
504
- return h(["string", "undefined"].includes(typeof element) ? vnode : element, finalProps, finalSlots);
577
+ const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
578
+ const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
579
+ const finalElement = ["undefined"].includes(typeof element) ? vnode.type : element;
580
+ return h(finalElement, finalProps, finalSlots);
505
581
  };
506
582
  }
507
583
  });
508
584
  };
585
+ function defineReactiveView(param1, param2) {
586
+ const instance = ref2();
587
+ return defineComponent({
588
+ name: param1 == null ? void 0 : param1.modelName,
589
+ props: __spreadValues({ setup }, param1 ? param1.props : {}),
590
+ setup() {
591
+ const _a = param1 != null ? param1 : {}, { setup: setup2, props } = _a, rest = __objRest(_a, ["setup", "props"]);
592
+ return (component) => {
593
+ const props2 = Object.entries(rest).reduce((props3, [key, val]) => {
594
+ return Object.assign(props3, { [key]: typeof val === "function" ? val(component, instance) : val });
595
+ }, {});
596
+ const slots = typeof (param1 == null ? void 0 : param1.slots) === "function" ? param1.slots(component) : Array.isArray(param1 == null ? void 0 : param1.slots) ? () => param1.slots : param1 == null ? void 0 : param1.slots;
597
+ return createVNode2(param2 != null ? param2 : ReactiveView_default, __spreadProps(__spreadValues(__spreadValues({}, props2), Object.assign({}, props2, typeof setup2 === "function" ? {
598
+ setup: (self, parent) => setup2(self, parent, component)
599
+ } : {})), {
600
+ instance
601
+ }), slots);
602
+ };
603
+ }
604
+ });
605
+ }
606
+ function showComponent(component, options = {}) {
607
+ var _a;
608
+ if (options.router) {
609
+ console.warn("[ReactiveView]: Deprecated {router} option used with {showComponent()}. \nUse {plugins} option instead.");
610
+ }
611
+ if (!options.key || !document.getElementById(options.key)) {
612
+ const container = options.container || "app-dialogs";
613
+ const dialogs = document.getElementById(container) || document.createElement("div");
614
+ if (!dialogs.hasAttribute("id")) {
615
+ dialogs.setAttribute("id", container);
616
+ document.body.appendChild(dialogs);
617
+ }
618
+ const dialog = document.createElement("div");
619
+ const id = (_a = options.key) != null ? _a : `dialog_${dialogs.children.length + 1}`;
620
+ dialog.setAttribute("id", id);
621
+ dialogs.appendChild(dialog);
622
+ const app = createApp(
623
+ {
624
+ setup() {
625
+ return () => component;
626
+ }
627
+ },
628
+ {
629
+ __cleanup__: () => {
630
+ document.querySelectorAll(`#${id}`).forEach((element) => element.remove());
631
+ app.unmount();
632
+ }
633
+ }
634
+ );
635
+ if (options.router) {
636
+ return app.use(options.router).mount(`#${id}`);
637
+ } else if (options.plugins) {
638
+ return options.plugins.reduce((app2, plugin) => {
639
+ return app2.use(...Array.isArray(plugin) ? plugin : [plugin]);
640
+ }, app).mount(`#${id}`);
641
+ } else {
642
+ return app.mount(`#${id}`);
643
+ }
644
+ }
645
+ }
646
+ var getData = (component, path, alternative) => {
647
+ const vue = access(component);
648
+ const data = ObjectManager2.on(componentState(vue));
649
+ if (path) {
650
+ return data.get(dataPath(vue, path), alternative);
651
+ } else {
652
+ return data.get();
653
+ }
654
+ };
655
+ var setData = (component, data, path) => {
656
+ const vue = access(component);
657
+ const diff = {
658
+ before: ObjectManager2.on(componentState(vue)).clone(),
659
+ after: path ? ObjectManager2.on(componentState(vue)).set(dataPath(vue, path), data).get() : ObjectManager2.on(componentState(vue)).set(data).get()
660
+ };
661
+ return "state" in vue ? diff : vue.$emit("update:state", diff);
662
+ };
663
+ var componentState = (component) => {
664
+ return unref2("state" in component ? component.state : component.$attrs.state);
665
+ };
666
+ var dataPath = (component, path) => {
667
+ return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
668
+ };
509
669
  export {
510
670
  MergeStyles,
511
671
  StyleParser,
512
672
  access,
673
+ dataPath,
513
674
  index_default as default,
675
+ defineReactiveView,
514
676
  extendVnode,
677
+ getData,
515
678
  getDate,
516
679
  getProps,
517
680
  getReactiveViewComponent,
518
681
  safeRequest,
682
+ setData,
519
683
  setup,
684
+ showComponent,
520
685
  useSubscription
521
686
  };
package/package.json CHANGED
@@ -1,46 +1,48 @@
1
- {
2
- "name": "@razaman2/reactive-view",
3
- "version": "0.0.34-beta.3",
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.19"
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.30",
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
+ "pr": "sh pr.sh"
14
+ },
15
+ "keywords": [
16
+ "vue",
17
+ "vue-helper",
18
+ "reactive-view",
19
+ "vue-class-component",
20
+ "reactive-ui"
21
+ ],
22
+ "author": "razaman2",
23
+ "license": "MIT",
24
+ "dependencies": {
25
+ "@razaman2/data-manager": "^3.2.12",
26
+ "@razaman2/event-emitter": "^2.1.1",
27
+ "@razaman2/object-manager": "^3.4.7",
28
+ "date-fns": "^4.1.0",
29
+ "date-fns-tz": "^3.2.0",
30
+ "tailwind-merge": "^3.3.1",
31
+ "uuid": "^13.0.0"
32
+ },
33
+ "peerDependencies": {
34
+ "vue": ">=3.0.0"
35
+ },
36
+ "devDependencies": {
37
+ "@types/uuid": "^11.0.0",
38
+ "tsup": "^8.5.0",
39
+ "typescript": "^5.9.3",
40
+ "vitest": "^4.0.5"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "files": [
46
+ "dist"
47
+ ]
48
+ }