@razaman2/reactive-view 0.0.22 → 0.0.23

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
@@ -41,10 +41,7 @@ declare const setup: {
41
41
  };
42
42
  declare const _default: {
43
43
  props: {
44
- setup: {
45
- type: FunctionConstructor;
46
- default: (parent?: {}) => {};
47
- };
44
+ setup: {};
48
45
  ReactiveView: {
49
46
  default: boolean;
50
47
  };
@@ -72,6 +69,10 @@ declare const _default: {
72
69
  type: StringConstructor;
73
70
  default: string;
74
71
  };
72
+ debug: {
73
+ type: BooleanConstructor;
74
+ default: boolean;
75
+ };
75
76
  };
76
77
  setup(props: Record<string, any>, context: SetupContext): (vue: ComponentPublicInstance) => any;
77
78
  };
package/dist/index.d.ts CHANGED
@@ -41,10 +41,7 @@ declare const setup: {
41
41
  };
42
42
  declare const _default: {
43
43
  props: {
44
- setup: {
45
- type: FunctionConstructor;
46
- default: (parent?: {}) => {};
47
- };
44
+ setup: {};
48
45
  ReactiveView: {
49
46
  default: boolean;
50
47
  };
@@ -72,6 +69,10 @@ declare const _default: {
72
69
  type: StringConstructor;
73
70
  default: string;
74
71
  };
72
+ debug: {
73
+ type: BooleanConstructor;
74
+ default: boolean;
75
+ };
75
76
  };
76
77
  setup(props: Record<string, any>, context: SetupContext): (vue: ComponentPublicInstance) => any;
77
78
  };
package/dist/index.js CHANGED
@@ -159,7 +159,7 @@ var import_vue = require("vue");
159
159
 
160
160
  // package.json
161
161
  var name = "@razaman2/reactive-view";
162
- var version = "0.0.22";
162
+ var version = "0.0.23";
163
163
 
164
164
  // src/ReactiveView.ts
