@razaman2/reactive-view 0.1.0-beta.1 → 0.1.0-beta.3

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
@@ -16,6 +16,12 @@ type SubscriptionItem = {
16
16
  handler: Function;
17
17
  data?: any;
18
18
  };
19
+ type PropType = {
20
+ default: any;
21
+ required: boolean;
22
+ validator: ((value: any) => boolean);
23
+ type: any | Array<any>;
24
+ };
19
25
  type PropExclusions = Array<string> | string;
20
26
 
21
27
  declare class Subscription {
@@ -118,6 +124,11 @@ declare function useSubscription(): {
118
124
  subscriptions: any[];
119
125
  subscription: Subscription;
120
126
  };
127
+ declare const Props: ({ default: value, type, validator, required }?: Partial<PropType>) => {
128
+ required: boolean | undefined;
129
+ validator: (value: any) => boolean;
130
+ default?: vue.Ref<any, any> | undefined;
131
+ };
121
132
  declare function StyleParser(styles?: Array<string> | Record<string, boolean> | string): {};
122
133
  declare function MergeStyles(...params: any): any;
123
134
  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>;
@@ -134,4 +145,4 @@ declare const getData: (component: any, path: number | string, alternative: any)
134
145
  declare const setData: (component: any, data: any, path?: string) => any;
135
146
  declare const dataPath: (component: any, path: string | number) => any;
136
147
 
137
- export { MergeStyles, StyleParser, access, dataPath, _default as default, defineReactiveView, extendVnode, getData, getDate, getProps, getReactiveViewComponent, safeRequest, setData, setup, showComponent, useSubscription };
148
+ export { MergeStyles, Props, StyleParser, access, dataPath, _default as default, defineReactiveView, extendVnode, getData, getDate, getProps, getReactiveViewComponent, safeRequest, setData, setup, showComponent, useSubscription };
package/dist/index.d.ts CHANGED
@@ -16,6 +16,12 @@ type SubscriptionItem = {
16
16
  handler: Function;
17
17
  data?: any;
18
18
  };
19
+ type PropType = {
20
+ default: any;
21
+ required: boolean;
22
+ validator: ((value: any) => boolean);
23
+ type: any | Array<any>;
24
+ };
19
25
  type PropExclusions = Array<string> | string;
20
26
 
21
27
  declare class Subscription {
@@ -118,6 +124,11 @@ declare function useSubscription(): {
118
124
  subscriptions: any[];
119
125
  subscription: Subscription;
120
126
  };
127
+ declare const Props: ({ default: value, type, validator, required }?: Partial<PropType>) => {
128
+ required: boolean | undefined;
129
+ validator: (value: any) => boolean;
130
+ default?: vue.Ref<any, any> | undefined;
131
+ };
121
132
  declare function StyleParser(styles?: Array<string> | Record<string, boolean> | string): {};
122
133
  declare function MergeStyles(...params: any): any;
123
134
  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>;
@@ -134,4 +145,4 @@ declare const getData: (component: any, path: number | string, alternative: any)
134
145
  declare const setData: (component: any, data: any, path?: string) => any;
135
146
  declare const dataPath: (component: any, path: string | number) => any;
136
147
 
137
- export { MergeStyles, StyleParser, access, dataPath, _default as default, defineReactiveView, extendVnode, getData, getDate, getProps, getReactiveViewComponent, safeRequest, setData, setup, showComponent, useSubscription };
148
+ export { MergeStyles, Props, StyleParser, access, dataPath, _default as default, defineReactiveView, extendVnode, getData, getDate, getProps, getReactiveViewComponent, safeRequest, setData, setup, showComponent, useSubscription };
package/dist/index.js CHANGED
@@ -60,6 +60,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
60
60
  var index_exports = {};
61
61
  __export(index_exports, {
62
62
  MergeStyles: () => MergeStyles,
63
+ Props: () => Props,
63
64
  StyleParser: () => StyleParser,
64
65
  access: () => access,
65
66
  dataPath: () => dataPath,
@@ -177,7 +178,7 @@ var import_vue = require("vue");
177
178
 
178
179
  // package.json
179
180
  var name = "@razaman2/reactive-view";
180
- var version = "0.1.0-beta.1";
181
+ var version = "0.1.0-beta.3";
181
182
 
182
183
  // src/ReactiveView.ts
183
184
  var setup = {
@@ -223,16 +224,16 @@ var ReactiveView_default = {
223
224
  setup(props, context) {
224
225
  var _a, _b, _c;
225
226
  const diff = (before, after) => {
227
+ const changed = (0, import_vue.ref)(false);
226
228
  const paths = Array.from(new Set(before.paths().concat(after.paths())));
227
- let changed = false;
228
- const change = paths.reduce((change2, path) => {
229
+ const changes = paths.reduce((changes2, path) => {
229
230
  if (before.get(path) !== after.get(path)) {
230
- change2.set(path, after.get(path));
231
- changed = true;
231
+ changes2.set(path, after.get(path));
232
+ changed.value = true;
232
233
  }
233
- return change2;
234
+ return changes2;
234
235
  }, import_object_manager.default.on({}));
235
- return { before: before.get(), after: after.get(), changes: change.get(), changed };
236
+ return { before: before.get(), after: after.get(), changes: changes.get(), changed: changed.value };
236
237
  };
237
238
  const dataPath2 = (path) => {
238
239
  try {
@@ -253,9 +254,6 @@ var ReactiveView_default = {
253
254
  const isAsyncFunctionData = ["AsyncFunction"].includes((_b = props.data) == null ? void 0 : _b.constructor.name);
254
255
  const isPromiseData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
255
256
  const vue = (0, import_vue.getCurrentInstance)();
256
- if ((isFunctionData || isPromiseData) && !("defaultData" in vue.vnode.props)) {
257
- console.warn(`${props.modelName}: defaultData is required for promise or async function data.`, props.data);
258
- }
259
257
  const defaultData = props.getDefaultData(
260
258
  "defaultData" in vue.vnode.props ? vue.vnode.props.defaultData : "data" in vue.vnode.props ? Array.isArray((0, import_vue.unref)(vue.vnode.props.data)) ? [] : {} : {}
261
259
  );
@@ -340,34 +338,45 @@ var ReactiveView_default = {
340
338
  const source = () => import_object_manager.default.on(model.getData()).clone();
341
339
  (0, import_vue.watch)(source, (after, before) => {
342
340
  const diff2 = access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after));
341
+ if (props.debug) {
342
+ console.warn(`[${props.modelName}]:model`, { diff: diff2, before, after });
343
+ }
343
344
  if (diff2.changed) {
344
345
  config2.callback(diff2, { component });
345
346
  }
346
- });
347
+ }, config2.options);
347
348
  }
348
349
  setTimeout(async () => {
349
350
  var _a3, _b2, _c2;
350
- const [data] = isPromiseData ? await Promise.all([
351
- isAsyncFunctionData ? props.data() : props.data,
352
- (_a3 = defer.value) != null ? _a3 : true
353
- ]) : [props.data];
354
- const isRefData = (0, import_vue.isRef)(data);
355
- const isReactiveData = (0, import_vue.isReactive)(data);
356
- const source = isRefData || isReactiveData || isFunctionData ? data : typeof data === "function" ? data : (() => data);
357
- (0, import_vue.watch)(source, async (after, before) => {
358
- var _a4;
359
- const diff2 = access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after));
360
- const callback = context.attrs["data:callback"];
361
- if (typeof callback === "function") {
362
- model.replaceData((_a4 = await callback(diff2, { component })) != null ? _a4 : after);
363
- } else {
364
- model.replaceData(after);
351
+ if (props.model !== false) {
352
+ if ((isFunctionData || isPromiseData) && !("defaultData" in vue.vnode.props)) {
353
+ console.warn(`${props.modelName}: defaultData is required for promise or async function data.`, props.data);
365
354
  }
366
- }, {
367
- immediate: (_b2 = context.attrs["data:immediate"]) != null ? _b2 : true,
368
- deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true,
369
- once: context.attrs["data:once"]
370
- });
355
+ const [data] = isPromiseData ? await Promise.all([
356
+ isAsyncFunctionData ? props.data() : props.data,
357
+ (_a3 = defer.value) != null ? _a3 : true
358
+ ]) : [props.data];
359
+ const isRefData = (0, import_vue.isRef)(data);
360
+ const isReactiveData = (0, import_vue.isReactive)(data);
361
+ const source = isRefData || isReactiveData || isFunctionData ? data : typeof data === "function" ? data : (() => data);
362
+ (0, import_vue.watch)(source, async (after, before) => {
363
+ var _a4;
364
+ const diff2 = access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after));
365
+ const callback = context.attrs["data:callback"];
366
+ if (props.debug) {
367
+ console.warn(`[${props.modelName}]:data`, { diff: diff2, data, callback, before, after, props, context, component, isRefData, isReactiveData });
368
+ }
369
+ if (typeof callback === "function") {
370
+ model.replaceData((_a4 = await callback(diff2, { component })) != null ? _a4 : after);
371
+ } else {
372
+ model.replaceData(after);
373
+ }
374
+ }, {
375
+ immediate: (_b2 = context.attrs["data:immediate"]) != null ? _b2 : true,
376
+ deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true,
377
+ once: context.attrs["data:once"]
378
+ });
379
+ }
371
380
  });
372
381
  setTimeout(async () => {
373
382
  var _a3;
@@ -712,6 +721,18 @@ function useSubscription() {
712
721
  subscription
713
722
  };
714
723
  }
724
+ var Props = ({ default: value, type, validator, required } = {}) => {
725
+ const types1 = Array.isArray(type) ? type : [type != null ? type : Array];
726
+ const types2 = types1.includes(Object) ? types1 : types1.concat(Object);
727
+ return __spreadProps(__spreadValues({}, value ? { default: (0, import_vue2.ref)(value) } : {}), {
728
+ required,
729
+ validator: (value2) => {
730
+ return validator ? validator((0, import_vue2.unref)(value2)) : Array.from(new Set(types2.map((type2) => {
731
+ return typeof type2 === "function" ? type2().constructor.name : type2;
732
+ }))).includes((0, import_vue2.unref)(value2).constructor.name);
733
+ }
734
+ });
735
+ };
715
736
  function StyleParser(styles = {}) {
716
737
  const transform = (style, status = true) => {
717
738
  const remove = style.split(/(-{[^}]+})/);
@@ -870,6 +891,7 @@ var dataPath = (component, path) => {
870
891
  // Annotate the CommonJS export names for ESM import in node:
871
892
  0 && (module.exports = {
872
893
  MergeStyles,
894
+ Props,
873
895
  StyleParser,
874
896
  access,
875
897
  dataPath,
package/dist/index.mjs CHANGED
@@ -131,7 +131,7 @@ import { ref, reactive, watch, isRef, isReactive, createVNode, getCurrentInstanc
131
131
 
132
132
  // package.json
133
133
  var name = "@razaman2/reactive-view";
134
- var version = "0.1.0-beta.1";
134
+ var version = "0.1.0-beta.3";
135
135
 
136
136
  // src/ReactiveView.ts
137
137
  var setup = {
@@ -177,16 +177,16 @@ var ReactiveView_default = {
177
177
  setup(props, context) {
178
178
  var _a, _b, _c;
179
179
  const diff = (before, after) => {
180
+ const changed = ref(false);
180
181
  const paths = Array.from(new Set(before.paths().concat(after.paths())));
181
- let changed = false;
182
- const change = paths.reduce((change2, path) => {
182
+ const changes = paths.reduce((changes2, path) => {
183
183
  if (before.get(path) !== after.get(path)) {
184
- change2.set(path, after.get(path));
185
- changed = true;
184
+ changes2.set(path, after.get(path));
185
+ changed.value = true;
186
186
  }
187
- return change2;
187
+ return changes2;
188
188
  }, ObjectManager.on({}));
189
- return { before: before.get(), after: after.get(), changes: change.get(), changed };
189
+ return { before: before.get(), after: after.get(), changes: changes.get(), changed: changed.value };
190
190
  };
191
191
  const dataPath2 = (path) => {
192
192
  try {
@@ -207,9 +207,6 @@ var ReactiveView_default = {
207
207
  const isAsyncFunctionData = ["AsyncFunction"].includes((_b = props.data) == null ? void 0 : _b.constructor.name);
208
208
  const isPromiseData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
209
209
  const vue = getCurrentInstance();
210
- if ((isFunctionData || isPromiseData) && !("defaultData" in vue.vnode.props)) {
211
- console.warn(`${props.modelName}: defaultData is required for promise or async function data.`, props.data);
212
- }
213
210
  const defaultData = props.getDefaultData(
214
211
  "defaultData" in vue.vnode.props ? vue.vnode.props.defaultData : "data" in vue.vnode.props ? Array.isArray(unref(vue.vnode.props.data)) ? [] : {} : {}
215
212
  );
@@ -294,34 +291,45 @@ var ReactiveView_default = {
294
291
  const source = () => ObjectManager.on(model.getData()).clone();
295
292
  watch(source, (after, before) => {
296
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
297
  if (diff2.changed) {
298
298
  config2.callback(diff2, { component });
299
299
  }
300
- });
300
+ }, config2.options);
301
301
  }
302
302
  setTimeout(async () => {
303
303
  var _a3, _b2, _c2;
304
- const [data] = isPromiseData ? await Promise.all([
305
- isAsyncFunctionData ? props.data() : props.data,
306
- (_a3 = defer.value) != null ? _a3 : true
307
- ]) : [props.data];
308
- const isRefData = isRef(data);
309
- const isReactiveData = isReactive(data);
310
- const source = isRefData || isReactiveData || isFunctionData ? data : typeof data === "function" ? data : (() => data);
311
- watch(source, async (after, before) => {
312
- var _a4;
313
- const diff2 = access(component).diff(ObjectManager.on(before), ObjectManager.on(after));
314
- const callback = context.attrs["data:callback"];
315
- if (typeof callback === "function") {
316
- model.replaceData((_a4 = await callback(diff2, { component })) != null ? _a4 : after);
317
- } else {
318
- model.replaceData(after);
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);
319
307
  }
320
- }, {
321
- immediate: (_b2 = context.attrs["data:immediate"]) != null ? _b2 : true,
322
- deep: (_c2 = context.attrs["data:deep"]) != null ? _c2 : true,
323
- once: context.attrs["data:once"]
324
- });
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, component, 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
+ }
325
333
  });
326
334
  setTimeout(async () => {
327
335
  var _a3;
@@ -666,6 +674,18 @@ function useSubscription() {
666
674
  subscription
667
675
  };
668
676
  }
677
+ var Props = ({ default: value, type, validator, required } = {}) => {
678
+ const types1 = Array.isArray(type) ? type : [type != null ? type : Array];
679
+ const types2 = types1.includes(Object) ? types1 : types1.concat(Object);
680
+ return __spreadProps(__spreadValues({}, value ? { default: ref2(value) } : {}), {
681
+ required,
682
+ validator: (value2) => {
683
+ return validator ? validator(unref2(value2)) : Array.from(new Set(types2.map((type2) => {
684
+ return typeof type2 === "function" ? type2().constructor.name : type2;
685
+ }))).includes(unref2(value2).constructor.name);
686
+ }
687
+ });
688
+ };
669
689
  function StyleParser(styles = {}) {
670
690
  const transform = (style, status = true) => {
671
691
  const remove = style.split(/(-{[^}]+})/);
@@ -823,6 +843,7 @@ var dataPath = (component, path) => {
823
843
  };
824
844
  export {
825
845
  MergeStyles,
846
+ Props,
826
847
  StyleParser,
827
848
  access,
828
849
  dataPath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@razaman2/reactive-view",
3
- "version": "0.1.0-beta.1",
3
+ "version": "0.1.0-beta.3",
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",