@razaman2/reactive-view 0.0.13 → 0.0.14

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.14";
166
168
 
167
169
  // src/ReactiveView.ts
168
170
  var props = {
@@ -202,27 +204,29 @@ 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;
206
- const template = (vue, options2) => {
207
+ var _a, _b, _c;
208
+ const template = (vue, options) => {
207
209
  var _a2, _b2, _c2;
208
210
  const vnode = context.slots.default ? (0, import_vue.h)(
209
211
  "div",
210
212
  context.attrs,
211
- context.slots.default({ vue, options: options2, props: props2, context })
213
+ context.slots.default({ vue, options, props: props2, context })
212
214
  ) : (0, import_vue.h)("div", __spreadValues({
213
215
  style: {
214
216
  color: "red",
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, 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);
221
225
  const defaultData = props2.getDefaultData(
222
226
  Array.isArray(props2.state) ? (_a = props2.defaultData) != null ? _a : [] : (_b = props2.defaultData) != null ? _b : {}
223
227
  );
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));
228
+ const type = Array.isArray(defaultData) ? [] : {};
229
+ const state = (0, import_vue.reactive)(import_data_manager.default.transform(props2.await ? type : (_c = props2.state) != null ? _c : type));
226
230
  const config = {
227
231
  defaultData,
228
232
  data: state,
@@ -231,56 +235,69 @@ var ReactiveView_default = {
231
235
  notifications: props2.notifications,
232
236
  subscriptions: props2.subscriptions
233
237
  };
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);
237
- const options = {
238
- parent: { self: (0, import_vue.getCurrentInstance)().proxy },
239
- self: { template, isValid, getState }
240
- };
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;
238
+ return ($vue) => {
239
+ var _a2, _c2, _d;
240
+ const getState = new Proxy(props2.model ? typeof props2.model === "function" ? props2.model(config) : props2.model : new import_data_manager.default(config), {
241
+ get(target, property, receiver) {
242
+ var _a3, _b3;
243
+ const beforeSetData = (_b3 = (_a3 = context.attrs["onUpdate:modelState"]) == null ? void 0 : _a3.beforeSetData) != null ? _b3 : access($vue).beforeSetData;
244
+ if (["setData", "replaceData"].includes(property) && typeof beforeSetData === "function") {
245
+ return (...params) => {
246
+ const type2 = Array.isArray(defaultData) ? [] : {};
247
+ beforeSetData(import_object_manager.default.on(type2).set(...params).get(), target);
248
+ };
249
+ } else {
250
+ return Reflect.get(target, property, receiver);
251
+ }
252
+ }
251
253
  });
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)(() => {
254
+ if (props2.await instanceof Promise) {
255
+ (0, import_vue.nextTick)(async () => {
256
+ getState.replaceData(await props2.await);
257
+ });
258
+ }
259
+ if (props2.defer instanceof Promise) {
260
+ (0, import_vue.nextTick)(async () => {
261
+ var _a3;
262
+ rendered.value = (_a3 = await props2.defer) != null ? _a3 : true;
263
+ });
264
+ } else {
265
+ rendered.value = true;
266
+ }
267
+ const options = {
268
+ parent: { self: $vue },
269
+ self: { template, getState, isValid }
270
+ };
271
+ const _b2 = (_a2 = props2.setup(options)) != null ? _a2 : options, { parent = {}, self = {} } = _b2, rest = __objRest(_b2, ["parent", "self"]);
272
+ if (context.attrs["onUpdate:modelState"]) {
273
+ const config2 = typeof context.attrs["onUpdate:modelState"] === "function" ? {
274
+ callback: context.attrs["onUpdate:modelState"]
275
+ } : (_c2 = context.attrs["onUpdate:modelState"]) != null ? _c2 : {};
258
276
  (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;
277
+ var _a3;
261
278
  const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
279
+ const beforeStateUpdate = (_a3 = config2.beforeStateUpdate) != null ? _a3 : access({ parent, self }).beforeStateUpdate;
262
280
  if (sync.value) {
263
281
  sync.value = false;
264
- } else {
282
+ } else if (typeof config2.callback === "function") {
265
283
  config2.callback(beforeStateUpdate ? beforeStateUpdate(diff) : diff, getState);
266
284
  }
267
285
  }, 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)(() => {
286
+ }
287
+ if (context.attrs["onUpdate:propsState"] || props2.sync) {
288
+ const config2 = typeof context.attrs["onUpdate:propsState"] === "function" ? {
289
+ callback: context.attrs["onUpdate:propsState"]
290
+ } : (_d = context.attrs["onUpdate:propsState"]) != null ? _d : {};
273
291
  (0, import_vue.watch)(() => import_object_manager.default.on(props2.state).clone(), (after, before) => {
292
+ const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
274
293
  if (props2.sync && typeof config2.callback !== "function") {
275
294
  getState.replaceData(after);
276
295
  } else if (typeof config2.callback === "function") {
277
- config2.callback({ before, after }, getState);
296
+ config2.callback(diff, getState);
278
297
  }
279
298
  sync.value = true;
280
299
  }, config2.options);
281
- });
282
- }
283
- return ($vue) => {
300
+ }
284
301
  const setup2 = { $vue, options: parent };
285
302
  while (setup2.options) {
286
303
  Object.defineProperties(setup2.$vue, Object.assign({
@@ -344,6 +361,20 @@ function getProps(props2, param2) {
344
361
  return props3;
345
362
  }, {}));
346
363
  }
364
+ function getReactiveViewComponent(component, options = {}) {
365
+ const model = (component2) => {
366
+ try {
367
+ return (component2.type || component2).props.hasOwnProperty("model");
368
+ } catch (e) {
369
+ return false;
370
+ }
371
+ };
372
+ const props2 = getProps(options, "setup");
373
+ const slots = typeof component === "function" ? component : () => {
374
+ return (component.type || component).setup ? (0, import_vue2.createVNode)(component, component.setup ? {} : props2) : component;
375
+ };
376
+ return model(component) ? (0, import_vue2.createVNode)(component, props2) : (0, import_vue2.createVNode)(ReactiveView_default, props2, slots);
377
+ }
347
378
  function getDate(param1, param2) {
348
379
  var _a, _b;
349
380
  const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
@@ -419,6 +450,7 @@ function getSubscription() {
419
450
  access,
420
451
  getDate,
421
452
  getProps,
453
+ getReactiveViewComponent,
422
454
  getSubscription,
423
455
  safeRequest,
424
456
  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 } 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 } 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.14";
129
130
 
130
131
  // src/ReactiveView.ts
131
132
  var props = {
@@ -165,27 +166,29 @@ 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
- const template = (vue, options2) => {
169
+ var _a, _b, _c;
170
+ const template = (vue, options) => {
170
171
  var _a2, _b2, _c2;
171
172
  const vnode = context.slots.default ? h(
172
173
  "div",
173
174
  context.attrs,
174
- context.slots.default({ vue, options: options2, props: props2, context })
175
+ context.slots.default({ vue, options, props: props2, context })
175
176
  ) : h("div", __spreadValues({
176
177
  style: {
177
178
  color: "red",
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, props: props2, context })) != null ? _c2 : vnode;
182
183
  };
183
184
  const isValid = ref(false);
185
+ const sync = ref(false);
186
+ const rendered = ref(false);
184
187
  const defaultData = props2.getDefaultData(
185
188
  Array.isArray(props2.state) ? (_a = props2.defaultData) != null ? _a : [] : (_b = props2.defaultData) != null ? _b : {}
186
189
  );
187
- const defaultType = Array.isArray(defaultData) ? [] : {};
188
- const state = reactive(DataManager.transform(props2.await ? defaultType : (_c = props2.state) != null ? _c : defaultType));
190
+ const type = Array.isArray(defaultData) ? [] : {};
191
+ const state = reactive(DataManager.transform(props2.await ? type : (_c = props2.state) != null ? _c : type));
189
192
  const config = {
190
193
  defaultData,
191
194
  data: state,
@@ -194,56 +197,69 @@ var ReactiveView_default = {
194
197
  notifications: props2.notifications,
195
198
  subscriptions: props2.subscriptions
196
199
  };
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);
200
- const options = {
201
- parent: { self: getCurrentInstance().proxy },
202
- self: { template, isValid, getState }
203
- };
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;
200
+ return ($vue) => {
201
+ var _a2, _c2, _d;
202
+ const getState = new Proxy(props2.model ? typeof props2.model === "function" ? props2.model(config) : props2.model : new DataManager(config), {
203
+ get(target, property, receiver) {
204
+ var _a3, _b3;
205
+ const beforeSetData = (_b3 = (_a3 = context.attrs["onUpdate:modelState"]) == null ? void 0 : _a3.beforeSetData) != null ? _b3 : access($vue).beforeSetData;
206
+ if (["setData", "replaceData"].includes(property) && typeof beforeSetData === "function") {
207
+ return (...params) => {
208
+ const type2 = Array.isArray(defaultData) ? [] : {};
209
+ beforeSetData(ObjectManager.on(type2).set(...params).get(), target);
210
+ };
211
+ } else {
212
+ return Reflect.get(target, property, receiver);
213
+ }
214
+ }
214
215
  });
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(() => {
216
+ if (props2.await instanceof Promise) {
217
+ nextTick(async () => {
218
+ getState.replaceData(await props2.await);
219
+ });
220
+ }
221
+ if (props2.defer instanceof Promise) {
222
+ nextTick(async () => {
223
+ var _a3;
224
+ rendered.value = (_a3 = await props2.defer) != null ? _a3 : true;
225
+ });
226
+ } else {
227
+ rendered.value = true;
228
+ }
229
+ const options = {
230
+ parent: { self: $vue },
231
+ self: { template, getState, isValid }
232
+ };
233
+ const _b2 = (_a2 = props2.setup(options)) != null ? _a2 : options, { parent = {}, self = {} } = _b2, rest = __objRest(_b2, ["parent", "self"]);
234
+ if (context.attrs["onUpdate:modelState"]) {
235
+ const config2 = typeof context.attrs["onUpdate:modelState"] === "function" ? {
236
+ callback: context.attrs["onUpdate:modelState"]
237
+ } : (_c2 = context.attrs["onUpdate:modelState"]) != null ? _c2 : {};
221
238
  watch(() => ObjectManager.on(state).clone(), (after, before) => {
222
- var _a2;
223
- const beforeStateUpdate = (_a2 = config2.beforeStateUpdate) != null ? _a2 : access({ parent, self }).beforeStateUpdate;
239
+ var _a3;
224
240
  const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
241
+ const beforeStateUpdate = (_a3 = config2.beforeStateUpdate) != null ? _a3 : access({ parent, self }).beforeStateUpdate;
225
242
  if (sync.value) {
226
243
  sync.value = false;
227
- } else {
244
+ } else if (typeof config2.callback === "function") {
228
245
  config2.callback(beforeStateUpdate ? beforeStateUpdate(diff) : diff, getState);
229
246
  }
230
247
  }, 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(() => {
248
+ }
249
+ if (context.attrs["onUpdate:propsState"] || props2.sync) {
250
+ const config2 = typeof context.attrs["onUpdate:propsState"] === "function" ? {
251
+ callback: context.attrs["onUpdate:propsState"]
252
+ } : (_d = context.attrs["onUpdate:propsState"]) != null ? _d : {};
236
253
  watch(() => ObjectManager.on(props2.state).clone(), (after, before) => {
254
+ const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
237
255
  if (props2.sync && typeof config2.callback !== "function") {
238
256
  getState.replaceData(after);
239
257
  } else if (typeof config2.callback === "function") {
240
- config2.callback({ before, after }, getState);
258
+ config2.callback(diff, getState);
241
259
  }
242
260
  sync.value = true;
243
261
  }, config2.options);
244
- });
245
- }
246
- return ($vue) => {
262
+ }
247
263
  const setup2 = { $vue, options: parent };
248
264
  while (setup2.options) {
249
265
  Object.defineProperties(setup2.$vue, Object.assign({
@@ -307,6 +323,20 @@ function getProps(props2, param2) {
307
323
  return props3;
308
324
  }, {}));
309
325
  }
326
+ function getReactiveViewComponent(component, options = {}) {
327
+ const model = (component2) => {
328
+ try {
329
+ return (component2.type || component2).props.hasOwnProperty("model");
330
+ } catch (e) {
331
+ return false;
332
+ }
333
+ };
334
+ const props2 = getProps(options, "setup");
335
+ const slots = typeof component === "function" ? component : () => {
336
+ return (component.type || component).setup ? createVNode(component, component.setup ? {} : props2) : component;
337
+ };
338
+ return model(component) ? createVNode(component, props2) : createVNode(ReactiveView_default, props2, slots);
339
+ }
310
340
  function getDate(param1, param2) {
311
341
  var _a, _b;
312
342
  const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
@@ -382,6 +412,7 @@ export {
382
412
  src_default as default,
383
413
  getDate,
384
414
  getProps,
415
+ getReactiveViewComponent,
385
416
  getSubscription,
386
417
  safeRequest,
387
418
  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.14",
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",