@razaman2/reactive-view 0.0.34 → 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)
@@ -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";
180
+ var version = "0.1.0-beta.1";
172
181
 
173
182
  // src/ReactiveView.ts
174
183
  var setup = {
@@ -179,17 +188,16 @@ var setup = {
179
188
  var ReactiveView_default = {
180
189
  props: {
181
190
  setup: {},
191
+ beta: [Boolean, String],
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: {},
200
+ data: { default: (0, import_vue.reactive)({}) },
193
201
  defaultData: {},
194
202
  getDefaultData: {
195
203
  type: Function,
@@ -209,142 +217,372 @@ var ReactiveView_default = {
209
217
  debug: {
210
218
  type: Boolean,
211
219
  default: false
212
- }
220
+ },
221
+ state: { default: (0, import_vue.reactive)({}) }
213
222
  },
214
223
  setup(props, context) {
215
- var _a, _b, _c, _d, _e, _f, _g;
216
- const template = (component2, vue2) => {
217
- return (0, import_vue.createVNode)(
218
- "div",
219
- context.slots.default ? context.attrs : __spreadValues({
220
- style: { color: "red", textAlign: "center" }
221
- }, context.attrs),
222
- context.slots.default ? context.slots.default({ component: component2, vue: vue2, props, context }) : `${props.modelName}: ${name}@${version}`
223
- );
224
+ var _a, _b, _c;
225
+ const diff = (before, after) => {
226
+ const paths = Array.from(new Set(before.paths().concat(after.paths())));
227
+ let changed = false;
228
+ const change = paths.reduce((change2, path) => {
229
+ if (before.get(path) !== after.get(path)) {
230
+ change2.set(path, after.get(path));
231
+ changed = true;
232
+ }
233
+ return change2;
234
+ }, import_object_manager.default.on({}));
235
+ return { before: before.get(), after: after.get(), changes: change.get(), changed };
236
+ };
237
+ const dataPath2 = (path) => {
238
+ try {
239
+ return context.attrs["data:path"](path);
240
+ } catch (e) {
241
+ return path;
242
+ }
243
+ };
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}`);
224
248
  };
225
249
  const isValid = (0, import_vue.ref)(false);
226
250
  const isReady = (0, import_vue.ref)(false);
227
- const isFunctionData = ["Function"].includes(((_a = props.data) != null ? _a : {}).constructor.name);
228
- const isAsyncFunctionData = ["AsyncFunction"].includes(((_b = props.data) != null ? _b : {}).constructor.name);
229
- const isPromiseData = ["Promise"].includes(((_c = props.data) != null ? _c : {}).constructor.name) || isAsyncFunctionData;
230
251
  const defer = (0, import_vue.ref)(typeof props.defer === "function" ? props.defer() : props.defer);
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;
231
255
  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
- if ((isPromiseData || isFunctionData) && !("defaultData" in vue.vnode.props)) {
236
- console.error("[ReactiveView]: defaultData is required for function or async 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);
237
258
  }
238
259
  const defaultData = props.getDefaultData(
239
- ((_d = vue.vnode.props) == null ? void 0 : _d.hasOwnProperty("defaultData")) ? vue.vnode.props.defaultData : ((_e = vue.vnode.props) == null ? void 0 : _e.hasOwnProperty("data")) ? Array.isArray(vue.vnode.props.data) ? [] : {} : {}
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)) ? [] : {} : {}
240
261
  );
241
262
  const datatype = Array.isArray(defaultData) ? [] : {};
242
- const config = {
243
- data: (0, import_vue.reactive)(import_object_manager.default.on(
244
- isPromiseData || isFunctionData || (0, import_vue.isRef)(props.data) || (0, import_vue.isReactive)(props.data) ? datatype : ((_f = vue.vnode.props) == null ? void 0 : _f.hasOwnProperty("data")) ? props.data : datatype
245
- ).clone()),
246
- defaultData: import_object_manager.default.on(defaultData).clone(),
247
- notifications: props.notifications,
248
- subscriptions: props.subscriptions,
249
- logging: props.logging,
250
- name: props.modelName
251
- };
252
- const model = new Proxy(props.model ? typeof props.model === "function" ? props.model(config) : props.model : new import_data_manager.default(config), {
253
- get(target, key, receiver) {
254
- if (key === "setData" || key === "replaceData") {
255
- return (...params) => {
256
- var _a2;
257
- const beforeSetData = (_a2 = access(component).beforeSetData) != null ? _a2 : props.beforeSetData;
258
- if (typeof beforeSetData === "function") {
259
- const after = import_object_manager.default.on(datatype).set(...params.length ? params : [defaultData]).get();
260
- const before = target.getData();
261
- beforeSetData({ before, after }, target);
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
+ };
262
298
  } else {
263
- target[key](...params);
299
+ return Reflect.get(target, key, receiver);
264
300
  }
265
- return target;
266
- };
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);
267
308
  } else {
268
- 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
+ }
269
319
  }
270
- }
271
- });
272
- const watchDataProp = (dataProp) => {
273
- var _a2, _b2, _c2;
274
- const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
275
- callback: (_b2 = ((_a2 = context.attrs["onUpdate:data"]) != null ? _a2 : {}).callback) != null ? _b2 : context.attrs["data:callback"],
276
- options: Object.assign({
277
- immediate: context.attrs["data:immediate"],
278
- deep: context.attrs["data:deep"],
279
- once: context.attrs["data:once"]
280
- }, ((_c2 = context.attrs["onUpdate:data"]) != null ? _c2 : {}).options)
281
320
  };
282
- if (context.attrs["data:log"]) {
283
- 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
+ });
284
347
  }
285
- (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 () => {
373
+ var _a3;
374
+ isReady.value = (_a3 = await defer.value) != null ? _a3 : true;
375
+ });
376
+ component.value = [access(component)].reduce((options, parent) => {
286
377
  var _a3;
287
- const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
288
- if (typeof config2.callback === "function") {
289
- model.replaceData((_a3 = config2.callback(diff, { component })) != null ? _a3 : after);
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);
290
397
  } else {
291
- model.replaceData(after);
398
+ return (_b2 = (_a3 = context.slots).loading) == null ? void 0 : _b2.call(_a3, { component });
292
399
  }
293
- }, config2.options);
400
+ };
294
401
  };
295
- setTimeout(async () => {
296
- var _a2;
297
- const [data] = await Promise.all([isAsyncFunctionData ? props.data() : props.data, (_a2 = defer.value) != null ? _a2 : true]);
298
- watchDataProp(data);
299
- });
300
- setTimeout(async () => {
301
- var _a2;
302
- isReady.value = (_a2 = await defer.value) != null ? _a2 : true;
303
- });
304
- if (context.attrs["onUpdate:model"]) {
305
- const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
306
- callback: context.attrs["onUpdate:model"]
307
- } : (_g = context.attrs["onUpdate:model"]) != null ? _g : {};
308
- if (context.attrs["model:log"]) {
309
- 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 });
310
475
  }
311
- (0, import_vue.watch)(() => model.getData(), (after, before) => {
312
- const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
313
- config2.callback(diff, { component });
314
- }, config2.options);
315
- }
316
- const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, isValid } });
317
- component.value = [access(component)].reduce((options, parent) => {
318
- var _a2;
319
- while (parent) {
320
- if (typeof parent.setup === "function") {
321
- options = { parent: options, self: (_a2 = parent.setup(component, options)) != null ? _a2 : {} };
322
- if (access(parent.$parent).ReactiveView) {
323
- 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);
324
491
  } else {
325
- parent = access(parent.$parent);
492
+ model.replaceData(after);
326
493
  }
327
- } else {
328
- 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 });
329
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);
330
509
  }
331
- return options;
332
- }, component.value);
333
- props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
334
- return (vue2) => {
335
- var _a2, _b2;
336
- if (isReady.value) {
337
- 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
+ }
338
537
  } else {
339
- 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
+ });
340
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
+ };
341
576
  };
577
+ return props.beta === "next" ? beta() : current();
342
578
  }
343
579
  };
344
580
 
345
581
  // src/index.ts
346
582
  var import_vue2 = require("vue");
347
583
  var import_date_fns_tz = require("date-fns-tz");
584
+ var import_tailwind_merge = require("tailwind-merge");
585
+ console.log(`%c[ReactiveView]: ${version}`, "background-color: red; color: yellow;");
348
586
  var index_default = ReactiveView_default;
349
587
  function safeRequest(request) {
350
588
  return new Promise(async (resolve) => {
@@ -374,7 +612,7 @@ function safeRequest(request) {
374
612
  }
375
613
  });
376
614
  }
377
- function getProps(props, param2) {
615
+ function getProps(props = {}, param2) {
378
616
  var _a;
379
617
  const exclude = Array.isArray(param2) || typeof param2 === "string" ? param2 : param2.exclude;
380
618
  const exclusions = (Array.isArray(exclude) ? exclude : [exclude]).join("|");
@@ -418,8 +656,9 @@ function getDate(param1, param2) {
418
656
  return (0, import_date_fns_tz.formatInTimeZone)(datetime(), options.timezone, options.format);
419
657
  }
420
658
  function access(view = {}, alternative) {
659
+ var _a;
421
660
  const resolve = (target) => {
422
- return new Proxy(target, {
661
+ return new Proxy((0, import_vue2.toRaw)(target), {
423
662
  get(target2, key) {
424
663
  const component = { tree: target2 };
425
664
  do {
@@ -440,9 +679,8 @@ function access(view = {}, alternative) {
440
679
  });
441
680
  };
442
681
  try {
443
- const component = typeof view === "function" ? view() : view;
444
- const ref2 = (0, import_vue2.isRef)(component) ? component.value : component;
445
- 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);
446
684
  } catch (e) {
447
685
  return resolve(view);
448
686
  }
@@ -525,37 +763,125 @@ var extendVnode = (component, element) => {
525
763
  const vnode = getVnode();
526
764
  return (props = {}, slots) => {
527
765
  var _a;
528
- const _b = getProps((_a = vnode.props) != null ? _a : {}, []), { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
529
- const finalClasses = MergeStyles(classes, typeof props.class === "function" ? props.class(classes) : props.class);
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);
530
771
  const functionalProps = Object.entries(props).reduce((props2, [key2, value]) => {
531
- if (![
532
- "class"
533
- /*, "style"*/
534
- ].includes(key2) && typeof value === "function") {
535
- props2[key2] = value(vnode.props[key2]);
772
+ var _a2;
773
+ if (!["class", "style", "setup"].includes(key2) && typeof value === "function") {
774
+ props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
536
775
  }
537
776
  return props2;
538
777
  }, props);
539
- const finalProps = Object.assign(rest, functionalProps, {
540
- class: finalClasses
541
- /*, style: finalStyles*/
542
- });
543
- const finalSlots = typeof slots === "function" ? slots(vnode.children) : vnode.children;
544
- return (0, import_vue2.h)(["string", "undefined"].includes(typeof element) ? vnode : element, finalProps, finalSlots);
778
+ const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
779
+ const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
780
+ const finalElement = ["undefined"].includes(typeof element) ? vnode.type : element;
781
+ return (0, import_vue2.h)(finalElement, finalProps, finalSlots);
545
782
  };
546
783
  }
547
784
  });
548
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
+ }
847
+ var getData = (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);
863
+ };
864
+ var componentState = (component) => {
865
+ return (0, import_vue2.unref)("state" in component ? component.state : component.$attrs.state);
866
+ };
867
+ var dataPath = (component, path) => {
868
+ return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
869
+ };
549
870
  // Annotate the CommonJS export names for ESM import in node:
550
871
  0 && (module.exports = {
551
872
  MergeStyles,
552
873
  StyleParser,
553
874
  access,
875
+ dataPath,
876
+ defineReactiveView,
554
877
  extendVnode,
878
+ getData,
555
879
  getDate,
556
880
  getProps,
557
881
  getReactiveViewComponent,
558
882
  safeRequest,
883
+ setData,
559
884
  setup,
885
+ showComponent,
560
886
  useSubscription
561
887
  });