@razaman2/reactive-view 0.0.13 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as vue from 'vue';
1
2
  import { SetupContext, ComponentPublicInstance, WatchOptions, UnwrapRef } from 'vue';
2
3
 
3
4
  type SubscriptionItem = {
@@ -93,6 +94,9 @@ declare function safeRequest(request: {
93
94
  }): Promise<any>;
94
95
  declare function getProps(props: Record<string, any>, exclude: PropExclusions): Record<string, any>;
95
96
  declare function getProps(props: Record<string, any>, options: PropOptions): Record<string, any>;
97
+ declare function getReactiveViewComponent(component: any, options?: Record<string, any>): vue.VNode<vue.RendererNode, vue.RendererElement, {
98
+ [key: string]: any;
99
+ }>;
96
100
  declare function getDate(timestamp: {
97
101
  toDate: () => Date;
98
102
  } | Date, format?: string): string;
@@ -113,4 +117,4 @@ declare function getSubscription(): {
113
117
  subscription: Subscription;
114
118
  };
115
119
 
116
- export { type StateUpdate, access, _default as default, getDate, getProps, getSubscription, safeRequest, setup };
120
+ export { type StateUpdate, access, _default as default, getDate, getProps, getReactiveViewComponent, getSubscription, safeRequest, setup };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as vue from 'vue';
1
2
  import { SetupContext, ComponentPublicInstance, WatchOptions, UnwrapRef } from 'vue';
2
3
 
3
4
  type SubscriptionItem = {
@@ -93,6 +94,9 @@ declare function safeRequest(request: {
93
94
  }): Promise<any>;
94
95
  declare function getProps(props: Record<string, any>, exclude: PropExclusions): Record<string, any>;
95
96
  declare function getProps(props: Record<string, any>, options: PropOptions): Record<string, any>;
97
+ declare function getReactiveViewComponent(component: any, options?: Record<string, any>): vue.VNode<vue.RendererNode, vue.RendererElement, {
98
+ [key: string]: any;
99
+ }>;
96
100
  declare function getDate(timestamp: {
97
101
  toDate: () => Date;
98
102
  } | Date, format?: string): string;
@@ -113,4 +117,4 @@ declare function getSubscription(): {
113
117
  subscription: Subscription;
114
118
  };
115
119
 
116
- export { type StateUpdate, access, _default as default, getDate, getProps, getSubscription, safeRequest, setup };
120
+ export { type StateUpdate, access, _default as default, getDate, getProps, getReactiveViewComponent, getSubscription, safeRequest, setup };
package/dist/index.js CHANGED
@@ -60,12 +60,14 @@ __export(src_exports, {
60
60
  default: () => src_default,
61
61
  getDate: () => getDate,
62
62
  getProps: () => getProps,
63
+ getReactiveViewComponent: () => getReactiveViewComponent,
63
64
  getSubscription: () => getSubscription,
64
65
  safeRequest: () => safeRequest,
65
66
  setup: () => setup
66
67
  });
67
68
  module.exports = __toCommonJS(src_exports);
68
69
  var import_date_fns_tz = require("date-fns-tz");
70
+ var import_vue2 = require("vue");
69
71
 
70
72
  // src/Subscription.ts
71
73
  var Subscription = class _Subscription {
@@ -162,7 +164,7 @@ var import_vue = require("vue");
162
164
 
163
165
  // package.json
164
166
  var name = "@razaman2/reactive-view";
165
- var version = "0.0.13";
167
+ var version = "0.0.15";
166
168
 
167
169
  // src/ReactiveView.ts
168
170
  var props = {
@@ -202,7 +204,7 @@ var setup = {
202
204
  var ReactiveView_default = {
203
205
  props: __spreadValues(__spreadValues({}, setup), props),
204
206
  setup(props2, context) {
205
- var _a, _b, _c, _d, _f;
207
+ var _a, _b, _c, _d, _e;
206
208
  const template = (vue, options2) => {
207
209
  var _a2, _b2, _c2;
208
210
  const vnode = context.slots.default ? (0, import_vue.h)(
@@ -215,14 +217,17 @@ var ReactiveView_default = {
215
217
  textAlign: "center"
216
218
  }
217
219
  }, context.attrs), `${props2.modelName}: ${name}@${version}`);
218
- return (_c2 = (_b2 = (_a2 = context.slots).template) == null ? void 0 : _b2.call(_a2, { $vue: vue, vnode })) != null ? _c2 : vnode;
220
+ return (_c2 = (_b2 = (_a2 = context.slots).template) == null ? void 0 : _b2.call(_a2, { vue, options: options2, props: props2, context })) != null ? _c2 : vnode;
219
221
  };
220
222
  const isValid = (0, import_vue.ref)(false);
223
+ const sync = (0, import_vue.ref)(false);
224
+ const rendered = (0, import_vue.ref)(false);
225
+ const component = (0, import_vue.ref)((_a = (0, import_vue.getCurrentInstance)()) == null ? void 0 : _a.proxy);
221
226
  const defaultData = props2.getDefaultData(
222
- Array.isArray(props2.state) ? (_a = props2.defaultData) != null ? _a : [] : (_b = props2.defaultData) != null ? _b : {}
227
+ Array.isArray(props2.state) ? (_b = props2.defaultData) != null ? _b : [] : (_c = props2.defaultData) != null ? _c : {}
223
228
  );
224
- const defaultType = Array.isArray(defaultData) ? [] : {};
225
- const state = (0, import_vue.reactive)(import_data_manager.default.transform(props2.await ? defaultType : (_c = props2.state) != null ? _c : defaultType));
229
+ const type = Array.isArray(defaultData) ? [] : {};
230
+ const state = (0, import_vue.reactive)(import_data_manager.default.transform(props2.await ? type : (_d = props2.state) != null ? _d : type));
226
231
  const config = {
227
232
  defaultData,
228
233
  data: state,
@@ -231,56 +236,69 @@ var ReactiveView_default = {
231
236
  notifications: props2.notifications,
232
237
  subscriptions: props2.subscriptions
233
238
  };
234
- const getState = props2.model ? typeof props2.model === "function" ? props2.model(config) : props2.model : new import_data_manager.default(config);
235
- const sync = (0, import_vue.ref)(false);
236
- const rendered = (0, import_vue.ref)(false);
239
+ const getState = new Proxy(props2.model ? typeof props2.model === "function" ? props2.model(config) : props2.model : new import_data_manager.default(config), {
240
+ get(target, property, receiver) {
241
+ var _a2, _b2;
242
+ const beforeSetData = (_b2 = (_a2 = context.attrs["onUpdate:modelState"]) == null ? void 0 : _a2.beforeSetData) != null ? _b2 : access(component).beforeSetData;
243
+ if (["setData", "replaceData"].includes(property) && typeof beforeSetData === "function") {
244
+ return (...params) => {
245
+ const type2 = Array.isArray(defaultData) ? [] : {};
246
+ beforeSetData(import_object_manager.default.on(type2).set(...params).get(), target);
247
+ };
248
+ } else {
249
+ return Reflect.get(target, property, receiver);
250
+ }
251
+ }
252
+ });
237
253
  const options = {
238
- parent: { self: (0, import_vue.getCurrentInstance)().proxy },
239
- self: { template, isValid, getState }
254
+ parent: { self: component },
255
+ self: { template, getState, isValid }
240
256
  };
241
- const _e = (_d = props2.setup(options)) != null ? _d : options, { parent = {}, self = {} } = _e, rest = __objRest(_e, ["parent", "self"]);
242
- if (props2.await instanceof Promise) {
243
- (0, import_vue.nextTick)(async () => {
244
- getState.replaceData(await props2.await);
245
- });
246
- }
247
- if (props2.defer instanceof Promise) {
248
- (0, import_vue.nextTick)(async () => {
249
- var _a2;
250
- rendered.value = (_a2 = await props2.defer) != null ? _a2 : true;
251
- });
252
- } else {
253
- rendered.value = true;
254
- }
255
- if (context.attrs["onUpdate:modelState"]) {
256
- const config2 = typeof context.attrs["onUpdate:modelState"] === "function" ? { callback: context.attrs["onUpdate:modelState"] } : context.attrs["onUpdate:modelState"];
257
- (0, import_vue.onMounted)(() => {
257
+ const _f = (_e = props2.setup(options)) != null ? _e : options, { parent = {}, self = {} } = _f, rest = __objRest(_f, ["parent", "self"]);
258
+ return ($vue) => {
259
+ var _a2, _b2;
260
+ if (props2.await instanceof Promise) {
261
+ (0, import_vue.nextTick)(async () => {
262
+ getState.replaceData(await props2.await);
263
+ });
264
+ }
265
+ if (props2.defer instanceof Promise) {
266
+ (0, import_vue.nextTick)(async () => {
267
+ var _a3;
268
+ rendered.value = (_a3 = await props2.defer) != null ? _a3 : true;
269
+ });
270
+ } else {
271
+ rendered.value = true;
272
+ }
273
+ if (context.attrs["onUpdate:modelState"]) {
274
+ const config2 = typeof context.attrs["onUpdate:modelState"] === "function" ? {
275
+ callback: context.attrs["onUpdate:modelState"]
276
+ } : (_a2 = context.attrs["onUpdate:modelState"]) != null ? _a2 : {};
258
277
  (0, import_vue.watch)(() => import_object_manager.default.on(state).clone(), (after, before) => {
259
- var _a2;
260
- const beforeStateUpdate = (_a2 = config2.beforeStateUpdate) != null ? _a2 : access({ parent, self }).beforeStateUpdate;
278
+ var _a3;
261
279
  const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
280
+ const beforeStateUpdate = (_a3 = config2.beforeStateUpdate) != null ? _a3 : access({ parent, self }).beforeStateUpdate;
262
281
  if (sync.value) {
263
282
  sync.value = false;
264
- } else {
283
+ } else if (typeof config2.callback === "function") {
265
284
  config2.callback(beforeStateUpdate ? beforeStateUpdate(diff) : diff, getState);
266
285
  }
267
286
  }, config2.options);
268
- });
269
- }
270
- if (context.attrs["onUpdate:propsState"] || props2.sync) {
271
- const config2 = (_f = typeof context.attrs["onUpdate:propsState"] === "function" ? { callback: context.attrs["onUpdate:propsState"] } : context.attrs["onUpdate:propsState"]) != null ? _f : {};
272
- (0, import_vue.onMounted)(() => {
287
+ }
288
+ if (context.attrs["onUpdate:propsState"] || props2.sync) {
289
+ const config2 = typeof context.attrs["onUpdate:propsState"] === "function" ? {
290
+ callback: context.attrs["onUpdate:propsState"]
291
+ } : (_b2 = context.attrs["onUpdate:propsState"]) != null ? _b2 : {};
273
292
  (0, import_vue.watch)(() => import_object_manager.default.on(props2.state).clone(), (after, before) => {
293
+ const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
274
294
  if (props2.sync && typeof config2.callback !== "function") {
275
295
  getState.replaceData(after);
276
296
  } else if (typeof config2.callback === "function") {
277
- config2.callback({ before, after }, getState);
297
+ config2.callback(diff, getState);
278
298
  }
279
299
  sync.value = true;
280
300
  }, config2.options);
281
- });
282
- }
283
- return ($vue) => {
301
+ }
284
302
  const setup2 = { $vue, options: parent };
285
303
  while (setup2.options) {
286
304
  Object.defineProperties(setup2.$vue, Object.assign({
@@ -344,6 +362,20 @@ function getProps(props2, param2) {
344
362
  return props3;
345
363
  }, {}));
346
364
  }
365
+ function getReactiveViewComponent(component, options = {}) {
366
+ const model = (component2) => {
367
+ try {
368
+ return (component2.type || component2).props.hasOwnProperty("model");
369
+ } catch (e) {
370
+ return false;
371
+ }
372
+ };
373
+ const props2 = getProps(options, "setup");
374
+ const slots = typeof component === "function" ? component : () => {
375
+ return (component.type || component).setup ? (0, import_vue2.createVNode)(component, component.setup ? {} : props2) : component;
376
+ };
377
+ return model(component) ? (0, import_vue2.createVNode)(component, props2) : (0, import_vue2.createVNode)(ReactiveView_default, props2, slots);
378
+ }
347
379
  function getDate(param1, param2) {
348
380
  var _a, _b;
349
381
  const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
@@ -419,6 +451,7 @@ function getSubscription() {
419
451
  access,
420
452
  getDate,
421
453
  getProps,
454
+ getReactiveViewComponent,
422
455
  getSubscription,
423
456
  safeRequest,
424
457
  setup
package/dist/index.mjs CHANGED
@@ -29,6 +29,7 @@ var __objRest = (source, exclude) => {
29
29
 
30
30
  // src/index.ts
31
31
  import { formatInTimeZone } from "date-fns-tz";
32
+ import { createVNode as createVNode2 } from "vue";
32
33
 
33
34
  // src/Subscription.ts
34
35
  var Subscription = class _Subscription {
@@ -121,11 +122,11 @@ var Subscriptions = _Subscriptions;
121
122
  // src/ReactiveView.ts
122
123
  import ObjectManager from "@razaman2/object-manager";
123
124
  import DataManager from "@razaman2/data-manager";
124
- import { h, ref, reactive, watch, nextTick, getCurrentInstance, onMounted } from "vue";
125
+ import { h, ref, reactive, watch, nextTick, getCurrentInstance } from "vue";
125
126
 
126
127
  // package.json
127
128
  var name = "@razaman2/reactive-view";
128
- var version = "0.0.13";
129
+ var version = "0.0.15";
129
130
 
130
131
  // src/ReactiveView.ts
131
132
  var props = {
@@ -165,7 +166,7 @@ var setup = {
165
166
  var ReactiveView_default = {
166
167
  props: __spreadValues(__spreadValues({}, setup), props),
167
168
  setup(props2, context) {
168
- var _a, _b, _c, _d, _f;
169
+ var _a, _b, _c, _d, _e;
169
170
  const template = (vue, options2) => {
170
171
  var _a2, _b2, _c2;
171
172
  const vnode = context.slots.default ? h(
@@ -178,14 +179,17 @@ var ReactiveView_default = {
178
179
  textAlign: "center"
179
180
  }
180
181
  }, context.attrs), `${props2.modelName}: ${name}@${version}`);
181
- return (_c2 = (_b2 = (_a2 = context.slots).template) == null ? void 0 : _b2.call(_a2, { $vue: vue, vnode })) != null ? _c2 : vnode;
182
+ return (_c2 = (_b2 = (_a2 = context.slots).template) == null ? void 0 : _b2.call(_a2, { vue, options: options2, props: props2, context })) != null ? _c2 : vnode;
182
183
  };
183
184
  const isValid = ref(false);
185
+ const sync = ref(false);
186
+ const rendered = ref(false);
187
+ const component = ref((_a = getCurrentInstance()) == null ? void 0 : _a.proxy);
184
188
  const defaultData = props2.getDefaultData(
185
- Array.isArray(props2.state) ? (_a = props2.defaultData) != null ? _a : [] : (_b = props2.defaultData) != null ? _b : {}
189
+ Array.isArray(props2.state) ? (_b = props2.defaultData) != null ? _b : [] : (_c = props2.defaultData) != null ? _c : {}
186
190
  );
187
- const defaultType = Array.isArray(defaultData) ? [] : {};
188
- const state = reactive(DataManager.transform(props2.await ? defaultType : (_c = props2.state) != null ? _c : defaultType));
191
+ const type = Array.isArray(defaultData) ? [] : {};
192
+ const state = reactive(DataManager.transform(props2.await ? type : (_d = props2.state) != null ? _d : type));
189
193
  const config = {
190
194
  defaultData,
191
195
  data: state,
@@ -194,56 +198,69 @@ var ReactiveView_default = {
194
198
  notifications: props2.notifications,
195
199
  subscriptions: props2.subscriptions
196
200
  };
197
- const getState = props2.model ? typeof props2.model === "function" ? props2.model(config) : props2.model : new DataManager(config);
198
- const sync = ref(false);
199
- const rendered = ref(false);
201
+ const getState = new Proxy(props2.model ? typeof props2.model === "function" ? props2.model(config) : props2.model : new DataManager(config), {
202
+ get(target, property, receiver) {
203
+ var _a2, _b2;
204
+ const beforeSetData = (_b2 = (_a2 = context.attrs["onUpdate:modelState"]) == null ? void 0 : _a2.beforeSetData) != null ? _b2 : access(component).beforeSetData;
205
+ if (["setData", "replaceData"].includes(property) && typeof beforeSetData === "function") {
206
+ return (...params) => {
207
+ const type2 = Array.isArray(defaultData) ? [] : {};
208
+ beforeSetData(ObjectManager.on(type2).set(...params).get(), target);
209
+ };
210
+ } else {
211
+ return Reflect.get(target, property, receiver);
212
+ }
213
+ }
214
+ });
200
215
  const options = {
201
- parent: { self: getCurrentInstance().proxy },
202
- self: { template, isValid, getState }
216
+ parent: { self: component },
217
+ self: { template, getState, isValid }
203
218
  };
204
- const _e = (_d = props2.setup(options)) != null ? _d : options, { parent = {}, self = {} } = _e, rest = __objRest(_e, ["parent", "self"]);
205
- if (props2.await instanceof Promise) {
206
- nextTick(async () => {
207
- getState.replaceData(await props2.await);
208
- });
209
- }
210
- if (props2.defer instanceof Promise) {
211
- nextTick(async () => {
212
- var _a2;
213
- rendered.value = (_a2 = await props2.defer) != null ? _a2 : true;
214
- });
215
- } else {
216
- rendered.value = true;
217
- }
218
- if (context.attrs["onUpdate:modelState"]) {
219
- const config2 = typeof context.attrs["onUpdate:modelState"] === "function" ? { callback: context.attrs["onUpdate:modelState"] } : context.attrs["onUpdate:modelState"];
220
- onMounted(() => {
219
+ const _f = (_e = props2.setup(options)) != null ? _e : options, { parent = {}, self = {} } = _f, rest = __objRest(_f, ["parent", "self"]);
220
+ return ($vue) => {
221
+ var _a2, _b2;
222
+ if (props2.await instanceof Promise) {
223
+ nextTick(async () => {
224
+ getState.replaceData(await props2.await);
225
+ });
226
+ }
227
+ if (props2.defer instanceof Promise) {
228
+ nextTick(async () => {
229
+ var _a3;
230
+ rendered.value = (_a3 = await props2.defer) != null ? _a3 : true;
231
+ });
232
+ } else {
233
+ rendered.value = true;
234
+ }
235
+ if (context.attrs["onUpdate:modelState"]) {
236
+ const config2 = typeof context.attrs["onUpdate:modelState"] === "function" ? {
237
+ callback: context.attrs["onUpdate:modelState"]
238
+ } : (_a2 = context.attrs["onUpdate:modelState"]) != null ? _a2 : {};
221
239
  watch(() => ObjectManager.on(state).clone(), (after, before) => {
222
- var _a2;
223
- const beforeStateUpdate = (_a2 = config2.beforeStateUpdate) != null ? _a2 : access({ parent, self }).beforeStateUpdate;
240
+ var _a3;
224
241
  const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
242
+ const beforeStateUpdate = (_a3 = config2.beforeStateUpdate) != null ? _a3 : access({ parent, self }).beforeStateUpdate;
225
243
  if (sync.value) {
226
244
  sync.value = false;
227
- } else {
245
+ } else if (typeof config2.callback === "function") {
228
246
  config2.callback(beforeStateUpdate ? beforeStateUpdate(diff) : diff, getState);
229
247
  }
230
248
  }, config2.options);
231
- });
232
- }
233
- if (context.attrs["onUpdate:propsState"] || props2.sync) {
234
- const config2 = (_f = typeof context.attrs["onUpdate:propsState"] === "function" ? { callback: context.attrs["onUpdate:propsState"] } : context.attrs["onUpdate:propsState"]) != null ? _f : {};
235
- onMounted(() => {
249
+ }
250
+ if (context.attrs["onUpdate:propsState"] || props2.sync) {
251
+ const config2 = typeof context.attrs["onUpdate:propsState"] === "function" ? {
252
+ callback: context.attrs["onUpdate:propsState"]
253
+ } : (_b2 = context.attrs["onUpdate:propsState"]) != null ? _b2 : {};
236
254
  watch(() => ObjectManager.on(props2.state).clone(), (after, before) => {
255
+ const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
237
256
  if (props2.sync && typeof config2.callback !== "function") {
238
257
  getState.replaceData(after);
239
258
  } else if (typeof config2.callback === "function") {
240
- config2.callback({ before, after }, getState);
259
+ config2.callback(diff, getState);
241
260
  }
242
261
  sync.value = true;
243
262
  }, config2.options);
244
- });
245
- }
246
- return ($vue) => {
263
+ }
247
264
  const setup2 = { $vue, options: parent };
248
265
  while (setup2.options) {
249
266
  Object.defineProperties(setup2.$vue, Object.assign({
@@ -307,6 +324,20 @@ function getProps(props2, param2) {
307
324
  return props3;
308
325
  }, {}));
309
326
  }
327
+ function getReactiveViewComponent(component, options = {}) {
328
+ const model = (component2) => {
329
+ try {
330
+ return (component2.type || component2).props.hasOwnProperty("model");
331
+ } catch (e) {
332
+ return false;
333
+ }
334
+ };
335
+ const props2 = getProps(options, "setup");
336
+ const slots = typeof component === "function" ? component : () => {
337
+ return (component.type || component).setup ? createVNode2(component, component.setup ? {} : props2) : component;
338
+ };
339
+ return model(component) ? createVNode2(component, props2) : createVNode2(ReactiveView_default, props2, slots);
340
+ }
310
341
  function getDate(param1, param2) {
311
342
  var _a, _b;
312
343
  const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
@@ -382,6 +413,7 @@ export {
382
413
  src_default as default,
383
414
  getDate,
384
415
  getProps,
416
+ getReactiveViewComponent,
385
417
  getSubscription,
386
418
  safeRequest,
387
419
  setup
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@razaman2/reactive-view",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
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",