@razaman2/reactive-view 0.0.34-beta.9 → 0.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.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)
@@ -61,6 +64,7 @@ __export(index_exports, {
61
64
  access: () => access,
62
65
  dataPath: () => dataPath,
63
66
  default: () => index_default,
67
+ defineReactiveView: () => defineReactiveView,
64
68
  extendVnode: () => extendVnode,
65
69
  getData: () => getData,
66
70
  getDate: () => getDate,
@@ -69,6 +73,7 @@ __export(index_exports, {
69
73
  safeRequest: () => safeRequest,
70
74
  setData: () => setData,
71
75
  setup: () => setup,
76
+ showComponent: () => showComponent,
72
77
  useSubscription: () => useSubscription
73
78
  });
74
79
  module.exports = __toCommonJS(index_exports);
@@ -172,7 +177,7 @@ var import_vue = require("vue");
172
177
 
173
178
  // package.json
174
179
  var name = "@razaman2/reactive-view";
175
- var version = "0.0.34-beta.9";
180
+ var version = "0.1.0-beta.1";
176
181
 
177
182
  // src/ReactiveView.ts
178
183
  var setup = {
@@ -183,19 +188,16 @@ var setup = {
183
188
  var ReactiveView_default = {
184
189
  props: {
185
190
  setup: {},
191
+ beta: [Boolean, String],
186
192
  ReactiveView: {
187
193
  type: Boolean,
188
194
  default: true
189
195
  },
190
- instance: {
191
- default: () => (0, import_vue.ref)()
192
- },
196
+ instance: { default: (0, import_vue.ref)() },
193
197
  notifications: Object,
194
198
  subscriptions: Object,
195
199
  beforeSetData: Function,
196
- data: {
197
- default: () => ({})
198
- },
200
+ data: { default: (0, import_vue.reactive)({}) },
199
201
  defaultData: {},
200
202
  getDefaultData: {
201
203
  type: Function,
@@ -216,18 +218,21 @@ var ReactiveView_default = {
216
218
  type: Boolean,
217
219
  default: false
218
220
  },
219
- state: {}
221
+ state: { default: (0, import_vue.reactive)({}) }
220
222
  },
221
223
  setup(props, context) {
222
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
224
+ var _a, _b, _c;
223
225
  const diff = (before, after) => {
224
- const change = after.paths().reduce((change2, path) => {
226
+ const paths = Array.from(new Set(before.paths().concat(after.paths())));
227
+ let changed = false;
228
+ const change = paths.reduce((change2, path) => {
225
229
  if (before.get(path) !== after.get(path)) {
226
230
  change2.set(path, after.get(path));
231
+ changed = true;
227
232
  }
228
233
  return change2;
229
234
  }, import_object_manager.default.on({}));
230
- return { before: before.get(), after: after.get(), change: change.get() };
235
+ return { before: before.get(), after: after.get(), changes: change.get(), changed };
231
236
  };
232
237
  const dataPath2 = (path) => {
233
238
  try {
@@ -236,133 +241,340 @@ var ReactiveView_default = {
236
241
  return path;
237
242
  }
238
243
  };
239
- const template = (component2, vue2) => {
240
- return (0, import_vue.createVNode)(
241
- "div",
242
- context.slots.default ? context.attrs : __spreadValues({
243
- style: { color: "red", textAlign: "center" }
244
- }, context.attrs),
245
- context.slots.default ? context.slots.default({ component: component2, vue: vue2, props, context }) : `${props.modelName}: ${name}@${version}`
246
- );
244
+ const template = (component, vue2) => {
245
+ return (0, import_vue.createVNode)("div", context.slots.default ? context.attrs : __spreadValues({
246
+ style: { color: "red", textAlign: "center" }
247
+ }, context.attrs), context.slots.default ? context.slots.default({ component, vue: vue2, props, context }) : `${props.modelName}: ${name}@${version}`);
247
248
  };
248
249
  const isValid = (0, import_vue.ref)(false);
249
250
  const isReady = (0, import_vue.ref)(false);
251
+ const defer = (0, import_vue.ref)(typeof props.defer === "function" ? props.defer() : props.defer);
250
252
  const isFunctionData = ["Function"].includes((_a = props.data) == null ? void 0 : _a.constructor.name);
251
253
  const isAsyncFunctionData = ["AsyncFunction"].includes((_b = props.data) == null ? void 0 : _b.constructor.name);
252
254
  const isPromiseData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
253
- const defer = (0, import_vue.ref)(typeof props.defer === "function" ? props.defer() : props.defer);
254
255
  const vue = (0, import_vue.getCurrentInstance)();
255
- if ((isPromiseData || isFunctionData) && !("defaultData" in vue.vnode.props)) {
256
- console.error("[ReactiveView]: defaultData is required for promise or async function data.");
256
+ if ((isFunctionData || isPromiseData) && !("defaultData" in vue.vnode.props)) {
257
+ console.warn(`${props.modelName}: defaultData is required for promise or async function data.`, props.data);
257
258
  }
258
259
  const defaultData = props.getDefaultData(
259
- ((_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) ? [] : {} : {}
260
+ "defaultData" in vue.vnode.props ? vue.vnode.props.defaultData : "data" in vue.vnode.props ? Array.isArray((0, import_vue.unref)(vue.vnode.props.data)) ? [] : {} : {}
260
261
  );
261
262
  const datatype = Array.isArray(defaultData) ? [] : {};
262
- const config = {
263
- data: (0, import_vue.reactive)(import_object_manager.default.on(
264
- 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
265
- ).clone()),
266
- defaultData: import_object_manager.default.on(defaultData).clone(),
267
- notifications: props.notifications,
268
- subscriptions: props.subscriptions,
269
- logging: props.logging,
270
- name: props.modelName
271
- };
272
- const model = new Proxy(props.model ? typeof props.model === "function" ? props.model(config) : props.model : new import_data_manager.default(config), {
273
- get(target, key, receiver) {
274
- if (key === "setData" || key === "replaceData") {
275
- return (...params) => {
276
- var _a2;
277
- const beforeSetData = (_a2 = access(component).beforeSetData) != null ? _a2 : props.beforeSetData;
278
- if (typeof beforeSetData === "function") {
279
- const before = target.getData();
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
- }
263
+ const beta = () => {
264
+ var _a2;
265
+ const emit = (after, before) => {
266
+ if (vue && vue.vnode.el) {
267
+ const event = new CustomEvent("data:emit", {
268
+ bubbles: true,
269
+ // Key: allows it to travel up
270
+ composed: true,
271
+ // Key: allows it to cross Shadow DOM boundaries
272
+ detail: { before, after }
273
+ // Payload goes here
274
+ });
275
+ access(component).model.setData(after);
276
+ vue.vnode.el.dispatchEvent(event);
277
+ }
278
+ };
279
+ const proxy = (data) => {
280
+ return new Proxy(data, {
281
+ get(target, key, receiver) {
282
+ if (["setData", "replaceData"].includes(key.toString())) {
283
+ return (...params) => {
284
+ var _a3;
285
+ const beforeSetData = (_a3 = access(component).beforeSetData) != null ? _a3 : props.beforeSetData;
286
+ if (typeof beforeSetData === "function") {
287
+ const before = import_object_manager.default.on(target.getData());
288
+ const after = params.length ? import_object_manager.default.on(datatype).set(...params) : import_object_manager.default.on(datatype).set(defaultData);
289
+ const diff2 = access(component).diff(before, after);
290
+ if (beforeSetData(diff2, target)) {
291
+ target[key](...params);
292
+ }
293
+ } else {
294
+ target[key](...params);
295
+ }
296
+ return target;
297
+ };
284
298
  } else {
285
- target[key](...params);
299
+ return Reflect.get(target, key, receiver);
286
300
  }
287
- return target;
288
- };
301
+ }
302
+ });
303
+ };
304
+ const normalize = (data) => {
305
+ const datatype2 = Array.isArray(defaultData) ? [] : {};
306
+ if ((0, import_vue.isRef)(data) || (0, import_vue.isReactive)(data) || isFunctionData || isPromiseData) {
307
+ return (0, import_vue.reactive)(datatype2);
289
308
  } else {
290
- return Reflect.get(target, key, receiver);
309
+ const props2 = "data" in vue.vnode.props;
310
+ try {
311
+ if (["Array", "Object"].includes(data.constructor.name)) {
312
+ return (0, import_vue.reactive)(datatype2);
313
+ } else {
314
+ return (0, import_vue.reactive)(props2 ? { "": datatype2 } : datatype2);
315
+ }
316
+ } catch (e) {
317
+ return (0, import_vue.reactive)(props2 ? { "": datatype2 } : datatype2);
318
+ }
291
319
  }
292
- }
293
- });
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
- }
298
- const watchDataProp = (dataProp) => {
299
- var _a2, _b2, _c2, _d2;
300
- const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
301
- callback: (_b2 = ((_a2 = context.attrs["onUpdate:data"]) != null ? _a2 : {}).callback) != null ? _b2 : context.attrs["data:callback"],
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)
305
320
  };
306
- if (context.attrs["data:log"]) {
307
- console.log(`[ReactiveView]:data`, { config: config2, dataProp });
321
+ const config = {
322
+ data: normalize((_a2 = vue.vnode.props) == null ? void 0 : _a2.data),
323
+ defaultData: import_object_manager.default.on(defaultData).clone(),
324
+ notifications: props.notifications,
325
+ subscriptions: props.subscriptions,
326
+ name: props.modelName,
327
+ logging: props.logging
328
+ };
329
+ const model = props.model ? typeof props.model === "function" ? props.model(config) : props.model : new import_data_manager.default(config);
330
+ const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, diff, emit, dataPath: dataPath2, model: proxy(model), isValid } });
331
+ if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
332
+ const config2 = {
333
+ callback: typeof context.attrs["onUpdate:model"] === "function" ? context.attrs["onUpdate:model"] : context.attrs["update:model"],
334
+ options: {
335
+ immediate: context.attrs["model:immediate"],
336
+ deep: context.attrs["model:deep"],
337
+ once: context.attrs["model:once"]
338
+ }
339
+ };
340
+ const source = () => import_object_manager.default.on(model.getData()).clone();
341
+ (0, import_vue.watch)(source, (after, before) => {
342
+ const diff2 = access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after));
343
+ if (diff2.changed) {
344
+ config2.callback(diff2, { component });
345
+ }
346
+ });
308
347
  }
309
- (0, import_vue.watch)(isFunctionData || (0, import_vue.isRef)(dataProp) || (0, import_vue.isReactive)(dataProp) ? dataProp : () => dataProp, (after, before) => {
348
+ setTimeout(async () => {
349
+ var _a3, _b2, _c2;
350
+ const [data] = isPromiseData ? await Promise.all([
351
+ isAsyncFunctionData ? props.data() : props.data,
352
+ (_a3 = defer.value) != null ? _a3 : true
353
+ ]) : [props.data];
354
+ const isRefData = (0, import_vue.isRef)(data);
355
+ const isReactiveData = (0, import_vue.isReactive)(data);
356
+ const source = isRefData || isReactiveData || isFunctionData ? data : typeof data === "function" ? data : (() => data);
357
+ (0, import_vue.watch)(source, async (after, before) => {
358
+ var _a4;
359
+ const diff2 = access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after));
360
+ const callback = context.attrs["data:callback"];
361
+ if (typeof callback === "function") {
362
+ model.replaceData((_a4 = await callback(diff2, { component })) != null ? _a4 : after);
363
+ } else {
364
+ model.replaceData(after);
365
+ }
366
+ }, {
367
+ immediate: (_b2 = context.attrs["data:immediate"]) != null ? _b2 : true,
368
+ deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true,
369
+ once: context.attrs["data:once"]
370
+ });
371
+ });
372
+ setTimeout(async () => {
310
373
  var _a3;
311
- if (typeof config2.callback === "function") {
312
- model.replaceData((_a3 = config2.callback(diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component })) != null ? _a3 : after);
374
+ isReady.value = (_a3 = await defer.value) != null ? _a3 : true;
375
+ });
376
+ component.value = [access(component)].reduce((options, parent) => {
377
+ var _a3;
378
+ while (parent) {
379
+ if (typeof parent.setup === "function") {
380
+ options = { parent: options, self: (_a3 = parent.setup(component, options)) != null ? _a3 : {} };
381
+ if (access(parent.$parent).ReactiveView) {
382
+ break;
383
+ } else {
384
+ parent = access(parent.$parent);
385
+ }
386
+ } else {
387
+ break;
388
+ }
389
+ }
390
+ return options;
391
+ }, component.value);
392
+ props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
393
+ return (vue2) => {
394
+ var _a3, _b2;
395
+ if (isReady.value) {
396
+ return access(component).template(component, vue2);
313
397
  } else {
314
- model.replaceData(after);
398
+ return (_b2 = (_a3 = context.slots).loading) == null ? void 0 : _b2.call(_a3, { component });
315
399
  }
316
- }, config2.options);
400
+ };
317
401
  };
318
- if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
319
- const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
320
- callback: context.attrs["onUpdate:model"],
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 : {};
325
- if (context.attrs["model:log"]) {
326
- console.log(`[ReactiveView]:model`, { config: config2 });
402
+ const current = () => {
403
+ var _a2, _b2, _c2, _d;
404
+ const emit = (after, before) => {
405
+ if (vue && vue.vnode.el) {
406
+ const event = new CustomEvent("data:emit", {
407
+ bubbles: true,
408
+ // Key: allows it to travel up
409
+ composed: true,
410
+ // Key: allows it to cross Shadow DOM boundaries
411
+ detail: { before, after }
412
+ // Payload goes here
413
+ });
414
+ vue.vnode.el.dispatchEvent(event);
415
+ }
416
+ };
417
+ const normalize = (data) => {
418
+ if (props.debug) {
419
+ 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) });
420
+ }
421
+ if ((0, import_vue.isReactive)(data)) {
422
+ return data;
423
+ } else {
424
+ if ((0, import_vue.isRef)(data) || isFunctionData || isPromiseData) {
425
+ return (0, import_vue.reactive)(datatype);
426
+ } else {
427
+ const props2 = "data" in vue.vnode.props;
428
+ try {
429
+ if (["Array", "Object"].includes(data.constructor.name)) {
430
+ return (0, import_vue.reactive)(props2 ? data : datatype);
431
+ } else {
432
+ return (0, import_vue.reactive)(props2 ? { "": data } : datatype);
433
+ }
434
+ } catch (e) {
435
+ return (0, import_vue.reactive)(props2 ? { "": data } : datatype);
436
+ }
437
+ }
438
+ }
439
+ };
440
+ const config = {
441
+ data: props.beta ? normalize((_a2 = vue.vnode.props) == null ? void 0 : _a2.data) : (0, import_vue.reactive)(import_object_manager.default.on(
442
+ isPromiseData || isFunctionData || (0, import_vue.isRef)(props.data) || (0, import_vue.isReactive)(props.data) ? datatype : "data" in vue.vnode.props ? props.data : datatype
443
+ ).clone()),
444
+ defaultData: import_object_manager.default.on(defaultData).clone(),
445
+ notifications: props.notifications,
446
+ subscriptions: props.subscriptions,
447
+ name: props.modelName,
448
+ logging: props.logging
449
+ };
450
+ const model = new Proxy(props.model ? typeof props.model === "function" ? props.model(config) : props.model : new import_data_manager.default(config), {
451
+ get(target, key, receiver) {
452
+ if (["setData", "replaceData"].includes(key.toString())) {
453
+ return (...params) => {
454
+ var _a3;
455
+ const beforeSetData = (_a3 = access(component).beforeSetData) != null ? _a3 : props.beforeSetData;
456
+ if (typeof beforeSetData === "function") {
457
+ const before = import_object_manager.default.on(target.getData());
458
+ const after = params.length ? import_object_manager.default.on(datatype).set(...params) : import_object_manager.default.on(datatype).set(defaultData);
459
+ if (beforeSetData(access(component).diff(before, after), target)) {
460
+ target[key](...params);
461
+ }
462
+ } else {
463
+ target[key](...params);
464
+ }
465
+ return target;
466
+ };
467
+ } else {
468
+ return Reflect.get(target, key, receiver);
469
+ }
470
+ }
471
+ });
472
+ const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, diff, emit, dataPath: dataPath2, isValid } });
473
+ if (props.debug) {
474
+ console.warn("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
327
475
  }
328
- (0, import_vue.watch)(() => model.getData(), (after, before) => {
329
- config2.callback(diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component });
330
- }, config2.options);
331
- }
332
- setTimeout(async () => {
333
- var _a2;
334
- const [data] = await Promise.all([isAsyncFunctionData ? props.data() : props.data, (_a2 = defer.value) != null ? _a2 : true]);
335
- watchDataProp(data);
336
- });
337
- setTimeout(async () => {
338
- var _a2;
339
- isReady.value = (_a2 = await defer.value) != null ? _a2 : true;
340
- });
341
- component.value = [access(component)].reduce((options, parent) => {
342
- var _a2;
343
- while (parent) {
344
- if (typeof parent.setup === "function") {
345
- options = { parent: options, self: (_a2 = parent.setup(component, options)) != null ? _a2 : {} };
346
- if (access(parent.$parent).ReactiveView) {
347
- break;
476
+ const watchDataProp = (dataProp) => {
477
+ var _a3, _b3, _c3, _d2;
478
+ const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
479
+ callback: (_b3 = ((_a3 = context.attrs["onUpdate:data"]) != null ? _a3 : {}).callback) != null ? _b3 : context.attrs["data:callback"],
480
+ options: Object.assign(__spreadValues(__spreadValues({
481
+ deep: (_c3 = context.attrs["data:deep"]) != null ? _c3 : true
482
+ }, 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)
483
+ };
484
+ if (context.attrs["data:log"]) {
485
+ console.warn(`[ReactiveView]:data`, { config: config2, dataProp });
486
+ }
487
+ (0, import_vue.watch)(isFunctionData || (0, import_vue.isRef)(dataProp) || (0, import_vue.isReactive)(dataProp) ? dataProp : () => dataProp, (after, before) => {
488
+ var _a4;
489
+ if (typeof config2.callback === "function") {
490
+ model.replaceData((_a4 = config2.callback(access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component })) != null ? _a4 : after);
348
491
  } else {
349
- parent = access(parent.$parent);
492
+ model.replaceData(after);
350
493
  }
351
- } else {
352
- break;
494
+ }, config2.options);
495
+ };
496
+ if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
497
+ const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
498
+ callback: context.attrs["onUpdate:model"],
499
+ options: Object.assign(__spreadValues(__spreadValues({
500
+ deep: (_b2 = context.attrs["model:deep"]) != null ? _b2 : true
501
+ }, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_c2 = context.attrs["onUpdate:model"]) != null ? _c2 : {}).options)
502
+ } : (_d = context.attrs["onUpdate:model"]) != null ? _d : {};
503
+ if (context.attrs["model:log"]) {
504
+ console.warn(`[ReactiveView]:model`, { config: config2 });
353
505
  }
506
+ (0, import_vue.watch)(() => import_object_manager.default.on(model.getData()).clone(), (after, before) => {
507
+ config2.callback(access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component });
508
+ }, config2.options);
354
509
  }
355
- return options;
356
- }, component.value);
357
- props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
358
- return (vue2) => {
359
- var _a2, _b2;
360
- if (isReady.value) {
361
- return access(component).template(component, vue2);
510
+ if (props.beta) {
511
+ const isRefData = (0, import_vue.isRef)(props.data);
512
+ if (isRefData || isFunctionData || isPromiseData) {
513
+ setTimeout(async () => {
514
+ var _a3, _b3, _c3;
515
+ const [data] = isPromiseData ? await Promise.all([
516
+ isAsyncFunctionData ? props.data() : props.data,
517
+ (_a3 = defer.value) != null ? _a3 : true
518
+ ]) : [props.data];
519
+ (0, import_vue.watch)(isRefData ? data : isFunctionData ? data : typeof data === "function" ? data : () => data, (after, before) => {
520
+ var _a4;
521
+ if (before !== void 0 || after !== void 0) {
522
+ const callback = context.attrs["data:callback"];
523
+ if (typeof callback === "function") {
524
+ const diff2 = access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after));
525
+ model.replaceData((_a4 = callback(diff2, { component })) != null ? _a4 : after);
526
+ } else {
527
+ model.replaceData(after);
528
+ }
529
+ }
530
+ }, {
531
+ immediate: (_b3 = context.attrs["data:immediate"]) != null ? _b3 : true,
532
+ deep: (_c3 = context.attrs["data:deep"]) != null ? _c3 : true,
533
+ once: context.attrs["data:once"]
534
+ });
535
+ });
536
+ }
362
537
  } else {
363
- return (_b2 = (_a2 = context.slots).loading) == null ? void 0 : _b2.call(_a2, { component });
538
+ setTimeout(async () => {
539
+ var _a3;
540
+ const [data] = await Promise.all([
541
+ isAsyncFunctionData ? props.data() : props.data,
542
+ (_a3 = defer.value) != null ? _a3 : true
543
+ ]);
544
+ watchDataProp(data);
545
+ });
364
546
  }
547
+ setTimeout(async () => {
548
+ var _a3;
549
+ isReady.value = (_a3 = await defer.value) != null ? _a3 : true;
550
+ });
551
+ component.value = [access(component)].reduce((options, parent) => {
552
+ var _a3;
553
+ while (parent) {
554
+ if (typeof parent.setup === "function") {
555
+ options = { parent: options, self: (_a3 = parent.setup(component, options)) != null ? _a3 : {} };
556
+ if (access(parent.$parent).ReactiveView) {
557
+ break;
558
+ } else {
559
+ parent = access(parent.$parent);
560
+ }
561
+ } else {
562
+ break;
563
+ }
564
+ }
565
+ return options;
566
+ }, component.value);
567
+ props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
568
+ return (vue2) => {
569
+ var _a3, _b3;
570
+ if (isReady.value) {
571
+ return access(component).template(component, vue2);
572
+ } else {
573
+ return (_b3 = (_a3 = context.slots).loading) == null ? void 0 : _b3.call(_a3, { component });
574
+ }
575
+ };
365
576
  };
