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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.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";
134
+ var version = "0.1.0-beta.2";
129
135
 
130
136
  // src/ReactiveView.ts
131
137
  var setup = {
@@ -136,17 +142,16 @@ var setup = {
136
142
  var ReactiveView_default = {
137
143
  props: {
138
144
  setup: {},
145
+ beta: [Boolean, String],
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: {},
154
+ data: { default: reactive({}) },
150
155
  defaultData: {},
151
156
  getDefaultData: {
152
157
  type: Function,
@@ -166,142 +171,380 @@ var ReactiveView_default = {
166
171
  debug: {
167
172
  type: Boolean,
168
173
  default: false
169
- }
174
+ },
175
+ state: { default: reactive({}) }
170
176
  },
171
177
  setup(props, context) {
172
- var _a, _b, _c, _d, _e, _f, _g;
173
- const template = (component2, vue2) => {
174
- return createVNode(
175
- "div",
176
- context.slots.default ? context.attrs : __spreadValues({
177
- style: { color: "red", textAlign: "center" }
178
- }, context.attrs),
179
- context.slots.default ? context.slots.default({ component: component2, vue: vue2, props, context }) : `${props.modelName}: ${name}@${version}`
180
- );
178
+ var _a, _b, _c;
179
+ const diff = (before, after) => {
180
+ const changed = ref(false);
181
+ const paths = Array.from(new Set(before.paths().concat(after.paths())));
182
+ const changes = paths.reduce((changes2, path) => {
183
+ if (before.get(path) !== after.get(path)) {
184
+ changes2.set(path, after.get(path));
185
+ changed.value = true;
186
+ }
187
+ return changes2;
188
+ }, ObjectManager.on({}));
189
+ return { before: before.get(), after: after.get(), changes: changes.get(), changed: changed.value };
190
+ };
191
+ const dataPath2 = (path) => {
192
+ try {
193
+ return context.attrs["data:path"](path);
194
+ } catch (e) {
195
+ return path;
196
+ }
197
+ };
198
+ const template = (component, vue2) => {
199
+ return createVNode("div", context.slots.default ? context.attrs : __spreadValues({
200
+ style: { color: "red", textAlign: "center" }
201
+ }, context.attrs), context.slots.default ? context.slots.default({ component, vue: vue2, props, context }) : `${props.modelName}: ${name}@${version}`);
181
202
  };
182
203
  const isValid = ref(false);
183
204
  const isReady = ref(false);
184
- const isFunctionData = ["Function"].includes(((_a = props.data) != null ? _a : {}).constructor.name);
185
- const isAsyncFunctionData = ["AsyncFunction"].includes(((_b = props.data) != null ? _b : {}).constructor.name);
186
- const isPromiseData = ["Promise"].includes(((_c = props.data) != null ? _c : {}).constructor.name) || isAsyncFunctionData;
187
205
  const defer = ref(typeof props.defer === "function" ? props.defer() : props.defer);
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;
188
209
  const vue = getCurrentInstance();
189
- if (props.debug) {
190
- console.log("[ReactiveView]:", { props, context, vue, defer, data: props.data, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
191
- }
192
- if ((isPromiseData || isFunctionData) && !("defaultData" in vue.vnode.props)) {
193
- console.error("[ReactiveView]: defaultData is required for function or async data.");
194
- }
195
210
  const defaultData = props.getDefaultData(
196
- ((_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) ? [] : {} : {}
211
+ "defaultData" in vue.vnode.props ? vue.vnode.props.defaultData : "data" in vue.vnode.props ? Array.isArray(unref(vue.vnode.props.data)) ? [] : {} : {}
197
212
  );
198
213
  const datatype = Array.isArray(defaultData) ? [] : {};
199
- const config = {
200
- data: reactive(ObjectManager.on(
201
- isPromiseData || isFunctionData || isRef(props.data) || isReactive(props.data) ? datatype : ((_f = vue.vnode.props) == null ? void 0 : _f.hasOwnProperty("data")) ? props.data : datatype
202
- ).clone()),
203
- defaultData: ObjectManager.on(defaultData).clone(),
204
- notifications: props.notifications,
205
- subscriptions: props.subscriptions,
206
- logging: props.logging,
207
- name: props.modelName
208
- };
209
- const model = new Proxy(props.model ? typeof props.model === "function" ? props.model(config) : props.model : new DataManager(config), {
210
- get(target, key, receiver) {
211
- if (key === "setData" || key === "replaceData") {
212
- return (...params) => {
213
- var _a2;
214
- const beforeSetData = (_a2 = access(component).beforeSetData) != null ? _a2 : props.beforeSetData;
215
- if (typeof beforeSetData === "function") {
216
- const after = ObjectManager.on(datatype).set(...params.length ? params : [defaultData]).get();
217
- const before = target.getData();
218
- beforeSetData({ before, after }, target);
214
+ const beta = () => {
215
+ var _a2;
216
+ const emit = (after, before) => {
217
+ if (vue && vue.vnode.el) {
218
+ const event = new CustomEvent("data:emit", {
219
+ bubbles: true,
220
+ // Key: allows it to travel up
221
+ composed: true,
222
+ // Key: allows it to cross Shadow DOM boundaries
223
+ detail: { before, after }
224
+ // Payload goes here
225
+ });
226
+ access(component).model.setData(after);
227
+ vue.vnode.el.dispatchEvent(event);
228
+ }
229
+ };
230
+ const proxy = (data) => {
231
+ return new Proxy(data, {
232
+ get(target, key, receiver) {
233
+ if (["setData", "replaceData"].includes(key.toString())) {
234
+ return (...params) => {
235
+ var _a3;
236
+ const beforeSetData = (_a3 = access(component).beforeSetData) != null ? _a3 : props.beforeSetData;
237
+ if (typeof beforeSetData === "function") {
238
+ const before = ObjectManager.on(target.getData());
239
+ const after = params.length ? ObjectManager.on(datatype).set(...params) : ObjectManager.on(datatype).set(defaultData);
240
+ const diff2 = access(component).diff(before, after);
241
+ if (beforeSetData(diff2, target)) {
242
+ target[key](...params);
243
+ }
244
+ } else {
245
+ target[key](...params);
246
+ }
247
+ return target;
248
+ };
219
249
  } else {
220
- target[key](...params);
250
+ return Reflect.get(target, key, receiver);
221
251
  }
222
- return target;
223
- };
252
+ }
253
+ });
254
+ };
255
+ const normalize = (data) => {
256
+ const datatype2 = Array.isArray(defaultData) ? [] : {};
257
+ if (isRef(data) || isReactive(data) || isFunctionData || isPromiseData) {
258
+ return reactive(datatype2);
224
259
  } else {
225
- return Reflect.get(target, key, receiver);
260
+ const props2 = "data" in vue.vnode.props;
261
+ try {
262
+ if (["Array", "Object"].includes(data.constructor.name)) {
263
+ return reactive(datatype2);
264
+ } else {
265
+ return reactive(props2 ? { "": datatype2 } : datatype2);
266
+ }
267
+ } catch (e) {
268
+ return reactive(props2 ? { "": datatype2 } : datatype2);
269
+ }
226
270
  }
227
- }
228
- });
229
- const watchDataProp = (dataProp) => {
230
- var _a2, _b2, _c2;
231
- const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
232
- callback: (_b2 = ((_a2 = context.attrs["onUpdate:data"]) != null ? _a2 : {}).callback) != null ? _b2 : context.attrs["data:callback"],
233
- options: Object.assign({
234
- immediate: context.attrs["data:immediate"],
235
- deep: context.attrs["data:deep"],
236
- once: context.attrs["data:once"]
237
- }, ((_c2 = context.attrs["onUpdate:data"]) != null ? _c2 : {}).options)
238
271
  };
239
- if (context.attrs["data:log"]) {
240
- console.log(`[ReactiveView]:data`, { config: config2, dataProp });
272
+ const config = {
273
+ data: normalize((_a2 = vue.vnode.props) == null ? void 0 : _a2.data),
274
+ defaultData: ObjectManager.on(defaultData).clone(),
275
+ notifications: props.notifications,
276
+ subscriptions: props.subscriptions,
277
+ name: props.modelName,
278
+ logging: props.logging
279
+ };
280
+ const model = props.model ? typeof props.model === "function" ? props.model(config) : props.model : new DataManager(config);
281
+ const component = ref({ parent: { self: vue.proxy }, self: { template, diff, emit, dataPath: dataPath2, model: proxy(model), isValid } });
282
+ if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
283
+ const config2 = {
284
+ callback: typeof context.attrs["onUpdate:model"] === "function" ? context.attrs["onUpdate:model"] : context.attrs["update:model"],
285
+ options: {
286
+ immediate: context.attrs["model:immediate"],
287
+ deep: context.attrs["model:deep"],
288
+ once: context.attrs["model:once"]
289
+ }
290
+ };
291
+ const source = () => ObjectManager.on(model.getData()).clone();
292
+ watch(source, (after, before) => {
293
+ const diff2 = access(component).diff(ObjectManager.on(before), ObjectManager.on(after));
294
+ if (props.debug) {
295
+ console.warn(`[${props.modelName}]:model`, { diff: diff2, before, after });
296
+ }
297
+ if (diff2.changed) {
298
+ config2.callback(diff2, { component });
299
+ }
300
+ }, config2.options);
241
301
  }
242
- watch(isFunctionData || isRef(dataProp) || isReactive(dataProp) ? dataProp : () => dataProp, (after, before) => {
302
+ setTimeout(async () => {
303
+ var _a3, _b2, _c2;
304
+ if (props.model !== false) {
305
+ if ((isFunctionData || isPromiseData) && !("defaultData" in vue.vnode.props)) {
306
+ console.warn(`${props.modelName}: defaultData is required for promise or async function data.`, props.data);
307
+ }
308
+ const [data] = isPromiseData ? await Promise.all([
309
+ isAsyncFunctionData ? props.data() : props.data,
310
+ (_a3 = defer.value) != null ? _a3 : true
311
+ ]) : [props.data];
312
+ const isRefData = isRef(data);
313
+ const isReactiveData = isReactive(data);
314
+ const source = isRefData || isReactiveData || isFunctionData ? data : typeof data === "function" ? data : (() => data);
315
+ watch(source, async (after, before) => {
316
+ var _a4;
317
+ const diff2 = access(component).diff(ObjectManager.on(before), ObjectManager.on(after));
318
+ const callback = context.attrs["data:callback"];
319
+ if (props.debug) {
320
+ console.warn(`[${props.modelName}]:data`, { diff: diff2, data, callback, before, after, props, context, isRefData, isReactiveData });
321
+ }
322
+ if (typeof callback === "function") {
323
+ model.replaceData((_a4 = await callback(diff2, { component })) != null ? _a4 : after);
324
+ } else {
325
+ model.replaceData(after);
326
+ }
327
+ }, {
328
+ immediate: (_b2 = context.attrs["data:immediate"]) != null ? _b2 : true,
329
+ deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true,
330
+ once: context.attrs["data:once"]
331
+ });
332
+ }
333
+ });
334
+ setTimeout(async () => {
243
335
  var _a3;
244
- const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
245
- if (typeof config2.callback === "function") {
246
- model.replaceData((_a3 = config2.callback(diff, { component })) != null ? _a3 : after);
336
+ isReady.value = (_a3 = await defer.value) != null ? _a3 : true;
337
+ });
338
+ component.value = [access(component)].reduce((options, parent) => {
339
+ var _a3;
340
+ while (parent) {
341
+ if (typeof parent.setup === "function") {
342
+ options = { parent: options, self: (_a3 = parent.setup(component, options)) != null ? _a3 : {} };
343
+ if (access(parent.$parent).ReactiveView) {
344
+ break;
345
+ } else {
346
+ parent = access(parent.$parent);
347
+ }
348
+ } else {
349
+ break;
350
+ }
351
+ }
352
+ return options;
353
+ }, component.value);
354
+ props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
355
+ return (vue2) => {
356
+ var _a3, _b2;
357
+ if (isReady.value) {
358
+ return access(component).template(component, vue2);
247
359
  } else {
248
- model.replaceData(after);
360
+ return (_b2 = (_a3 = context.slots).loading) == null ? void 0 : _b2.call(_a3, { component });
249
361
  }
250
- }, config2.options);
362
+ };
251
363
  };
252
- setTimeout(async () => {
253
- var _a2;
254
- const [data] = await Promise.all([isAsyncFunctionData ? props.data() : props.data, (_a2 = defer.value) != null ? _a2 : true]);
255
- watchDataProp(data);
256
- });
257
- setTimeout(async () => {
258
- var _a2;
259
- isReady.value = (_a2 = await defer.value) != null ? _a2 : true;
260
- });
261
- if (context.attrs["onUpdate:model"]) {
262
- const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
263
- callback: context.attrs["onUpdate:model"]
264
- } : (_g = context.attrs["onUpdate:model"]) != null ? _g : {};
265
- if (context.attrs["model:log"]) {
266
- console.log(`[ReactiveView]:model`, { config: config2 });
364
+ const current = () => {
365
+ var _a2, _b2, _c2, _d;
366
+ const emit = (after, before) => {
367
+ if (vue && vue.vnode.el) {
368
+ const event = new CustomEvent("data:emit", {
369
+ bubbles: true,
370
+ // Key: allows it to travel up
371
+ composed: true,
372
+ // Key: allows it to cross Shadow DOM boundaries
373
+ detail: { before, after }
374
+ // Payload goes here
375
+ });
376
+ vue.vnode.el.dispatchEvent(event);
377
+ }
378
+ };
379
+ const normalize = (data) => {
380
+ if (props.debug) {
381
+ console.warn(`[ReactiveView]: using beta props data in [${props.modelName}] component`, { vue, data, defaultData, isRef: isRef(data), isReactive: isReactive(data) });
382
+ }
383
+ if (isReactive(data)) {
384
+ return data;
385
+ } else {
386
+ if (isRef(data) || isFunctionData || isPromiseData) {
387
+ return reactive(datatype);
388
+ } else {
389
+ const props2 = "data" in vue.vnode.props;
390
+ try {
391
+ if (["Array", "Object"].includes(data.constructor.name)) {
392
+ return reactive(props2 ? data : datatype);
393
+ } else {
394
+ return reactive(props2 ? { "": data } : datatype);
395
+ }
396
+ } catch (e) {
397
+ return reactive(props2 ? { "": data } : datatype);
398
+ }
399
+ }
400
+ }
401
+ };
402
+ const config = {
403
+ data: props.beta ? normalize((_a2 = vue.vnode.props) == null ? void 0 : _a2.data) : reactive(ObjectManager.on(
404
+ isPromiseData || isFunctionData || isRef(props.data) || isReactive(props.data) ? datatype : "data" in vue.vnode.props ? props.data : datatype
405
+ ).clone()),
406
+ defaultData: ObjectManager.on(defaultData).clone(),
407
+ notifications: props.notifications,
408
+ subscriptions: props.subscriptions,
409
+ name: props.modelName,
410
+ logging: props.logging
411
+ };
412
+ const model = new Proxy(props.model ? typeof props.model === "function" ? props.model(config) : props.model : new DataManager(config), {
413
+ get(target, key, receiver) {
414
+ if (["setData", "replaceData"].includes(key.toString())) {
415
+ return (...params) => {
416
+ var _a3;
417
+ const beforeSetData = (_a3 = access(component).beforeSetData) != null ? _a3 : props.beforeSetData;
418
+ if (typeof beforeSetData === "function") {
419
+ const before = ObjectManager.on(target.getData());
420
+ const after = params.length ? ObjectManager.on(datatype).set(...params) : ObjectManager.on(datatype).set(defaultData);
421
+ if (beforeSetData(access(component).diff(before, after), target)) {
422
+ target[key](...params);
423
+ }
424
+ } else {
425
+ target[key](...params);
426
+ }
427
+ return target;
428
+ };
429
+ } else {
430
+ return Reflect.get(target, key, receiver);
431
+ }
432
+ }
433
+ });
434
+ const component = ref({ parent: { self: vue.proxy }, self: { template, model, diff, emit, dataPath: dataPath2, isValid } });
435
+ if (props.debug) {
436
+ console.warn("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isPromiseData });
267
437
  }
268
- watch(() => model.getData(), (after, before) => {
269
- const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
270
- config2.callback(diff, { component });
271
- }, config2.options);
272
- }
273
- const component = ref({ parent: { self: vue.proxy }, self: { template, model, isValid } });
274
- component.value = [access(component)].reduce((options, parent) => {
275
- var _a2;
276
- while (parent) {
277
- if (typeof parent.setup === "function") {
278
- options = { parent: options, self: (_a2 = parent.setup(component, options)) != null ? _a2 : {} };
279
- if (access(parent.$parent).ReactiveView) {
280
- break;
438
+ const watchDataProp = (dataProp) => {
439
+ var _a3, _b3, _c3, _d2;
440
+ const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
441
+ callback: (_b3 = ((_a3 = context.attrs["onUpdate:data"]) != null ? _a3 : {}).callback) != null ? _b3 : context.attrs["data:callback"],
442
+ options: Object.assign(__spreadValues(__spreadValues({
443
+ deep: (_c3 = context.attrs["data:deep"]) != null ? _c3 : true
444
+ }, 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)
445
+ };
446
+ if (context.attrs["data:log"]) {
447
+ console.warn(`[ReactiveView]:data`, { config: config2, dataProp });
448
+ }
449
+ watch(isFunctionData || isRef(dataProp) || isReactive(dataProp) ? dataProp : () => dataProp, (after, before) => {
450
+ var _a4;
451
+ if (typeof config2.callback === "function") {
452
+ model.replaceData((_a4 = config2.callback(access(component).diff(ObjectManager.on(before), ObjectManager.on(after)), { component })) != null ? _a4 : after);
281
453
  } else {
282
- parent = access(parent.$parent);
454
+ model.replaceData(after);
283
455
  }
284
- } else {
285
- break;
456
+ }, config2.options);
457
+ };
458
+ if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
459
+ const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
460
+ callback: context.attrs["onUpdate:model"],
461
+ options: Object.assign(__spreadValues(__spreadValues({
462
+ deep: (_b2 = context.attrs["model:deep"]) != null ? _b2 : true
463
+ }, 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)
464
+ } : (_d = context.attrs["onUpdate:model"]) != null ? _d : {};
465
+ if (context.attrs["model:log"]) {
466
+ console.warn(`[ReactiveView]:model`, { config: config2 });
286
467
  }
468
+ watch(() => ObjectManager.on(model.getData()).clone(), (after, before) => {
469
+ config2.callback(access(component).diff(ObjectManager.on(before), ObjectManager.on(after)), { component });
470
+ }, config2.options);
287
471
  }
288
- return options;
289
- }, component.value);
290
- props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
291
- return (vue2) => {
292
- var _a2, _b2;
293
- if (isReady.value) {
294
- return access(component).template(component, vue2);
472
+ if (props.beta) {
473
+ const isRefData = isRef(props.data);
474
+ if (isRefData || isFunctionData || isPromiseData) {
475
+ setTimeout(async () => {
476
+ var _a3, _b3, _c3;
477
+ const [data] = isPromiseData ? await Promise.all([
478
+ isAsyncFunctionData ? props.data() : props.data,
479
+ (_a3 = defer.value) != null ? _a3 : true
480
+ ]) : [props.data];
481
+ watch(isRefData ? data : isFunctionData ? data : typeof data === "function" ? data : () => data, (after, before) => {
482
+ var _a4;
483
+ if (before !== void 0 || after !== void 0) {
484
+ const callback = context.attrs["data:callback"];
485
+ if (typeof callback === "function") {
486
+ const diff2 = access(component).diff(ObjectManager.on(before), ObjectManager.on(after));
487
+ model.replaceData((_a4 = callback(diff2, { component })) != null ? _a4 : after);
488
+ } else {
489
+ model.replaceData(after);
490
+ }
491
+ }
492
+ }, {
493
+ immediate: (_b3 = context.attrs["data:immediate"]) != null ? _b3 : true,
494
+ deep: (_c3 = context.attrs["data:deep"]) != null ? _c3 : true,
495
+ once: context.attrs["data:once"]
496
+ });
497
+ });
498
+ }
295
499
  } else {
296
- return (_b2 = (_a2 = context.slots).loading) == null ? void 0 : _b2.call(_a2, { component });
500
+ setTimeout(async () => {
501
+ var _a3;
502
+ const [data] = await Promise.all([
503
+ isAsyncFunctionData ? props.data() : props.data,
504
+ (_a3 = defer.value) != null ? _a3 : true
505
+ ]);
506
+ watchDataProp(data);
507
+ });
297
508
  }
509
+ setTimeout(async () => {
510
+ var _a3;
511
+ isReady.value = (_a3 = await defer.value) != null ? _a3 : true;
512
+ });
513
+ component.value = [access(component)].reduce((options, parent) => {
514
+ var _a3;
515
+ while (parent) {
516
+ if (typeof parent.setup === "function") {
517
+ options = { parent: options, self: (_a3 = parent.setup(component, options)) != null ? _a3 : {} };
518
+ if (access(parent.$parent).ReactiveView) {
519
+ break;
520
+ } else {
521
+ parent = access(parent.$parent);
522
+ }
523
+ } else {
524
+ break;
525
+ }
526
+ }
527
+ return options;
528
+ }, component.value);
529
+ props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
530
+ return (vue2) => {
531
+ var _a3, _b3;
532
+ if (isReady.value) {
533
+ return access(component).template(component, vue2);
534
+ } else {
535
+ return (_b3 = (_a3 = context.slots).loading) == null ? void 0 : _b3.call(_a3, { component });
536
+ }
537
+ };
298
538
  };
539
+ return props.beta === "next" ? beta() : current();
299
540
  }
300
541
  };
301
542
 
302
543
  // src/index.ts
303
- import { createVNode as createVNode2, isRef as isRef2, h } from "vue";
544
+ import { h, ref as ref2, unref as unref2, toRaw, createApp, createVNode as createVNode2, defineComponent } from "vue";
304
545
  import { formatInTimeZone } from "date-fns-tz";
546
+ import { twMerge } from "tailwind-merge";
547
+ console.log(`%c[ReactiveView]: ${version}`, "background-color: red; color: yellow;");
305
548
  var index_default = ReactiveView_default;
306
549
  function safeRequest(request) {
307
550
  return new Promise(async (resolve) => {
@@ -331,7 +574,7 @@ function safeRequest(request) {
331
574
  }
332
575
  });
333
576
  }
334
- function getProps(props, param2) {
577
+ function getProps(props = {}, param2) {
335
578
  var _a;
336
579
  const exclude = Array.isArray(param2) || typeof param2 === "string" ? param2 : param2.exclude;
337
580
  const exclusions = (Array.isArray(exclude) ? exclude : [exclude]).join("|");
@@ -375,8 +618,9 @@ function getDate(param1, param2) {
375
618
  return formatInTimeZone(datetime(), options.timezone, options.format);
376
619
  }
377
620
  function access(view = {}, alternative) {
621
+ var _a;
378
622
  const resolve = (target) => {
379
- return new Proxy(target, {
623
+ return new Proxy(toRaw(target), {
380
624
  get(target2, key) {
381
625
  const component = { tree: target2 };
382
626
  do {
@@ -397,9 +641,8 @@ function access(view = {}, alternative) {
397
641
  });
398
642
  };
399
643
  try {
400
- const component = typeof view === "function" ? view() : view;
401
- const ref2 = isRef2(component) ? component.value : component;
402
- return resolve(ref2.ReactiveView ? access(ref2.instance) : ref2);
644
+ const component = (_a = unref2(typeof view === "function" ? view() : view)) != null ? _a : {};
645
+ return resolve("instance" in component ? component.instance : component);
403
646
  } catch (e) {
404
647
  return resolve(view);
405
648
  }
@@ -482,37 +725,125 @@ var extendVnode = (component, element) => {
482
725
  const vnode = getVnode();
483
726
  return (props = {}, slots) => {
484
727
  var _a;
485
- const _b = getProps((_a = vnode.props) != null ? _a : {}, []), { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
486
- const finalClasses = MergeStyles(classes, typeof props.class === "function" ? props.class(classes) : props.class);
728
+ const isFunctionClass = typeof props.class === "function";
729
+ const isFunctionStyle = typeof props.style === "function";
730
+ const _b = (_a = vnode.props) != null ? _a : {}, { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
731
+ const finalClasses = twMerge(isFunctionClass ? "" : classes, MergeStyles(isFunctionClass ? props.class(classes) : props.class).string);
732
+ const finalStyles = MergeStyles(styles, isFunctionStyle ? props.style(styles) : props.style);
487
733
  const functionalProps = Object.entries(props).reduce((props2, [key2, value]) => {
488
- if (![
489
- "class"
490
- /*, "style"*/
491
- ].includes(key2) && typeof value === "function") {
492
- props2[key2] = value(vnode.props[key2]);
734
+ var _a2;
735
+ if (!["class", "style", "setup"].includes(key2) && typeof value === "function") {
736
+ props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
493
737
  }
494
738
  return props2;
495
739
  }, props);
496
- const finalProps = Object.assign(rest, functionalProps, {
497
- class: finalClasses
498
- /*, style: finalStyles*/
499
- });
500
- const finalSlots = typeof slots === "function" ? slots(vnode.children) : vnode.children;
501
- return h(["string", "undefined"].includes(typeof element) ? vnode : element, finalProps, finalSlots);
740
+ const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
741
+ const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
742
+ const finalElement = ["undefined"].includes(typeof element) ? vnode.type : element;
743
+ return h(finalElement, finalProps, finalSlots);
502
744
  };
503
745
  }
504
746
  });
505
747
  };
748
+ function defineReactiveView(param1, param2) {
749
+ const instance = ref2();
750
+ return defineComponent({
751
+ name: param1 == null ? void 0 : param1.modelName,
752
+ props: __spreadValues({ setup }, param1 ? param1.props : {}),
753
+ setup() {
754
+ const _a = param1 != null ? param1 : {}, { setup: setup2, props } = _a, rest = __objRest(_a, ["setup", "props"]);
755
+ return (component) => {
756
+ const props2 = Object.entries(rest).reduce((props3, [key, val]) => {
757
+ return Object.assign(props3, { [key]: typeof val === "function" ? val(component, instance) : val });
758
+ }, {});
759
+ 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;
760
+ return createVNode2(param2 != null ? param2 : ReactiveView_default, __spreadProps(__spreadValues(__spreadValues({}, props2), Object.assign({}, props2, typeof setup2 === "function" ? {
761
+ setup: (self, parent) => setup2(self, parent, component)
762
+ } : {})), {
763
+ instance
764
+ }), slots);
765
+ };
766
+ }
767
+ });
768
+ }
769
+ function showComponent(component, options = {}) {
770
+ var _a;
771
+ if (options.router) {
772
+ console.warn("[ReactiveView]: Deprecated {router} option used with {showComponent()}. \nUse {plugins} option instead.");
773
+ }
774
+ if (!options.key || !document.getElementById(options.key)) {
775
+ const container = options.container || "app-dialogs";
776
+ const dialogs = document.getElementById(container) || document.createElement("div");
777
+ if (!dialogs.hasAttribute("id")) {
778
+ dialogs.setAttribute("id", container);
779
+ document.body.appendChild(dialogs);
780
+ }
781
+ const dialog = document.createElement("div");
782
+ const id = (_a = options.key) != null ? _a : `dialog_${dialogs.children.length + 1}`;
783
+ dialog.setAttribute("id", id);
784
+ dialogs.appendChild(dialog);
785
+ const app = createApp(
786
+ {
787
+ setup() {
788
+ return () => component;
789
+ }
790
+ },
791
+ {
792
+ __cleanup__: () => {
793
+ document.querySelectorAll(`#${id}`).forEach((element) => element.remove());
794
+ app.unmount();
795
+ }
796
+ }
797
+ );
798
+ if (options.router) {
799
+ return app.use(options.router).mount(`#${id}`);
800
+ } else if (options.plugins) {
801
+ return options.plugins.reduce((app2, plugin) => {
802
+ return app2.use(...Array.isArray(plugin) ? plugin : [plugin]);
803
+ }, app).mount(`#${id}`);
804
+ } else {
805
+ return app.mount(`#${id}`);
806
+ }
807
+ }
808
+ }
809
+ var getData = (component, path, alternative) => {
810
+ const vue = access(component);
811
+ const data = ObjectManager2.on(componentState(vue));
812
+ if (path) {
813
+ return data.get(dataPath(vue, path), alternative);
814
+ } else {
815
+ return data.get();
816
+ }
817
+ };
818
+ var setData = (component, data, path) => {
819
+ const vue = access(component);
820
+ const diff = {
821
+ before: ObjectManager2.on(componentState(vue)).clone(),
822
+ after: path ? ObjectManager2.on(componentState(vue)).set(dataPath(vue, path), data).get() : ObjectManager2.on(componentState(vue)).set(data).get()
823
+ };
824
+ return "state" in vue ? diff : vue.$emit("update:state", diff);
825
+ };
826
+ var componentState = (component) => {
827
+ return unref2("state" in component ? component.state : component.$attrs.state);
828
+ };
829
+ var dataPath = (component, path) => {
830
+ return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
831
+ };
506
832
  export {
507
833
  MergeStyles,
508
834
  StyleParser,
509
835
  access,
836
+ dataPath,
510
837
  index_default as default,
838
+ defineReactiveView,
511
839
  extendVnode,
840
+ getData,
512
841
  getDate,
513
842
  getProps,
514
843
  getReactiveViewComponent,
515
844
  safeRequest,
845
+ setData,
516
846
  setup,
847
+ showComponent,
517
848
  useSubscription
518
849
  };