@razaman2/reactive-view 0.0.34-beta.18 → 0.0.34-beta.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -43,6 +43,7 @@ declare const setup: {
43
43
  declare const _default: {
44
44
  props: {
45
45
  setup: {};
46
+ beta: BooleanConstructor;
46
47
  ReactiveView: {
47
48
  type: BooleanConstructor;
48
49
  default: boolean;
@@ -121,8 +122,13 @@ declare function StyleParser(styles?: Array<string> | Record<string, boolean> |
121
122
  declare function MergeStyles(...params: any): any;
122
123
  declare const extendVnode: (component: Record<string, any>, element: any) => Record<string, (props?: Record<string, any>, slots?: Record<string, any> | ((slots: Record<string, any>) => Record<string, any>)) => any>;
123
124
  declare function defineReactiveView(options: Record<string, any>, component: typeof _default, _options: Record<string, any>): ReturnType<typeof defineComponent>;
125
+ declare function showComponent(component: any, options?: {
126
+ container?: string;
127
+ key?: string;
128
+ router?: any;
129
+ }): void;
124
130
  declare const getData: (component: any, path: number | string, alternative: any) => any;
125
131
  declare const setData: (component: any, data: any, path?: string) => any;
126
132
  declare const dataPath: (component: any, path: string | number) => any;
127
133
 
128
- export { MergeStyles, StyleParser, access, dataPath, _default as default, defineReactiveView, extendVnode, getData, getDate, getProps, getReactiveViewComponent, safeRequest, setData, setup, useSubscription };
134
+ export { MergeStyles, StyleParser, access, dataPath, _default as default, defineReactiveView, extendVnode, getData, getDate, getProps, getReactiveViewComponent, safeRequest, setData, setup, showComponent, useSubscription };
package/dist/index.d.ts CHANGED
@@ -43,6 +43,7 @@ declare const setup: {
43
43
  declare const _default: {
44
44
  props: {
45
45
  setup: {};
46
+ beta: BooleanConstructor;
46
47
  ReactiveView: {
47
48
  type: BooleanConstructor;
48
49
  default: boolean;
@@ -121,8 +122,13 @@ declare function StyleParser(styles?: Array<string> | Record<string, boolean> |
121
122
  declare function MergeStyles(...params: any): any;
122
123
  declare const extendVnode: (component: Record<string, any>, element: any) => Record<string, (props?: Record<string, any>, slots?: Record<string, any> | ((slots: Record<string, any>) => Record<string, any>)) => any>;
123
124
  declare function defineReactiveView(options: Record<string, any>, component: typeof _default, _options: Record<string, any>): ReturnType<typeof defineComponent>;
125
+ declare function showComponent(component: any, options?: {
126
+ container?: string;
127
+ key?: string;
128
+ router?: any;
129
+ }): void;
124
130
  declare const getData: (component: any, path: number | string, alternative: any) => any;
125
131
  declare const setData: (component: any, data: any, path?: string) => any;
126
132
  declare const dataPath: (component: any, path: string | number) => any;
127
133
 
128
- export { MergeStyles, StyleParser, access, dataPath, _default as default, defineReactiveView, extendVnode, getData, getDate, getProps, getReactiveViewComponent, safeRequest, setData, setup, useSubscription };
134
+ export { MergeStyles, StyleParser, access, dataPath, _default as default, defineReactiveView, extendVnode, getData, getDate, getProps, getReactiveViewComponent, safeRequest, setData, setup, showComponent, useSubscription };
package/dist/index.js CHANGED
@@ -70,6 +70,7 @@ __export(index_exports, {
70
70
  safeRequest: () => safeRequest,
71
71
  setData: () => setData,
72
72
  setup: () => setup,
73
+ showComponent: () => showComponent,
73
74
  useSubscription: () => useSubscription
74
75
  });
75
76
  module.exports = __toCommonJS(index_exports);
@@ -173,7 +174,7 @@ var import_vue = require("vue");
173
174
 
174
175
  // package.json
175
176
  var name = "@razaman2/reactive-view";
176
- var version = "0.0.34-beta.18";
177
+ var version = "0.0.34-beta.19";
177
178
 
178
179
  // src/ReactiveView.ts
179
180
  var setup = {
@@ -184,6 +185,7 @@ var setup = {
184
185
  var ReactiveView_default = {
185
186
  props: {
186
187
  setup: {},
188
+ beta: Boolean,
187
189
  ReactiveView: {
188
190
  type: Boolean,
189
191
  default: true
@@ -216,7 +218,7 @@ var ReactiveView_default = {
216
218
  state: { default: () => (0, import_vue.reactive)({}) }
217
219
  },
218
220
  setup(props, context) {
219
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
221
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
220
222
  const diff = (before, after) => {
221
223
  const change = after.paths().reduce((change2, path) => {
222
224
  if (before.get(path) !== after.get(path)) {
@@ -249,16 +251,46 @@ var ReactiveView_default = {
249
251
  const isPromiseData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
250
252
  const defer = (0, import_vue.ref)(typeof props.defer === "function" ? props.defer() : props.defer);
251
253
  const vue = (0, import_vue.getCurrentInstance)();
252
- if ((isPromiseData || isFunctionData) && !("defaultData" in vue.vnode.props)) {
254
+ if ((isFunctionData || isPromiseData) && !("defaultData" in vue.vnode.props)) {
253
255
  console.error("[ReactiveView]: defaultData is required for promise or async function data.");
254
256
  }
255
257
  const defaultData = props.getDefaultData(
256
258
  ((_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) ? [] : {} : {}
257
259
  );
258
260
  const datatype = Array.isArray(defaultData) ? [] : {};
261
+ const normalize = (data) => {
262
+ var _a2, _b2, _c2;
263
+ console.warn(`[ReactiveView]: using beta props data in [${props.modelName}] component`, data, defaultData);
264
+ if ((0, import_vue.isReactive)(data)) {
265
+ return data;
266
+ } else if ((0, import_vue.isRef)(data)) {
267
+ try {
268
+ if (["Array", "Object"].includes((0, import_vue.unref)(data).constructor.name)) {
269
+ return (0, import_vue.unref)(data);
270
+ } else {
271
+ return (0, import_vue.reactive)({ "": (0, import_vue.unref)(data) });
272
+ }
273
+ } catch (e) {
274
+ return (0, import_vue.reactive)({ "": (0, import_vue.unref)(data) });
275
+ }
276
+ } else {
277
+ if (isFunctionData || isPromiseData) {
278
+ } else {
279
+ try {
280
+ if (["Array", "Object"].includes(data.constructor.name)) {
281
+ return (0, import_vue.reactive)(((_a2 = vue.vnode.props) == null ? void 0 : _a2.hasOwnProperty("data")) ? data : defaultData);
282
+ } else {
283
+ return (0, import_vue.reactive)({ "": ((_b2 = vue.vnode.props) == null ? void 0 : _b2.hasOwnProperty("data")) ? data : defaultData });
284
+ }
285
+ } catch (e) {
286
+ return (0, import_vue.reactive)({ "": ((_c2 = vue.vnode.props) == null ? void 0 : _c2.hasOwnProperty("data")) ? data : defaultData });
287
+ }
288
+ }
289
+ }
290
+ };
259
291
  const config = {
260
- data: (0, import_vue.reactive)(import_object_manager.default.on(
261
- 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
292
+ data: props.beta ? normalize((_f = vue.vnode.props) == null ? void 0 : _f.data) : (0, import_vue.reactive)(import_object_manager.default.on(
293
+ isPromiseData || isFunctionData || (0, import_vue.isRef)(props.data) || (0, import_vue.isReactive)(props.data) ? datatype : ((_g = vue.vnode.props) == null ? void 0 : _g.hasOwnProperty("data")) ? props.data : datatype
262
294
  ).clone()),
263
295
  defaultData: import_object_manager.default.on(defaultData).clone(),
264
296
  notifications: props.notifications,
@@ -316,9 +348,9 @@ var ReactiveView_default = {
316
348
  const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
317
349
  callback: context.attrs["onUpdate:model"],
318
350
  options: Object.assign(__spreadValues(__spreadValues({
319
- deep: (_g = context.attrs["model:deep"]) != null ? _g : true
320
- }, 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)
321
- } : (_i = context.attrs["onUpdate:model"]) != null ? _i : {};
351
+ deep: (_h = context.attrs["model:deep"]) != null ? _h : true
352
+ }, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_i = context.attrs["onUpdate:model"]) != null ? _i : {}).options)
353
+ } : (_j = context.attrs["onUpdate:model"]) != null ? _j : {};
322
354
  if (context.attrs["model:log"]) {
323
355
  console.log(`[ReactiveView]:model`, { config: config2 });
324
356
  }
@@ -326,11 +358,13 @@ var ReactiveView_default = {
326
358
  config2.callback(diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component });
327
359
  }, config2.options);
328
360
  }
329
- setTimeout(async () => {
330
- var _a2;
331
- const [data] = await Promise.all([isAsyncFunctionData ? props.data() : props.data, (_a2 = defer.value) != null ? _a2 : true]);
332
- watchDataProp(data);
333
- });
361
+ if (!props.beta) {
362
+ setTimeout(async () => {
363
+ var _a2;
364
+ const [data] = await Promise.all([isAsyncFunctionData ? props.data() : props.data, (_a2 = defer.value) != null ? _a2 : true]);
365
+ watchDataProp(data);
366
+ });
367
+ }
334
368
  setTimeout(async () => {
335
369
  var _a2;
336
370
  isReady.value = (_a2 = await defer.value) != null ? _a2 : true;
@@ -567,18 +601,52 @@ var extendVnode = (component, element) => {
567
601
  });
568
602
  };
569
603
  function defineReactiveView(param1, param2) {
604
+ console.log(`log params:`, { param1, param2 });
570
605
  return (0, import_vue2.defineComponent)({
571
606
  props: __spreadValues({ setup }, param1.props),
572
607
  setup() {
573
608
  const _a = param1, { setup: setup2, props } = _a, rest = __objRest(_a, ["setup", "props"]);
574
609
  return (component) => {
575
- return (0, import_vue2.createVNode)(param2, Object.assign({}, rest, setup2 ? {
610
+ return (0, import_vue2.createVNode)(param2 != null ? param2 : ReactiveView_default, Object.assign({}, rest, setup2 ? {
576
611
  setup: (self, parent) => setup2(self, parent, component)
577
- } : {}));
612
+ // @ts-ignore
613
+ } : {}), typeof param1.slots === "function" ? param1.slots(component) : param1.slots);
578
614
  };
579
615
  }
580
616
  });
581
617
  }
618
+ function showComponent(component, options = {}) {
619
+ var _a;
620
+ if (!options.key || !document.getElementById(options.key)) {
621
+ const container = options.container || "app-modal";
622
+ const dialogs = document.getElementById(container) || document.createElement("div");
623
+ if (!dialogs.hasAttribute("id")) {
624
+ dialogs.setAttribute("id", container);
625
+ document.body.appendChild(dialogs);
626
+ }
627
+ const dialog = document.createElement("div");
628
+ const id = (_a = options.key) != null ? _a : `dialog_${dialogs.children.length + 1}`;
629
+ dialog.setAttribute("id", id);
630
+ dialogs.appendChild(dialog);
631
+ const app = (0, import_vue2.createApp)(
632
+ {
633
+ setup() {
634
+ return () => component;
635
+ }
636
+ },
637
+ {
638
+ __cleanup__: () => {
639
+ document.querySelectorAll(`#${id}`).forEach((element) => element.remove());
640
+ }
641
+ }
642
+ );
643
+ if (options.router) {
644
+ app.use(options.router).mount(`#${id}`);
645
+ } else {
646
+ app.mount(`#${id}`);
647
+ }
648
+ }
649
+ }
582
650
  var getData = (component, path, alternative) => {
583
651
  const vue = access(component);
584
652
  const data = import_object_manager2.default.on(componentState(vue));
@@ -617,5 +685,6 @@ var dataPath = (component, path) => {
617
685
  safeRequest,
618
686
  setData,
619
687
  setup,
688
+ showComponent,
620
689
  useSubscription
621
690
  });
package/dist/index.mjs CHANGED
@@ -124,11 +124,11 @@ var Subscriptions = _Subscriptions;
124
124
  // src/ReactiveView.ts
125
125
  import ObjectManager from "@razaman2/object-manager";
126
126
  import DataManager from "@razaman2/data-manager";
127
- import { ref, reactive, watch, isRef, isReactive, createVNode, getCurrentInstance } from "vue";
127
+ import { ref, reactive, watch, unref, isRef, isReactive, createVNode, getCurrentInstance } from "vue";
128
128
 
129
129
  // package.json
130
130
  var name = "@razaman2/reactive-view";
131
- var version = "0.0.34-beta.18";
131
+ var version = "0.0.34-beta.19";
132
132
 
133
133
  // src/ReactiveView.ts
134
134
  var setup = {
@@ -139,6 +139,7 @@ var setup = {
139
139
  var ReactiveView_default = {
140
140
  props: {
141
141
  setup: {},
142
+ beta: Boolean,
142
143
  ReactiveView: {
143
144
  type: Boolean,
144
145
  default: true
@@ -171,7 +172,7 @@ var ReactiveView_default = {
171
172
  state: { default: () => reactive({}) }
172
173
  },
173
174
  setup(props, context) {
174
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
175
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
175
176
  const diff = (before, after) => {
176
177
  const change = after.paths().reduce((change2, path) => {
177
178
  if (before.get(path) !== after.get(path)) {
@@ -204,16 +205,46 @@ var ReactiveView_default = {
204
205
  const isPromiseData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
205
206
  const defer = ref(typeof props.defer === "function" ? props.defer() : props.defer);
206
207
  const vue = getCurrentInstance();
207
- if ((isPromiseData || isFunctionData) && !("defaultData" in vue.vnode.props)) {
208
+ if ((isFunctionData || isPromiseData) && !("defaultData" in vue.vnode.props)) {
208
209
  console.error("[ReactiveView]: defaultData is required for promise or async function data.");
209
210
  }
210
211
  const defaultData = props.getDefaultData(
211
212
  ((_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) ? [] : {} : {}
212
213
  );
213
214
  const datatype = Array.isArray(defaultData) ? [] : {};
215
+ const normalize = (data) => {
216
+ var _a2, _b2, _c2;
217
+ console.warn(`[ReactiveView]: using beta props data in [${props.modelName}] component`, data, defaultData);
218
+ if (isReactive(data)) {
219
+ return data;
220
+ } else if (isRef(data)) {
221
+ try {
222
+ if (["Array", "Object"].includes(unref(data).constructor.name)) {
223
+ return unref(data);
224
+ } else {
225
+ return reactive({ "": unref(data) });
226
+ }
227
+ } catch (e) {
228
+ return reactive({ "": unref(data) });
229
+ }
230
+ } else {
231
+ if (isFunctionData || isPromiseData) {
232
+ } else {
233
+ try {
234
+ if (["Array", "Object"].includes(data.constructor.name)) {
235
+ return reactive(((_a2 = vue.vnode.props) == null ? void 0 : _a2.hasOwnProperty("data")) ? data : defaultData);
236
+ } else {
237
+ return reactive({ "": ((_b2 = vue.vnode.props) == null ? void 0 : _b2.hasOwnProperty("data")) ? data : defaultData });
238
+ }
239
+ } catch (e) {
240
+ return reactive({ "": ((_c2 = vue.vnode.props) == null ? void 0 : _c2.hasOwnProperty("data")) ? data : defaultData });
241
+ }
242
+ }
243
+ }
244
+ };
214
245
  const config = {
215
- data: reactive(ObjectManager.on(
216
- isPromiseData || isFunctionData || isRef(props.data) || isReactive(props.data) ? datatype : ((_f = vue.vnode.props) == null ? void 0 : _f.hasOwnProperty("data")) ? props.data : datatype
246
+ data: props.beta ? normalize((_f = vue.vnode.props) == null ? void 0 : _f.data) : reactive(ObjectManager.on(
247
+ isPromiseData || isFunctionData || isRef(props.data) || isReactive(props.data) ? datatype : ((_g = vue.vnode.props) == null ? void 0 : _g.hasOwnProperty("data")) ? props.data : datatype
217
248
  ).clone()),
218
249
  defaultData: ObjectManager.on(defaultData).clone(),
219
250
  notifications: props.notifications,
@@ -271,9 +302,9 @@ var ReactiveView_default = {
271
302
  const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
272
303
  callback: context.attrs["onUpdate:model"],
273
304
  options: Object.assign(__spreadValues(__spreadValues({
274
- deep: (_g = context.attrs["model:deep"]) != null ? _g : true
275
- }, 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)
276
- } : (_i = context.attrs["onUpdate:model"]) != null ? _i : {};
305
+ deep: (_h = context.attrs["model:deep"]) != null ? _h : true
306
+ }, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_i = context.attrs["onUpdate:model"]) != null ? _i : {}).options)
307
+ } : (_j = context.attrs["onUpdate:model"]) != null ? _j : {};
277
308
  if (context.attrs["model:log"]) {
278
309
  console.log(`[ReactiveView]:model`, { config: config2 });
279
310
  }
@@ -281,11 +312,13 @@ var ReactiveView_default = {
281
312
  config2.callback(diff(ObjectManager.on(before), ObjectManager.on(after)), { component });
282
313
  }, config2.options);
283
314
  }
284
- setTimeout(async () => {
285
- var _a2;
286
- const [data] = await Promise.all([isAsyncFunctionData ? props.data() : props.data, (_a2 = defer.value) != null ? _a2 : true]);
287
- watchDataProp(data);
288
- });
315
+ if (!props.beta) {
316
+ setTimeout(async () => {
317
+ var _a2;
318
+ const [data] = await Promise.all([isAsyncFunctionData ? props.data() : props.data, (_a2 = defer.value) != null ? _a2 : true]);
319
+ watchDataProp(data);
320
+ });
321
+ }
289
322
  setTimeout(async () => {
290
323
  var _a2;
291
324
  isReady.value = (_a2 = await defer.value) != null ? _a2 : true;
@@ -319,7 +352,7 @@ var ReactiveView_default = {
319
352
  };
320
353
 
321
354
  // src/index.ts
322
- import { h, unref as unref2, toRaw, createVNode as createVNode2, defineComponent } from "vue";
355
+ import { h, unref as unref2, toRaw, createApp, createVNode as createVNode2, defineComponent } from "vue";
323
356
  import { formatInTimeZone } from "date-fns-tz";
324
357
  import { twMerge } from "tailwind-merge";
325
358
  console.log(`%c[ReactiveView]: ${version}`, "background-color: red; color: yellow;");
@@ -522,18 +555,52 @@ var extendVnode = (component, element) => {
522
555
  });
523
556
  };
524
557
  function defineReactiveView(param1, param2) {
558
+ console.log(`log params:`, { param1, param2 });
525
559
  return defineComponent({
526
560
  props: __spreadValues({ setup }, param1.props),
527
561
  setup() {
528
562
  const _a = param1, { setup: setup2, props } = _a, rest = __objRest(_a, ["setup", "props"]);
529
563
  return (component) => {
530
- return createVNode2(param2, Object.assign({}, rest, setup2 ? {
564
+ return createVNode2(param2 != null ? param2 : ReactiveView_default, Object.assign({}, rest, setup2 ? {
531
565
  setup: (self, parent) => setup2(self, parent, component)
532
- } : {}));
566
+ // @ts-ignore
567
+ } : {}), typeof param1.slots === "function" ? param1.slots(component) : param1.slots);
533
568
  };
534
569
  }
535
570
  });
536
571
  }
572
+ function showComponent(component, options = {}) {
573
+ var _a;
574
+ if (!options.key || !document.getElementById(options.key)) {
575
+ const container = options.container || "app-modal";
576
+ const dialogs = document.getElementById(container) || document.createElement("div");
577
+ if (!dialogs.hasAttribute("id")) {
578
+ dialogs.setAttribute("id", container);
579
+ document.body.appendChild(dialogs);
580
+ }
581
+ const dialog = document.createElement("div");
582
+ const id = (_a = options.key) != null ? _a : `dialog_${dialogs.children.length + 1}`;
583
+ dialog.setAttribute("id", id);
584
+ dialogs.appendChild(dialog);
585
+ const app = createApp(
586
+ {
587
+ setup() {
588
+ return () => component;
589
+ }
590
+ },
591
+ {
592
+ __cleanup__: () => {
593
+ document.querySelectorAll(`#${id}`).forEach((element) => element.remove());
594
+ }
595
+ }
596
+ );
597
+ if (options.router) {
598
+ app.use(options.router).mount(`#${id}`);
599
+ } else {
600
+ app.mount(`#${id}`);
601
+ }
602
+ }
603
+ }
537
604
  var getData = (component, path, alternative) => {
538
605
  const vue = access(component);
539
606
  const data = ObjectManager2.on(componentState(vue));
@@ -572,5 +639,6 @@ export {
572
639
  safeRequest,
573
640
  setData,
574
641
  setup,
642
+ showComponent,
575
643
  useSubscription
576
644
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@razaman2/reactive-view",
3
- "version": "0.0.34-beta.18",
3
+ "version": "0.0.34-beta.19",
4
4
  "description": "This library enables you to build vue apps in an object oriented way. It provides a convenient approach to extend and override ui components. It provides a built in eventing system along with component data management.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",