577
+ return props.beta === "next" ? beta() : current();
366
578
  }
367
579
  };
368
580
 
@@ -370,6 +582,7 @@ var ReactiveView_default = {
370
582
  var import_vue2 = require("vue");
371
583
  var import_date_fns_tz = require("date-fns-tz");
372
584
  var import_tailwind_merge = require("tailwind-merge");
585
+ console.log(`%c[ReactiveView]: ${version}`, "background-color: red; color: yellow;");
373
586
  var index_default = ReactiveView_default;
374
587
  function safeRequest(request) {
375
588
  return new Promise(async (resolve) => {
@@ -443,6 +656,7 @@ function getDate(param1, param2) {
443
656
  return (0, import_date_fns_tz.formatInTimeZone)(datetime(), options.timezone, options.format);
444
657
  }
445
658
  function access(view = {}, alternative) {
659
+ var _a;
446
660
  const resolve = (target) => {
447
661
  return new Proxy((0, import_vue2.toRaw)(target), {
448
662
  get(target2, key) {
@@ -465,9 +679,8 @@ function access(view = {}, alternative) {
465
679
  });
466
680
  };
467
681
  try {
468
- const component = typeof view === "function" ? view() : view;
469
- const ref2 = (0, import_vue2.isRef)(component) ? component.value : component;
470
- return resolve(ref2.ReactiveView ? access(ref2.instance) : ref2);
682
+ const component = (_a = (0, import_vue2.unref)(typeof view === "function" ? view() : view)) != null ? _a : {};
683
+ return resolve("instance" in component ? component.instance : component);
471
684
  } catch (e) {
472
685
  return resolve(view);
473
686
  }
@@ -550,28 +763,106 @@ var extendVnode = (component, element) => {
550
763
  const vnode = getVnode();
551
764
  return (props = {}, slots) => {
552
765
  var _a;
553
- const _b = getProps((_a = vnode.props) != null ? _a : {}, []), { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
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);
766
+ const isFunctionClass = typeof props.class === "function";
767
+ const isFunctionStyle = typeof props.style === "function";
768
+ const _b = (_a = vnode.props) != null ? _a : {}, { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
769
+ const finalClasses = (0, import_tailwind_merge.twMerge)(isFunctionClass ? "" : classes, MergeStyles(isFunctionClass ? props.class(classes) : props.class).string);
770
+ const finalStyles = MergeStyles(styles, isFunctionStyle ? props.style(styles) : props.style);
556
771
  const functionalProps = Object.entries(props).reduce((props2, [key2, value]) => {
557
772
  var _a2;
558
- if (!["class", "style"].includes(key2) && typeof value === "function") {
773
+ if (!["class", "style", "setup"].includes(key2) && typeof value === "function") {
559
774
  props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
560
775
  }
561
776
  return props2;
562
777
  }, props);
563
778
  const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
564
779
  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);
780
+ const finalElement = ["undefined"].includes(typeof element) ? vnode.type : element;
781
+ return (0, import_vue2.h)(finalElement, finalProps, finalSlots);
566
782
  };
567
783
  }
568
784
  });
569
785
  };
786
+ function defineReactiveView(param1, param2) {
787
+ const instance = (0, import_vue2.ref)();
788
+ return (0, import_vue2.defineComponent)({
789
+ name: param1 == null ? void 0 : param1.modelName,
790
+ props: __spreadValues({ setup }, param1 ? param1.props : {}),
791
+ setup() {
792
+ const _a = param1 != null ? param1 : {}, { setup: setup2, props } = _a, rest = __objRest(_a, ["setup", "props"]);
793
+ return (component) => {
794
+ const props2 = Object.entries(rest).reduce((props3, [key, val]) => {
795
+ return Object.assign(props3, { [key]: typeof val === "function" ? val(component, instance) : val });
796
+ }, {});
797
+ 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;
798
+ return (0, import_vue2.createVNode)(param2 != null ? param2 : ReactiveView_default, __spreadProps(__spreadValues(__spreadValues({}, props2), Object.assign({}, props2, typeof setup2 === "function" ? {
799
+ setup: (self, parent) => setup2(self, parent, component)
800
+ } : {})), {
801
+ instance
802
+ }), slots);
803
+ };
804
+ }
805
+ });
806
+ }
807
+ function showComponent(component, options = {}) {
808
+ var _a;
809
+ if (options.router) {
810
+ console.warn("[ReactiveView]: Deprecated {router} option used with {showComponent()}. \nUse {plugins} option instead.");
811
+ }
812
+ if (!options.key || !document.getElementById(options.key)) {
813
+ const container = options.container || "app-dialogs";
814
+ const dialogs = document.getElementById(container) || document.createElement("div");
815
+ if (!dialogs.hasAttribute("id")) {
816
+ dialogs.setAttribute("id", container);
817
+ document.body.appendChild(dialogs);
818
+ }
819
+ const dialog = document.createElement("div");
820
+ const id = (_a = options.key) != null ? _a : `dialog_${dialogs.children.length + 1}`;
821
+ dialog.setAttribute("id", id);
822
+ dialogs.appendChild(dialog);
823
+ const app = (0, import_vue2.createApp)(
824
+ {
825
+ setup() {
826
+ return () => component;
827
+ }
828
+ },
829
+ {
830
+ __cleanup__: () => {
831
+ document.querySelectorAll(`#${id}`).forEach((element) => element.remove());
832
+ app.unmount();
833
+ }
834
+ }
835
+ );
836
+ if (options.router) {
837
+ return app.use(options.router).mount(`#${id}`);
838
+ } else if (options.plugins) {
839
+ return options.plugins.reduce((app2, plugin) => {
840
+ return app2.use(...Array.isArray(plugin) ? plugin : [plugin]);
841
+ }, app).mount(`#${id}`);
842
+ } else {
843
+ return app.mount(`#${id}`);
844
+ }
845
+ }
846
+ }
570
847
  var getData = (component, path, alternative) => {
571
- return import_object_manager2.default.on((0, import_vue2.unref)(component.state)).get(dataPath(component, path), alternative);
848
+ const vue = access(component);
849
+ const data = import_object_manager2.default.on(componentState(vue));
850
+ if (path) {
851
+ return data.get(dataPath(vue, path), alternative);
852
+ } else {
853
+ return data.get();
854
+ }
855
+ };
856
+ var setData = (component, data, path) => {
857
+ const vue = access(component);
858
+ const diff = {
859
+ before: import_object_manager2.default.on(componentState(vue)).clone(),
860
+ 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()
861
+ };
862
+ return "state" in vue ? diff : vue.$emit("update:state", diff);
572
863
  };
573
- var setData = (component, data) => {
574
- return component.$emit("update:state", { before: import_object_manager2.default.on((0, import_vue2.unref)(component.state)).clone(), after: data });
864
+ var componentState = (component) => {
865
+ return (0, import_vue2.unref)("state" in component ? component.state : component.$attrs.state);
575
866
  };
576
867
  var dataPath = (component, path) => {
577
868
  return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
@@ -582,6 +873,7 @@ var dataPath = (component, path) => {
582
873
  StyleParser,
583
874
  access,
584
875
  dataPath,
876
+ defineReactiveView,
585
877
  extendVnode,
586
878
  getData,
587
879
  getDate,
@@ -590,5 +882,6 @@ var dataPath = (component, path) => {
590
882
  safeRequest,
591
883
  setData,
592
884
  setup,
885
+ showComponent,
593
886
  useSubscription
594
887
  });