165
165
  var setup = {
@@ -168,7 +168,7 @@ var setup = {
168
168
  };
169
169
  var ReactiveView_default = {
170
170
  props: {
171
- setup,
171
+ setup: {},
172
172
  ReactiveView: {
173
173
  default: true
174
174
  },
@@ -197,33 +197,37 @@ var ReactiveView_default = {
197
197
  modelName: {
198
198
  type: String,
199
199
  default: "ReactiveView"
200
+ },
201
+ debug: {
202
+ type: Boolean,
203
+ default: false
200
204
  }
201
205
  },
202
206
  setup(props, context) {
203
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
204
- const template = (vue, component2) => {
205
- var _a2, _b2, _c2;
206
- const params = { vue, component: component2, props, context };
207
- const vnode = context.slots.default ? (0, import_vue.createVNode)(
207
+ var _a, _b, _c, _d, _e, _f, _g;
208
+ const template = (component2, vue) => {
209
+ return context.slots.default ? (0, import_vue.createVNode)(
208
210
  "div",
209
211
  context.attrs,
210
- context.slots.default(params)
212
+ context.slots.default({ vue, component: component2, props, context })
211
213
  ) : (0, import_vue.createVNode)("div", __spreadValues({
212
214
  style: {
213
215
  color: "red",
214
216
  textAlign: "center"
215
217
  }
216
218
  }, context.attrs), `${props.modelName}: ${name}@${version}`);
217
- return (_c2 = (_b2 = (_a2 = context.slots).template) == null ? void 0 : _b2.call(_a2, params)) != null ? _c2 : vnode;
218
219
  };
219
220
  const isValid = (0, import_vue.ref)(false);
220
221
  const ready = (0, import_vue.ref)(false);
221
222
  const instance = (0, import_vue.getCurrentInstance)();
222
223
  const deferred = (0, import_vue.ref)(typeof props.defer === "function" ? props.defer() : props.defer);
223
224
  const state = typeof props.data === "function" ? props.data() : props.data;
224
- const isAsyncData = state instanceof Promise;
225
- if (isAsyncData && !((_a = instance.vnode.props) == null ? void 0 : _a.hasOwnProperty("defaultData"))) {
226
- throw new Error("[ReactiveView]: defaultData is required for async data.");
225
+ const async = state instanceof Promise;
226
+ if (props.debug) {
227
+ console.log("[ReactiveView]:", { props, context });
228
+ }
229
+ if (async && !((_a = instance.vnode.props) == null ? void 0 : _a.hasOwnProperty("defaultData"))) {
230
+ console.error("[ReactiveView]: defaultData is required for async data.");
227
231
  }
228
232
  if (props.loading && !props.defer) {
229
233
  console.warn("[ReactiveView]: loading prop should be used with defer prop.");
@@ -232,7 +236,7 @@ var ReactiveView_default = {
232
236
  ((_b = instance.vnode.props) == null ? void 0 : _b.hasOwnProperty("defaultData")) ? instance.vnode.props.defaultData : typeof ((_c = instance.vnode.props) == null ? void 0 : _c.data) === "object" ? Array.isArray(instance.vnode.props.data) ? [] : {} : ((_d = instance.vnode.props) == null ? void 0 : _d.hasOwnProperty("data")) ? (_e = instance.vnode.props) == null ? void 0 : _e.data : {}
233
237
  );
234
238
  const datatype = Array.isArray(defaultData) ? [] : {};
235
- const data = isAsyncData ? datatype : ((_f = instance.vnode.props) == null ? void 0 : _f.hasOwnProperty("data")) ? state : datatype;
239
+ const data = async ? datatype : ((_f = instance.vnode.props) == null ? void 0 : _f.hasOwnProperty("data")) ? state : datatype;
236
240
  const config = {
237
241
  name: props.modelName,
238
242
  defaultData: import_object_manager.default.on(defaultData).clone(),
@@ -248,7 +252,9 @@ var ReactiveView_default = {
248
252
  var _a2;
249
253
  const beforeSetData = (_a2 = access(component).beforeSetData) != null ? _a2 : props.beforeSetData;
250
254
  if (typeof beforeSetData === "function") {
251
- beforeSetData(import_object_manager.default.on(datatype).set(...params).get(), target);
255
+ const after = import_object_manager.default.on(datatype).set(...params).get();
256
+ const before = target.getData();
257
+ beforeSetData({ before, after }, target);
252
258
  } else {
253
259
  target[key](...params);
254
260
  }
@@ -259,12 +265,30 @@ var ReactiveView_default = {
259
265
  }
260
266
  }
261
267
  });
262
- if (isAsyncData) {
263
- (0, import_vue.nextTick)(async () => {
264
- model.replaceData(await state);
268
+ const watchDataProp = (dataProp) => {
269
+ var _a2;
270
+ const config2 = typeof context.attrs["onUpdate:data"] === "function" ? {
271
+ callback: context.attrs["onUpdate:data"]
272
+ } : (_a2 = context.attrs["onUpdate:data"]) != null ? _a2 : {};
273
+ console.log("log dataProp:", dataProp);
274
+ (0, import_vue.watch)(typeof dataProp === "function" || (0, import_vue.isRef)(dataProp) ? dataProp : () => dataProp, (after, before) => {
275
+ var _a3;
276
+ const diff = { before: import_object_manager.default.on(before).get(), after: import_object_manager.default.on(after).get() };
277
+ if (typeof config2.callback === "function") {
278
+ model.replaceData((_a3 = config2.callback(diff, model)) != null ? _a3 : after);
279
+ } else {
280
+ model.replaceData(after);
281
+ }
282
+ }, config2.options);
283
+ };
284
+ if (async) {
285
+ setTimeout(async () => {
286
+ watchDataProp(await state);
265
287
  });
288
+ } else {
289
+ watchDataProp(state);
266
290
  }
267
- (0, import_vue.nextTick)(async () => {
291
+ setTimeout(async () => {
268
292
  var _a2;
269
293
  ready.value = (_a2 = await deferred.value) != null ? _a2 : true;
270
294
  });
@@ -277,29 +301,29 @@ var ReactiveView_default = {
277
301
  config2.callback(diff, model);
278
302
  }, config2.options);
279
303
  }
280
- if ((_h = context.attrs["onUpdate:data"]) != null ? _h : true) {
281
- const config2 = typeof context.attrs["onUpdate:data"] === "function" ? {
282
- callback: context.attrs["onUpdate:data"]
283
- } : (_i = context.attrs["onUpdate:data"]) != null ? _i : {};
284
- (0, import_vue.watch)(async () => typeof props.data === "function" ? await props.data() : await props.data, async (after, before) => {
285
- const diff = { before: import_object_manager.default.on(await before).get(), after: import_object_manager.default.on(await after).get() };
286
- if (typeof config2.callback === "function") {
287
- config2.callback(diff, model);
288
- } else {
289
- model.replaceData(await after);
290
- }
291
- }, config2.options);
292
- }
293
304
  const component = (0, import_vue.ref)({ parent: { self: instance.proxy }, self: { template, model, isValid } });
294
- if (typeof props.setup === "function") {
295
- component.value = props.setup(component.value, component);
296
- }
297
- if (props.instance) {
298
- props.instance.value = component.value;
305
+ if (access(component).ReactiveView) {
306
+ component.value = [access(component)].reduce((options, parent) => {
307
+ var _a2;
308
+ while (parent) {
309
+ if (typeof parent.setup === "function") {
310
+ options = { parent: options, self: (_a2 = parent.setup(component, options)) != null ? _a2 : {} };
311
+ if (access(parent.$parent).ReactiveView) {
312
+ break;
313
+ } else {
314
+ parent = parent.$parent;
315
+ }
316
+ } else {
317
+ break;
318
+ }
319
+ }
320
+ return options;
321
+ }, component.value);
299
322
  }
323
+ props.instance.value = component.value;
300
324
  return (vue) => {
301
325
  if (ready.value) {
302
- return access(component).template(vue, component);
326
+ return access(component).template(component, vue);
303
327
  } else {
304
328
  return props.loading;
305
329
  }
@@ -394,7 +418,11 @@ function access(view = {}, alternative) {
394
418
  component.tree = "parent" in component.tree && component.tree.parent;
395
419
  }
396
420
  } while (component.tree);
397
- return alternative;
421
+ try {
422
+ return new alternative();
423
+ } catch (e) {
424
+ return alternative;
425
+ }
398
426
  }
399
427
  });
400
428
  };
package/dist/index.mjs CHANGED
@@ -110,16 +110,16 @@ _Subscriptions.subscriptions = _Subscriptions.create();
110
110
  var Subscriptions = _Subscriptions;
111
111
 
112
112
  // src/index.ts
113
- import { createVNode as createVNode2, isRef } from "vue";
113
+ import { createVNode as createVNode2, isRef as isRef2 } from "vue";
114
114
 
115
115
  // src/ReactiveView.ts
116
116
  import ObjectManager from "@razaman2/object-manager";
117
117
  import DataManager from "@razaman2/data-manager";
118
- import { ref, reactive, watch, nextTick, createVNode, getCurrentInstance } from "vue";
118
+ import { ref, reactive, watch, isRef, createVNode, getCurrentInstance } from "vue";
119
119
 
120
120
  // package.json
121
121
  var name = "@razaman2/reactive-view";
122
- var version = "0.0.22";
122
+ var version = "0.0.23";
123
123
 
124
124
  // src/ReactiveView.ts
125
125
  var setup = {
@@ -128,7 +128,7 @@ var setup = {
128
128
  };
129
129
  var ReactiveView_default = {
130
130
  props: {
131
- setup,
131
+ setup: {},
132
132
  ReactiveView: {
133
133
  default: true
134
134
  },
@@ -157,33 +157,37 @@ var ReactiveView_default = {
157
157
  modelName: {
158
158
  type: String,
159
159
  default: "ReactiveView"
160
+ },
161
+ debug: {
162
+ type: Boolean,
163
+ default: false
160
164
  }
161
165
  },
162
166
  setup(props, context) {
163
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
164
- const template = (vue, component2) => {
165
- var _a2, _b2, _c2;
166
- const params = { vue, component: component2, props, context };
167
- const vnode = context.slots.default ? createVNode(
167
+ var _a, _b, _c, _d, _e, _f, _g;
168
+ const template = (component2, vue) => {
169
+ return context.slots.default ? createVNode(
168
170
  "div",
169
171
  context.attrs,
170
- context.slots.default(params)
172
+ context.slots.default({ vue, component: component2, props, context })
171
173
  ) : createVNode("div", __spreadValues({
172
174
  style: {
173
175
  color: "red",
174
176
  textAlign: "center"
175
177
  }
176
178
  }, context.attrs), `${props.modelName}: ${name}@${version}`);
177
- return (_c2 = (_b2 = (_a2 = context.slots).template) == null ? void 0 : _b2.call(_a2, params)) != null ? _c2 : vnode;
178
179
  };
179
180
  const isValid = ref(false);
180
181
  const ready = ref(false);
181
182
  const instance = getCurrentInstance();
182
183
  const deferred = ref(typeof props.defer === "function" ? props.defer() : props.defer);
183
184
  const state = typeof props.data === "function" ? props.data() : props.data;
184
- const isAsyncData = state instanceof Promise;
185
- if (isAsyncData && !((_a = instance.vnode.props) == null ? void 0 : _a.hasOwnProperty("defaultData"))) {
186
- throw new Error("[ReactiveView]: defaultData is required for async data.");
185
+ const async = state instanceof Promise;
186
+ if (props.debug) {
187
+ console.log("[ReactiveView]:", { props, context });
188
+ }
189
+ if (async && !((_a = instance.vnode.props) == null ? void 0 : _a.hasOwnProperty("defaultData"))) {
190
+ console.error("[ReactiveView]: defaultData is required for async data.");
187
191
  }
188
192
  if (props.loading && !props.defer) {
189
193
  console.warn("[ReactiveView]: loading prop should be used with defer prop.");
@@ -192,7 +196,7 @@ var ReactiveView_default = {
192
196
  ((_b = instance.vnode.props) == null ? void 0 : _b.hasOwnProperty("defaultData")) ? instance.vnode.props.defaultData : typeof ((_c = instance.vnode.props) == null ? void 0 : _c.data) === "object" ? Array.isArray(instance.vnode.props.data) ? [] : {} : ((_d = instance.vnode.props) == null ? void 0 : _d.hasOwnProperty("data")) ? (_e = instance.vnode.props) == null ? void 0 : _e.data : {}
193
197
  );
194
198
  const datatype = Array.isArray(defaultData) ? [] : {};
195
- const data = isAsyncData ? datatype : ((_f = instance.vnode.props) == null ? void 0 : _f.hasOwnProperty("data")) ? state : datatype;
199
+ const data = async ? datatype : ((_f = instance.vnode.props) == null ? void 0 : _f.hasOwnProperty("data")) ? state : datatype;
196
200
  const config = {
197
201
  name: props.modelName,
198
202
  defaultData: ObjectManager.on(defaultData).clone(),
@@ -208,7 +212,9 @@ var ReactiveView_default = {
208
212
  var _a2;
209
213
  const beforeSetData = (_a2 = access(component).beforeSetData) != null ? _a2 : props.beforeSetData;
210
214
  if (typeof beforeSetData === "function") {
211
- beforeSetData(ObjectManager.on(datatype).set(...params).get(), target);
215
+ const after = ObjectManager.on(datatype).set(...params).get();
216
+ const before = target.getData();
217
+ beforeSetData({ before, after }, target);
212
218
  } else {
213
219
  target[key](...params);
214
220
  }
@@ -219,12 +225,30 @@ var ReactiveView_default = {
219
225
  }
220
226
  }
221
227
  });
222
- if (isAsyncData) {
223
- nextTick(async () => {
224
- model.replaceData(await state);
228
+ const watchDataProp = (dataProp) => {
229
+ var _a2;
230
+ const config2 = typeof context.attrs["onUpdate:data"] === "function" ? {
231
+ callback: context.attrs["onUpdate:data"]
232
+ } : (_a2 = context.attrs["onUpdate:data"]) != null ? _a2 : {};
233
+ console.log("log dataProp:", dataProp);
234
+ watch(typeof dataProp === "function" || isRef(dataProp) ? dataProp : () => dataProp, (after, before) => {
235
+ var _a3;
236
+ const diff = { before: ObjectManager.on(before).get(), after: ObjectManager.on(after).get() };
237
+ if (typeof config2.callback === "function") {
238
+ model.replaceData((_a3 = config2.callback(diff, model)) != null ? _a3 : after);
239
+ } else {
240
+ model.replaceData(after);
241
+ }
242
+ }, config2.options);
243
+ };
244
+ if (async) {
245
+ setTimeout(async () => {
246
+ watchDataProp(await state);
225
247
  });
248
+ } else {
249
+ watchDataProp(state);
226
250
  }
227
- nextTick(async () => {
251
+ setTimeout(async () => {
228
252
  var _a2;
229
253
  ready.value = (_a2 = await deferred.value) != null ? _a2 : true;
230
254
  });
@@ -237,29 +261,29 @@ var ReactiveView_default = {
237
261
  config2.callback(diff, model);
238
262
  }, config2.options);
239
263
  }
240
- if ((_h = context.attrs["onUpdate:data"]) != null ? _h : true) {
241
- const config2 = typeof context.attrs["onUpdate:data"] === "function" ? {
242
- callback: context.attrs["onUpdate:data"]
243
- } : (_i = context.attrs["onUpdate:data"]) != null ? _i : {};
244
- watch(async () => typeof props.data === "function" ? await props.data() : await props.data, async (after, before) => {
245
- const diff = { before: ObjectManager.on(await before).get(), after: ObjectManager.on(await after).get() };
246
- if (typeof config2.callback === "function") {
247
- config2.callback(diff, model);
248
- } else {
249
- model.replaceData(await after);
250
- }
251
- }, config2.options);
252
- }
253
264
  const component = ref({ parent: { self: instance.proxy }, self: { template, model, isValid } });
254
- if (typeof props.setup === "function") {
255
- component.value = props.setup(component.value, component);
256
- }
257
- if (props.instance) {
258
- props.instance.value = component.value;
265
+ if (access(component).ReactiveView) {
266
+ component.value = [access(component)].reduce((options, parent) => {
267
+ var _a2;
268
+ while (parent) {
269
+ if (typeof parent.setup === "function") {
270
+ options = { parent: options, self: (_a2 = parent.setup(component, options)) != null ? _a2 : {} };
271
+ if (access(parent.$parent).ReactiveView) {
272
+ break;
273
+ } else {
274
+ parent = parent.$parent;
275
+ }
276
+ } else {
277
+ break;
278
+ }
279
+ }
280
+ return options;
281
+ }, component.value);
259
282
  }
283
+ props.instance.value = component.value;
260
284
  return (vue) => {
261
285
  if (ready.value) {
262
- return access(component).template(vue, component);
286
+ return access(component).template(component, vue);
263
287
  } else {
264
288
  return props.loading;
265
289
  }
@@ -354,13 +378,17 @@ function access(view = {}, alternative) {
354
378
  component.tree = "parent" in component.tree && component.tree.parent;
355
379
  }
356
380
  } while (component.tree);
357
- return alternative;
381
+ try {
382
+ return new alternative();
383
+ } catch (e) {
384
+ return alternative;
385
+ }
358
386
  }
359
387
  });
360
388
  };
361
389
  try {
362
390
  const component = typeof view === "function" ? view() : view;
363
- const ref2 = isRef(component) ? component.value : component;
391
+ const ref2 = isRef2(component) ? component.value : component;
364
392
  return resolve(ref2.ReactiveView ? access(ref2.instance) : ref2);
365
393
  } catch (e) {
366
394
  return resolve(view);
package/package.json CHANGED
@@ -1,45 +1,45 @@
1
- {
2
- "name": "@razaman2/reactive-view",
3
- "version": "0.0.22",
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
- "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
- "types": "dist/index.d.ts",
8
- "scripts": {
9
- "prepublishOnly": "npm run build",
10
- "build": "tsup src/index.ts --format cjs,esm --dts",
11
- "lint": "tsc",
12
- "test": "cd tests/vue-ts && npm run dev"
13
- },
14
- "keywords": [
15
- "vue",
16
- "vue-helper",
17
- "reactive-view",
18
- "vue-class-component",
19
- "reactive-ui"
20
- ],
21
- "author": "razaman2",
22
- "license": "MIT",
23
- "dependencies": {
24
- "@razaman2/data-manager": "^3.2.11",
25
- "@razaman2/object-manager": "^3.4.2",
26
- "date-fns": "^4.1.0",
27
- "date-fns-tz": "^3.2.0",
28
- "uuid": "^11.1.0"
29
- },
30
- "peerDependencies": {
31
- "vue": "^3.5.13"
32
- },
33
- "devDependencies": {
34
- "@types/uuid": "^10.0.0",
35
- "tsup": "^8.4.0",
36
- "typescript": "^5.8.2",
37
- "vitest": "^3.1.1"
38
- },
39
- "publishConfig": {
40
- "access": "public"
41
- },
42
- "files": [
43
- "dist"
44
- ]
45
- }
1
+ {
2
+ "name": "@razaman2/reactive-view",
3
+ "version": "0.0.23",
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
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "prepublishOnly": "npm run build",
10
+ "build": "tsup src/index.ts --format cjs,esm --dts",
11
+ "lint": "tsc",
12
+ "test": "cd tests/vue-ts && npm run dev"
13
+ },
14
+ "keywords": [
15
+ "vue",
16
+ "vue-helper",
17
+ "reactive-view",
18
+ "vue-class-component",
19
+ "reactive-ui"
20
+ ],
21
+ "author": "razaman2",
22
+ "license": "MIT",
23
+ "dependencies": {
24
+ "@razaman2/data-manager": "^3.2.11",
25
+ "@razaman2/object-manager": "^3.4.2",
26
+ "date-fns": "^4.1.0",
27
+ "date-fns-tz": "^3.2.0",
28
+ "uuid": "^11.1.0"
29
+ },
30
+ "peerDependencies": {
31
+ "vue": "^3.5.13"
32
+ },
33
+ "devDependencies": {
34
+ "@types/uuid": "^10.0.0",
35
+ "tsup": "^8.4.0",
36
+ "typescript": "^5.8.3",
37
+ "vitest": "^3.1.1"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "files": [
43
+ "dist"
44
+ ]
45
+ }