@razaman2/reactive-view 0.1.0-beta.1 → 0.1.0-beta.10
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 +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +159 -83
- package/dist/index.mjs +157 -82
- package/package.json +5 -5
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 Prop: ({ 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, Prop, 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 Prop: ({ 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, Prop, StyleParser, access, dataPath, _default as default, defineReactiveView, extendVnode, getData, getDate, getProps, getReactiveViewComponent, safeRequest, setData, setup, showComponent, useSubscription };
|
package/dist/index.js
CHANGED
|
@@ -35,8 +35,8 @@ var __objRest = (source, exclude) => {
|
|
|
35
35
|
return target;
|
|
36
36
|
};
|
|
37
37
|
var __export = (target, all) => {
|
|
38
|
-
for (var
|
|
39
|
-
__defProp(target,
|
|
38
|
+
for (var name in all)
|
|
39
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
40
|
};
|
|
41
41
|
var __copyProps = (to, from, except, desc) => {
|
|
42
42
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -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
|
+
Prop: () => Prop,
|
|
63
64
|
StyleParser: () => StyleParser,
|
|
64
65
|
access: () => access,
|
|
65
66
|
dataPath: () => dataPath,
|
|
@@ -88,34 +89,34 @@ var Subscription = class _Subscription {
|
|
|
88
89
|
static create() {
|
|
89
90
|
return new _Subscription();
|
|
90
91
|
}
|
|
91
|
-
subscribe(
|
|
92
|
-
if (this.isNameAvailable(
|
|
92
|
+
subscribe(name, handler, data) {
|
|
93
|
+
if (this.isNameAvailable(name)) {
|
|
93
94
|
this.subscriptions.push({
|
|
94
|
-
name
|
|
95
|
+
name,
|
|
95
96
|
handler
|
|
96
97
|
});
|
|
97
|
-
this.data[
|
|
98
|
+
this.data[name] = data;
|
|
98
99
|
}
|
|
99
100
|
return this;
|
|
100
101
|
}
|
|
101
|
-
replace(
|
|
102
|
-
this.unsubscribe(
|
|
103
|
-
return this.subscribe(
|
|
102
|
+
replace(name, handler, data) {
|
|
103
|
+
this.unsubscribe(name);
|
|
104
|
+
return this.subscribe(name, handler, data);
|
|
104
105
|
}
|
|
105
106
|
unsubscribe(param1) {
|
|
106
107
|
if (!Array.isArray(param1)) {
|
|
107
108
|
param1 = param1 ? [param1] : [];
|
|
108
109
|
}
|
|
109
|
-
const log = (
|
|
110
|
-
return console.log(`%cUnsubscribed From Subscription (${
|
|
110
|
+
const log = (name) => {
|
|
111
|
+
return console.log(`%cUnsubscribed From Subscription (${name})`, "background-color: yellow; color: green; font-weight: bold; padding: 3px;");
|
|
111
112
|
};
|
|
112
113
|
if (param1.length) {
|
|
113
|
-
param1.forEach((
|
|
114
|
-
const subscription = this.find(
|
|
114
|
+
param1.forEach((name) => {
|
|
115
|
+
const subscription = this.find(name);
|
|
115
116
|
if (subscription) {
|
|
116
117
|
subscription.handler();
|
|
117
118
|
this.remove(subscription);
|
|
118
|
-
log(
|
|
119
|
+
log(name);
|
|
119
120
|
}
|
|
120
121
|
});
|
|
121
122
|
} else {
|
|
@@ -130,20 +131,20 @@ var Subscription = class _Subscription {
|
|
|
130
131
|
size() {
|
|
131
132
|
return this.subscriptions.length;
|
|
132
133
|
}
|
|
133
|
-
hasSubscription(
|
|
134
|
-
return Boolean(this.find(
|
|
134
|
+
hasSubscription(name) {
|
|
135
|
+
return Boolean(this.find(name));
|
|
135
136
|
}
|
|
136
137
|
remove(subscription) {
|
|
137
138
|
this.subscriptions.splice(this.subscriptions.indexOf(subscription), 1);
|
|
138
139
|
}
|
|
139
|
-
find(
|
|
140
|
+
find(name) {
|
|
140
141
|
return this.subscriptions.find((subscription) => {
|
|
141
|
-
return subscription.name ===
|
|
142
|
+
return subscription.name === name;
|
|
142
143
|
});
|
|
143
144
|
}
|
|
144
|
-
isNameAvailable(
|
|
145
|
-
if (this.hasSubscription(
|
|
146
|
-
throw new Error(`There is already a subscription called "${
|
|
145
|
+
isNameAvailable(name) {
|
|
146
|
+
if (this.hasSubscription(name)) {
|
|
147
|
+
throw new Error(`There is already a subscription called "${name}".`);
|
|
147
148
|
} else {
|
|
148
149
|
return true;
|
|
149
150
|
}
|
|
@@ -151,12 +152,12 @@ var Subscription = class _Subscription {
|
|
|
151
152
|
registrations() {
|
|
152
153
|
return this.subscriptions;
|
|
153
154
|
}
|
|
154
|
-
get(
|
|
155
|
-
const subscription = this.find(
|
|
155
|
+
get(name) {
|
|
156
|
+
const subscription = this.find(name);
|
|
156
157
|
if (subscription) {
|
|
157
158
|
return subscription;
|
|
158
159
|
} else {
|
|
159
|
-
throw new Error(`Subscription "${
|
|
160
|
+
throw new Error(`Subscription "${name}" doesn't exist!`);
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
163
|
};
|
|
@@ -176,8 +177,55 @@ var import_data_manager = __toESM(require("@razaman2/data-manager"));
|
|
|
176
177
|
var import_vue = require("vue");
|
|
177
178
|
|
|
178
179
|
// package.json
|
|
179
|
-
var
|
|
180
|
-
var
|
|
180
|
+
var version = "0.1.0-beta.10";
|
|
181
|
+
var package_default = {
|
|
182
|
+
name: "@razaman2/reactive-view",
|
|
183
|
+
version,
|
|
184
|
+
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.",
|
|
185
|
+
main: "dist/index.js",
|
|
186
|
+
module: "dist/index.mjs",
|
|
187
|
+
types: "dist/index.d.ts",
|
|
188
|
+
scripts: {
|
|
189
|
+
prepublishOnly: "npm run build",
|
|
190
|
+
build: "tsup src/index.ts --format cjs,esm --dts",
|
|
191
|
+
lint: "tsc",
|
|
192
|
+
test: "cd tests/vue-ts && npm run dev",
|
|
193
|
+
pr: "sh pr.sh"
|
|
194
|
+
},
|
|
195
|
+
keywords: [
|
|
196
|
+
"vue",
|
|
197
|
+
"vue-helper",
|
|
198
|
+
"reactive-view",
|
|
199
|
+
"vue-class-component",
|
|
200
|
+
"reactive-ui"
|
|
201
|
+
],
|
|
202
|
+
author: "razaman2",
|
|
203
|
+
license: "MIT",
|
|
204
|
+
dependencies: {
|
|
205
|
+
"@razaman2/data-manager": "^3.3.8",
|
|
206
|
+
"@razaman2/event-emitter": "^2.1.1",
|
|
207
|
+
"@razaman2/object-manager": "^3.4.7",
|
|
208
|
+
"date-fns": "^4.1.0",
|
|
209
|
+
"date-fns-tz": "^3.2.0",
|
|
210
|
+
"tailwind-merge": "^3.5.0",
|
|
211
|
+
uuid: "^13.0.0"
|
|
212
|
+
},
|
|
213
|
+
peerDependencies: {
|
|
214
|
+
vue: ">=3.0.0"
|
|
215
|
+
},
|
|
216
|
+
devDependencies: {
|
|
217
|
+
"@types/uuid": "^11.0.0",
|
|
218
|
+
tsup: "^8.5.1",
|
|
219
|
+
typescript: "^5.9.3",
|
|
220
|
+
vitest: "^4.1.2"
|
|
221
|
+
},
|
|
222
|
+
publishConfig: {
|
|
223
|
+
access: "public"
|
|
224
|
+
},
|
|
225
|
+
files: [
|
|
226
|
+
"dist"
|
|
227
|
+
]
|
|
228
|
+
};
|
|
181
229
|
|
|
182
230
|
// src/ReactiveView.ts
|
|
183
231
|
var setup = {
|
|
@@ -222,17 +270,19 @@ var ReactiveView_default = {
|
|
|
222
270
|
},
|
|
223
271
|
setup(props, context) {
|
|
224
272
|
var _a, _b, _c;
|
|
273
|
+
const subscriptions = [];
|
|
274
|
+
(0, import_vue.onBeforeUnmount)(() => subscriptions.forEach((subscription) => subscription()));
|
|
225
275
|
const diff = (before, after) => {
|
|
276
|
+
const changed = (0, import_vue.ref)(false);
|
|
226
277
|
const paths = Array.from(new Set(before.paths().concat(after.paths())));
|
|
227
|
-
|
|
228
|
-
const change = paths.reduce((change2, path) => {
|
|
278
|
+
const changes = paths.reduce((changes2, path) => {
|
|
229
279
|
if (before.get(path) !== after.get(path)) {
|
|
230
|
-
|
|
231
|
-
changed = true;
|
|
280
|
+
changes2.set(path, after.get(path));
|
|
281
|
+
changed.value = true;
|
|
232
282
|
}
|
|
233
|
-
return
|
|
283
|
+
return changes2;
|
|
234
284
|
}, import_object_manager.default.on({}));
|
|
235
|
-
return { before: before.get(), after: after.get(), changes:
|
|
285
|
+
return { before: before.get(), after: after.get(), changes: changes.get(), changed: changed.value };
|
|
236
286
|
};
|
|
237
287
|
const dataPath2 = (path) => {
|
|
238
288
|
try {
|
|
@@ -244,18 +294,15 @@ var ReactiveView_default = {
|
|
|
244
294
|
const template = (component, vue2) => {
|
|
245
295
|
return (0, import_vue.createVNode)("div", context.slots.default ? context.attrs : __spreadValues({
|
|
246
296
|
style: { color: "red", textAlign: "center" }
|
|
247
|
-
}, context.attrs), context.slots.default ? context.slots.default({ component, vue: vue2, props, context }) : `${props.modelName}: ${name}@${version}`);
|
|
297
|
+
}, context.attrs), context.slots.default ? context.slots.default({ component, vue: vue2, props, context }) : `${props.modelName}: ${package_default.name}@${package_default.version}`);
|
|
248
298
|
};
|
|
249
299
|
const isValid = (0, import_vue.ref)(false);
|
|
250
300
|
const isReady = (0, import_vue.ref)(false);
|
|
251
301
|
const defer = (0, import_vue.ref)(typeof props.defer === "function" ? props.defer() : props.defer);
|
|
252
302
|
const isFunctionData = ["Function"].includes((_a = props.data) == null ? void 0 : _a.constructor.name);
|
|
253
303
|
const isAsyncFunctionData = ["AsyncFunction"].includes((_b = props.data) == null ? void 0 : _b.constructor.name);
|
|
254
|
-
const
|
|
304
|
+
const isAsyncData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
|
|
255
305
|
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
306
|
const defaultData = props.getDefaultData(
|
|
260
307
|
"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
308
|
);
|
|
@@ -302,19 +349,20 @@ var ReactiveView_default = {
|
|
|
302
349
|
});
|
|
303
350
|
};
|
|
304
351
|
const normalize = (data) => {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
352
|
+
if ((0, import_vue.isRef)(data) || (0, import_vue.isReactive)(data)) {
|
|
353
|
+
return data;
|
|
354
|
+
} else if (isFunctionData || isAsyncData) {
|
|
355
|
+
return (0, import_vue.ref)(datatype);
|
|
308
356
|
} else {
|
|
309
357
|
const props2 = "data" in vue.vnode.props;
|
|
310
358
|
try {
|
|
311
359
|
if (["Array", "Object"].includes(data.constructor.name)) {
|
|
312
|
-
return (0, import_vue.
|
|
360
|
+
return (0, import_vue.ref)(data);
|
|
313
361
|
} else {
|
|
314
|
-
return (0, import_vue.
|
|
362
|
+
return (0, import_vue.ref)(props2 ? { "": data } : datatype);
|
|
315
363
|
}
|
|
316
364
|
} catch (e) {
|
|
317
|
-
return (0, import_vue.
|
|
365
|
+
return (0, import_vue.ref)(props2 ? { "": data } : datatype);
|
|
318
366
|
}
|
|
319
367
|
}
|
|
320
368
|
};
|
|
@@ -326,7 +374,7 @@ var ReactiveView_default = {
|
|
|
326
374
|
name: props.modelName,
|
|
327
375
|
logging: props.logging
|
|
328
376
|
};
|
|
329
|
-
const model = props.model ? typeof props.model === "function" ? props.model(config) : props.model :
|
|
377
|
+
const model = props.model ? typeof props.model === "function" ? props.model(config) : props.model : import_data_manager.default.setConfig({ beforeGetData: (data) => (0, import_vue.isRef)(data) ? (0, import_vue.unref)(data) : data }, config);
|
|
330
378
|
const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, diff, emit, dataPath: dataPath2, model: proxy(model), isValid } });
|
|
331
379
|
if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
|
|
332
380
|
const config2 = {
|
|
@@ -338,36 +386,51 @@ var ReactiveView_default = {
|
|
|
338
386
|
}
|
|
339
387
|
};
|
|
340
388
|
const source = () => import_object_manager.default.on(model.getData()).clone();
|
|
341
|
-
(0, import_vue.watch)(source, (after, before) => {
|
|
389
|
+
subscriptions.push((0, import_vue.watch)(source, (after, before) => {
|
|
342
390
|
const diff2 = access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after));
|
|
391
|
+
if (props.debug) {
|
|
392
|
+
console.warn(`[${props.modelName}]:model`, { diff: diff2, before, after });
|
|
393
|
+
}
|
|
343
394
|
if (diff2.changed) {
|
|
344
395
|
config2.callback(diff2, { component });
|
|
345
396
|
}
|
|
346
|
-
});
|
|
397
|
+
}, config2.options));
|
|
347
398
|
}
|
|
348
|
-
|
|
349
|
-
var _a3, _b2, _c2;
|
|
350
|
-
|
|
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;
|
|
399
|
+
const track = (source, options = {}) => {
|
|
400
|
+
var _a3, _b2, _c2, _d, _e;
|
|
401
|
+
subscriptions.push((0, import_vue.watch)(source, async (after, before) => {
|
|
359
402
|
const diff2 = access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after));
|
|
360
403
|
const callback = context.attrs["data:callback"];
|
|
404
|
+
if (props.debug) {
|
|
405
|
+
console.warn(`[${props.modelName}]:data`, { diff: diff2, callback, before, after, props, context, component });
|
|
406
|
+
}
|
|
361
407
|
if (typeof callback === "function") {
|
|
362
|
-
|
|
408
|
+
callback(diff2, { component });
|
|
363
409
|
} else {
|
|
364
410
|
model.replaceData(after);
|
|
365
411
|
}
|
|
366
412
|
}, {
|
|
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
|
-
});
|
|
413
|
+
immediate: (_b2 = (_a3 = context.attrs["data:immediate"]) != null ? _a3 : options.immediate) != null ? _b2 : true,
|
|
414
|
+
deep: (_d = (_c2 = context.attrs["data:deep"]) != null ? _c2 : options.deep) != null ? _d : true,
|
|
415
|
+
once: (_e = context.attrs["data:once"]) != null ? _e : options.once
|
|
416
|
+
}));
|
|
417
|
+
};
|
|
418
|
+
setTimeout(async () => {
|
|
419
|
+
var _a3;
|
|
420
|
+
if (props.model !== false) {
|
|
421
|
+
if (isFunctionData || isAsyncData) {
|
|
422
|
+
if (!("defaultData" in vue.vnode.props)) {
|
|
423
|
+
console.warn(`${props.modelName}: defaultData is required for promise or function data.`, props.data);
|
|
424
|
+
}
|
|
425
|
+
const [data] = isAsyncData ? await Promise.all([
|
|
426
|
+
isAsyncFunctionData ? props.data() : props.data,
|
|
427
|
+
(_a3 = defer.value) != null ? _a3 : true
|
|
428
|
+
]) : [props.data];
|
|
429
|
+
track(typeof data === "function" ? data : (() => data));
|
|
430
|
+
} else {
|
|
431
|
+
track((0, import_vue.isRef)(props.data) || (0, import_vue.isReactive)(props.data) ? props.data : () => props.data, { immediate: false });
|
|
432
|
+
}
|
|
433
|
+
}
|
|
371
434
|
});
|
|
372
435
|
setTimeout(async () => {
|
|
373
436
|
var _a3;
|
|
@@ -421,7 +484,7 @@ var ReactiveView_default = {
|
|
|
421
484
|
if ((0, import_vue.isReactive)(data)) {
|
|
422
485
|
return data;
|
|
423
486
|
} else {
|
|
424
|
-
if ((0, import_vue.isRef)(data) || isFunctionData ||
|
|
487
|
+
if ((0, import_vue.isRef)(data) || isFunctionData || isAsyncData) {
|
|
425
488
|
return (0, import_vue.reactive)(datatype);
|
|
426
489
|
} else {
|
|
427
490
|
const props2 = "data" in vue.vnode.props;
|
|
@@ -439,7 +502,7 @@ var ReactiveView_default = {
|
|
|
439
502
|
};
|
|
440
503
|
const config = {
|
|
441
504
|
data: props.beta ? normalize((_a2 = vue.vnode.props) == null ? void 0 : _a2.data) : (0, import_vue.reactive)(import_object_manager.default.on(
|
|
442
|
-
|
|
505
|
+
isAsyncData || isFunctionData || (0, import_vue.isRef)(props.data) || (0, import_vue.isReactive)(props.data) ? datatype : "data" in vue.vnode.props ? props.data : datatype
|
|
443
506
|
).clone()),
|
|
444
507
|
defaultData: import_object_manager.default.on(defaultData).clone(),
|
|
445
508
|
notifications: props.notifications,
|
|
@@ -471,7 +534,7 @@ var ReactiveView_default = {
|
|
|
471
534
|
});
|
|
472
535
|
const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, diff, emit, dataPath: dataPath2, isValid } });
|
|
473
536
|
if (props.debug) {
|
|
474
|
-
console.warn("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData,
|
|
537
|
+
console.warn("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isAsyncData });
|
|
475
538
|
}
|
|
476
539
|
const watchDataProp = (dataProp) => {
|
|
477
540
|
var _a3, _b3, _c3, _d2;
|
|
@@ -484,14 +547,14 @@ var ReactiveView_default = {
|
|
|
484
547
|
if (context.attrs["data:log"]) {
|
|
485
548
|
console.warn(`[ReactiveView]:data`, { config: config2, dataProp });
|
|
486
549
|
}
|
|
487
|
-
(0, import_vue.watch)(isFunctionData || (0, import_vue.isRef)(dataProp) || (0, import_vue.isReactive)(dataProp) ? dataProp : () => dataProp, (after, before) => {
|
|
550
|
+
subscriptions.push((0, import_vue.watch)(isFunctionData || (0, import_vue.isRef)(dataProp) || (0, import_vue.isReactive)(dataProp) ? dataProp : () => dataProp, (after, before) => {
|
|
488
551
|
var _a4;
|
|
489
552
|
if (typeof config2.callback === "function") {
|
|
490
553
|
model.replaceData((_a4 = config2.callback(access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component })) != null ? _a4 : after);
|
|
491
554
|
} else {
|
|
492
555
|
model.replaceData(after);
|
|
493
556
|
}
|
|
494
|
-
}, config2.options);
|
|
557
|
+
}, config2.options));
|
|
495
558
|
};
|
|
496
559
|
if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
|
|
497
560
|
const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
|
|
@@ -503,20 +566,20 @@ var ReactiveView_default = {
|
|
|
503
566
|
if (context.attrs["model:log"]) {
|
|
504
567
|
console.warn(`[ReactiveView]:model`, { config: config2 });
|
|
505
568
|
}
|
|
506
|
-
(0, import_vue.watch)(() => import_object_manager.default.on(model.getData()).clone(), (after, before) => {
|
|
569
|
+
subscriptions.push((0, import_vue.watch)(() => import_object_manager.default.on(model.getData()).clone(), (after, before) => {
|
|
507
570
|
config2.callback(access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component });
|
|
508
|
-
}, config2.options);
|
|
571
|
+
}, config2.options));
|
|
509
572
|
}
|
|
510
573
|
if (props.beta) {
|
|
511
574
|
const isRefData = (0, import_vue.isRef)(props.data);
|
|
512
|
-
if (isRefData || isFunctionData ||
|
|
575
|
+
if (isRefData || isFunctionData || isAsyncData) {
|
|
513
576
|
setTimeout(async () => {
|
|
514
577
|
var _a3, _b3, _c3;
|
|
515
|
-
const [data] =
|
|
578
|
+
const [data] = isAsyncData ? await Promise.all([
|
|
516
579
|
isAsyncFunctionData ? props.data() : props.data,
|
|
517
580
|
(_a3 = defer.value) != null ? _a3 : true
|
|
518
581
|
]) : [props.data];
|
|
519
|
-
(0, import_vue.watch)(isRefData ? data : isFunctionData ? data : typeof data === "function" ? data : () => data, (after, before) => {
|
|
582
|
+
subscriptions.push((0, import_vue.watch)(isRefData ? data : isFunctionData ? data : typeof data === "function" ? data : () => data, (after, before) => {
|
|
520
583
|
var _a4;
|
|
521
584
|
if (before !== void 0 || after !== void 0) {
|
|
522
585
|
const callback = context.attrs["data:callback"];
|
|
@@ -531,7 +594,7 @@ var ReactiveView_default = {
|
|
|
531
594
|
immediate: (_b3 = context.attrs["data:immediate"]) != null ? _b3 : true,
|
|
532
595
|
deep: (_c3 = context.attrs["data:deep"]) != null ? _c3 : true,
|
|
533
596
|
once: context.attrs["data:once"]
|
|
534
|
-
});
|
|
597
|
+
}));
|
|
535
598
|
});
|
|
536
599
|
}
|
|
537
600
|
} else {
|
|
@@ -689,29 +752,41 @@ function useSubscription() {
|
|
|
689
752
|
const subscriptions = [];
|
|
690
753
|
const subscription = Subscriptions.get();
|
|
691
754
|
return {
|
|
692
|
-
addSubscription(
|
|
693
|
-
subscription.subscribe(
|
|
694
|
-
subscriptions.push(() => subscription.unsubscribe(
|
|
755
|
+
addSubscription(name, handler = () => false, data) {
|
|
756
|
+
subscription.subscribe(name, handler, data);
|
|
757
|
+
subscriptions.push(() => subscription.unsubscribe(name));
|
|
695
758
|
},
|
|
696
|
-
replaceSubscription(
|
|
697
|
-
subscription.replace(
|
|
698
|
-
subscriptions.push(() => subscription.unsubscribe(
|
|
759
|
+
replaceSubscription(name, handler = () => false, data) {
|
|
760
|
+
subscription.replace(name, handler, data);
|
|
761
|
+
subscriptions.push(() => subscription.unsubscribe(name));
|
|
699
762
|
},
|
|
700
763
|
removeSubscriptions() {
|
|
701
764
|
subscriptions.forEach((subscription2) => safeRequest({
|
|
702
765
|
try: () => subscription2()
|
|
703
766
|
}));
|
|
704
767
|
},
|
|
705
|
-
removeSubscription(
|
|
706
|
-
subscription.unsubscribe(
|
|
768
|
+
removeSubscription(name) {
|
|
769
|
+
subscription.unsubscribe(name);
|
|
707
770
|
},
|
|
708
|
-
hasSubscription(
|
|
709
|
-
return subscription.hasSubscription(
|
|
771
|
+
hasSubscription(name) {
|
|
772
|
+
return subscription.hasSubscription(name);
|
|
710
773
|
},
|
|
711
774
|
subscriptions,
|
|
712
775
|
subscription
|
|
713
776
|
};
|
|
714
777
|
}
|
|
778
|
+
var Prop = ({ default: value, type, validator, required } = {}) => {
|
|
779
|
+
const types1 = Array.isArray(type) ? type : [type != null ? type : Array];
|
|
780
|
+
const types2 = types1.includes(Object) ? types1 : types1.concat(Object);
|
|
781
|
+
return __spreadProps(__spreadValues({}, value ? { default: (0, import_vue2.ref)(value) } : {}), {
|
|
782
|
+
required,
|
|
783
|
+
validator: (value2) => {
|
|
784
|
+
return validator ? validator((0, import_vue2.unref)(value2)) : Array.from(new Set(types2.map((type2) => {
|
|
785
|
+
return typeof type2 === "function" ? type2().constructor.name : type2;
|
|
786
|
+
}))).includes((0, import_vue2.unref)(value2).constructor.name);
|
|
787
|
+
}
|
|
788
|
+
});
|
|
789
|
+
};
|
|
715
790
|
function StyleParser(styles = {}) {
|
|
716
791
|
const transform = (style, status = true) => {
|
|
717
792
|
const remove = style.split(/(-{[^}]+})/);
|
|
@@ -870,6 +945,7 @@ var dataPath = (component, path) => {
|
|
|
870
945
|
// Annotate the CommonJS export names for ESM import in node:
|
|
871
946
|
0 && (module.exports = {
|
|
872
947
|
MergeStyles,
|
|
948
|
+
Prop,
|
|
873
949
|
StyleParser,
|
|
874
950
|
access,
|
|
875
951
|
dataPath,
|
package/dist/index.mjs
CHANGED
|
@@ -42,34 +42,34 @@ var Subscription = class _Subscription {
|
|
|
42
42
|
static create() {
|
|
43
43
|
return new _Subscription();
|
|
44
44
|
}
|
|
45
|
-
subscribe(
|
|
46
|
-
if (this.isNameAvailable(
|
|
45
|
+
subscribe(name, handler, data) {
|
|
46
|
+
if (this.isNameAvailable(name)) {
|
|
47
47
|
this.subscriptions.push({
|
|
48
|
-
name
|
|
48
|
+
name,
|
|
49
49
|
handler
|
|
50
50
|
});
|
|
51
|
-
this.data[
|
|
51
|
+
this.data[name] = data;
|
|
52
52
|
}
|
|
53
53
|
return this;
|
|
54
54
|
}
|
|
55
|
-
replace(
|
|
56
|
-
this.unsubscribe(
|
|
57
|
-
return this.subscribe(
|
|
55
|
+
replace(name, handler, data) {
|
|
56
|
+
this.unsubscribe(name);
|
|
57
|
+
return this.subscribe(name, handler, data);
|
|
58
58
|
}
|
|
59
59
|
unsubscribe(param1) {
|
|
60
60
|
if (!Array.isArray(param1)) {
|
|
61
61
|
param1 = param1 ? [param1] : [];
|
|
62
62
|
}
|
|
63
|
-
const log = (
|
|
64
|
-
return console.log(`%cUnsubscribed From Subscription (${
|
|
63
|
+
const log = (name) => {
|
|
64
|
+
return console.log(`%cUnsubscribed From Subscription (${name})`, "background-color: yellow; color: green; font-weight: bold; padding: 3px;");
|
|
65
65
|
};
|
|
66
66
|
if (param1.length) {
|
|
67
|
-
param1.forEach((
|
|
68
|
-
const subscription = this.find(
|
|
67
|
+
param1.forEach((name) => {
|
|
68
|
+
const subscription = this.find(name);
|
|
69
69
|
if (subscription) {
|
|
70
70
|
subscription.handler();
|
|
71
71
|
this.remove(subscription);
|
|
72
|
-
log(
|
|
72
|
+
log(name);
|
|
73
73
|
}
|
|
74
74
|
});
|
|
75
75
|
} else {
|
|
@@ -84,20 +84,20 @@ var Subscription = class _Subscription {
|
|
|
84
84
|
size() {
|
|
85
85
|
return this.subscriptions.length;
|
|
86
86
|
}
|
|
87
|
-
hasSubscription(
|
|
88
|
-
return Boolean(this.find(
|
|
87
|
+
hasSubscription(name) {
|
|
88
|
+
return Boolean(this.find(name));
|
|
89
89
|
}
|
|
90
90
|
remove(subscription) {
|
|
91
91
|
this.subscriptions.splice(this.subscriptions.indexOf(subscription), 1);
|
|
92
92
|
}
|
|
93
|
-
find(
|
|
93
|
+
find(name) {
|
|
94
94
|
return this.subscriptions.find((subscription) => {
|
|
95
|
-
return subscription.name ===
|
|
95
|
+
return subscription.name === name;
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
|
-
isNameAvailable(
|
|
99
|
-
if (this.hasSubscription(
|
|
100
|
-
throw new Error(`There is already a subscription called "${
|
|
98
|
+
isNameAvailable(name) {
|
|
99
|
+
if (this.hasSubscription(name)) {
|
|
100
|
+
throw new Error(`There is already a subscription called "${name}".`);
|
|
101
101
|
} else {
|
|
102
102
|
return true;
|
|
103
103
|
}
|
|
@@ -105,12 +105,12 @@ var Subscription = class _Subscription {
|
|
|
105
105
|
registrations() {
|
|
106
106
|
return this.subscriptions;
|
|
107
107
|
}
|
|
108
|
-
get(
|
|
109
|
-
const subscription = this.find(
|
|
108
|
+
get(name) {
|
|
109
|
+
const subscription = this.find(name);
|
|
110
110
|
if (subscription) {
|
|
111
111
|
return subscription;
|
|
112
112
|
} else {
|
|
113
|
-
throw new Error(`Subscription "${
|
|
113
|
+
throw new Error(`Subscription "${name}" doesn't exist!`);
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
};
|
|
@@ -127,11 +127,58 @@ var Subscriptions = _Subscriptions;
|
|
|
127
127
|
// src/ReactiveView.ts
|
|
128
128
|
import ObjectManager from "@razaman2/object-manager";
|
|
129
129
|
import DataManager from "@razaman2/data-manager";
|
|
130
|
-
import { ref, reactive, watch, isRef, isReactive, createVNode, getCurrentInstance,
|
|
130
|
+
import { ref, reactive, watch, unref, isRef, isReactive, createVNode, getCurrentInstance, onBeforeUnmount } from "vue";
|
|
131
131
|
|
|
132
132
|
// package.json
|
|
133
|
-
var
|
|
134
|
-
var
|
|
133
|
+
var version = "0.1.0-beta.10";
|
|
134
|
+
var package_default = {
|
|
135
|
+
name: "@razaman2/reactive-view",
|
|
136
|
+
version,
|
|
137
|
+
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.",
|
|
138
|
+
main: "dist/index.js",
|
|
139
|
+
module: "dist/index.mjs",
|
|
140
|
+
types: "dist/index.d.ts",
|
|
141
|
+
scripts: {
|
|
142
|
+
prepublishOnly: "npm run build",
|
|
143
|
+
build: "tsup src/index.ts --format cjs,esm --dts",
|
|
144
|
+
lint: "tsc",
|
|
145
|
+
test: "cd tests/vue-ts && npm run dev",
|
|
146
|
+
pr: "sh pr.sh"
|
|
147
|
+
},
|
|
148
|
+
keywords: [
|
|
149
|
+
"vue",
|
|
150
|
+
"vue-helper",
|
|
151
|
+
"reactive-view",
|
|
152
|
+
"vue-class-component",
|
|
153
|
+
"reactive-ui"
|
|
154
|
+
],
|
|
155
|
+
author: "razaman2",
|
|
156
|
+
license: "MIT",
|
|
157
|
+
dependencies: {
|
|
158
|
+
"@razaman2/data-manager": "^3.3.8",
|
|
159
|
+
"@razaman2/event-emitter": "^2.1.1",
|
|
160
|
+
"@razaman2/object-manager": "^3.4.7",
|
|
161
|
+
"date-fns": "^4.1.0",
|
|
162
|
+
"date-fns-tz": "^3.2.0",
|
|
163
|
+
"tailwind-merge": "^3.5.0",
|
|
164
|
+
uuid: "^13.0.0"
|
|
165
|
+
},
|
|
166
|
+
peerDependencies: {
|
|
167
|
+
vue: ">=3.0.0"
|
|
168
|
+
},
|
|
169
|
+
devDependencies: {
|
|
170
|
+
"@types/uuid": "^11.0.0",
|
|
171
|
+
tsup: "^8.5.1",
|
|
172
|
+
typescript: "^5.9.3",
|
|
173
|
+
vitest: "^4.1.2"
|
|
174
|
+
},
|
|
175
|
+
publishConfig: {
|
|
176
|
+
access: "public"
|
|
177
|
+
},
|
|
178
|
+
files: [
|
|
179
|
+
"dist"
|
|
180
|
+
]
|
|
181
|
+
};
|
|
135
182
|
|
|
136
183
|
// src/ReactiveView.ts
|
|
137
184
|
var setup = {
|
|
@@ -176,17 +223,19 @@ var ReactiveView_default = {
|
|
|
176
223
|
},
|
|
177
224
|
setup(props, context) {
|
|
178
225
|
var _a, _b, _c;
|
|
226
|
+
const subscriptions = [];
|
|
227
|
+
onBeforeUnmount(() => subscriptions.forEach((subscription) => subscription()));
|
|
179
228
|
const diff = (before, after) => {
|
|
229
|
+
const changed = ref(false);
|
|
180
230
|
const paths = Array.from(new Set(before.paths().concat(after.paths())));
|
|
181
|
-
|
|
182
|
-
const change = paths.reduce((change2, path) => {
|
|
231
|
+
const changes = paths.reduce((changes2, path) => {
|
|
183
232
|
if (before.get(path) !== after.get(path)) {
|
|
184
|
-
|
|
185
|
-
changed = true;
|
|
233
|
+
changes2.set(path, after.get(path));
|
|
234
|
+
changed.value = true;
|
|
186
235
|
}
|
|
187
|
-
return
|
|
236
|
+
return changes2;
|
|
188
237
|
}, ObjectManager.on({}));
|
|
189
|
-
return { before: before.get(), after: after.get(), changes:
|
|
238
|
+
return { before: before.get(), after: after.get(), changes: changes.get(), changed: changed.value };
|
|
190
239
|
};
|
|
191
240
|
const dataPath2 = (path) => {
|
|
192
241
|
try {
|
|
@@ -198,18 +247,15 @@ var ReactiveView_default = {
|
|
|
198
247
|
const template = (component, vue2) => {
|
|
199
248
|
return createVNode("div", context.slots.default ? context.attrs : __spreadValues({
|
|
200
249
|
style: { color: "red", textAlign: "center" }
|
|
201
|
-
}, context.attrs), context.slots.default ? context.slots.default({ component, vue: vue2, props, context }) : `${props.modelName}: ${name}@${version}`);
|
|
250
|
+
}, context.attrs), context.slots.default ? context.slots.default({ component, vue: vue2, props, context }) : `${props.modelName}: ${package_default.name}@${package_default.version}`);
|
|
202
251
|
};
|
|
203
252
|
const isValid = ref(false);
|
|
204
253
|
const isReady = ref(false);
|
|
205
254
|
const defer = ref(typeof props.defer === "function" ? props.defer() : props.defer);
|
|
206
255
|
const isFunctionData = ["Function"].includes((_a = props.data) == null ? void 0 : _a.constructor.name);
|
|
207
256
|
const isAsyncFunctionData = ["AsyncFunction"].includes((_b = props.data) == null ? void 0 : _b.constructor.name);
|
|
208
|
-
const
|
|
257
|
+
const isAsyncData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
|
|
209
258
|
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
259
|
const defaultData = props.getDefaultData(
|
|
214
260
|
"defaultData" in vue.vnode.props ? vue.vnode.props.defaultData : "data" in vue.vnode.props ? Array.isArray(unref(vue.vnode.props.data)) ? [] : {} : {}
|
|
215
261
|
);
|
|
@@ -256,19 +302,20 @@ var ReactiveView_default = {
|
|
|
256
302
|
});
|
|
257
303
|
};
|
|
258
304
|
const normalize = (data) => {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
305
|
+
if (isRef(data) || isReactive(data)) {
|
|
306
|
+
return data;
|
|
307
|
+
} else if (isFunctionData || isAsyncData) {
|
|
308
|
+
return ref(datatype);
|
|
262
309
|
} else {
|
|
263
310
|
const props2 = "data" in vue.vnode.props;
|
|
264
311
|
try {
|
|
265
312
|
if (["Array", "Object"].includes(data.constructor.name)) {
|
|
266
|
-
return
|
|
313
|
+
return ref(data);
|
|
267
314
|
} else {
|
|
268
|
-
return
|
|
315
|
+
return ref(props2 ? { "": data } : datatype);
|
|
269
316
|
}
|
|
270
317
|
} catch (e) {
|
|
271
|
-
return
|
|
318
|
+
return ref(props2 ? { "": data } : datatype);
|
|
272
319
|
}
|
|
273
320
|
}
|
|
274
321
|
};
|
|
@@ -280,7 +327,7 @@ var ReactiveView_default = {
|
|
|
280
327
|
name: props.modelName,
|
|
281
328
|
logging: props.logging
|
|
282
329
|
};
|
|
283
|
-
const model = props.model ? typeof props.model === "function" ? props.model(config) : props.model :
|
|
330
|
+
const model = props.model ? typeof props.model === "function" ? props.model(config) : props.model : DataManager.setConfig({ beforeGetData: (data) => isRef(data) ? unref(data) : data }, config);
|
|
284
331
|
const component = ref({ parent: { self: vue.proxy }, self: { template, diff, emit, dataPath: dataPath2, model: proxy(model), isValid } });
|
|
285
332
|
if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
|
|
286
333
|
const config2 = {
|
|
@@ -292,36 +339,51 @@ var ReactiveView_default = {
|
|
|
292
339
|
}
|
|
293
340
|
};
|
|
294
341
|
const source = () => ObjectManager.on(model.getData()).clone();
|
|
295
|
-
watch(source, (after, before) => {
|
|
342
|
+
subscriptions.push(watch(source, (after, before) => {
|
|
296
343
|
const diff2 = access(component).diff(ObjectManager.on(before), ObjectManager.on(after));
|
|
344
|
+
if (props.debug) {
|
|
345
|
+
console.warn(`[${props.modelName}]:model`, { diff: diff2, before, after });
|
|
346
|
+
}
|
|
297
347
|
if (diff2.changed) {
|
|
298
348
|
config2.callback(diff2, { component });
|
|
299
349
|
}
|
|
300
|
-
});
|
|
350
|
+
}, config2.options));
|
|
301
351
|
}
|
|
302
|
-
|
|
303
|
-
var _a3, _b2, _c2;
|
|
304
|
-
|
|
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;
|
|
352
|
+
const track = (source, options = {}) => {
|
|
353
|
+
var _a3, _b2, _c2, _d, _e;
|
|
354
|
+
subscriptions.push(watch(source, async (after, before) => {
|
|
313
355
|
const diff2 = access(component).diff(ObjectManager.on(before), ObjectManager.on(after));
|
|
314
356
|
const callback = context.attrs["data:callback"];
|
|
357
|
+
if (props.debug) {
|
|
358
|
+
console.warn(`[${props.modelName}]:data`, { diff: diff2, callback, before, after, props, context, component });
|
|
359
|
+
}
|
|
315
360
|
if (typeof callback === "function") {
|
|
316
|
-
|
|
361
|
+
callback(diff2, { component });
|
|
317
362
|
} else {
|
|
318
363
|
model.replaceData(after);
|
|
319
364
|
}
|
|
320
365
|
}, {
|
|
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
|
-
});
|
|
366
|
+
immediate: (_b2 = (_a3 = context.attrs["data:immediate"]) != null ? _a3 : options.immediate) != null ? _b2 : true,
|
|
367
|
+
deep: (_d = (_c2 = context.attrs["data:deep"]) != null ? _c2 : options.deep) != null ? _d : true,
|
|
368
|
+
once: (_e = context.attrs["data:once"]) != null ? _e : options.once
|
|
369
|
+
}));
|
|
370
|
+
};
|
|
371
|
+
setTimeout(async () => {
|
|
372
|
+
var _a3;
|
|
373
|
+
if (props.model !== false) {
|
|
374
|
+
if (isFunctionData || isAsyncData) {
|
|
375
|
+
if (!("defaultData" in vue.vnode.props)) {
|
|
376
|
+
console.warn(`${props.modelName}: defaultData is required for promise or function data.`, props.data);
|
|
377
|
+
}
|
|
378
|
+
const [data] = isAsyncData ? await Promise.all([
|
|
379
|
+
isAsyncFunctionData ? props.data() : props.data,
|
|
380
|
+
(_a3 = defer.value) != null ? _a3 : true
|
|
381
|
+
]) : [props.data];
|
|
382
|
+
track(typeof data === "function" ? data : (() => data));
|
|
383
|
+
} else {
|
|
384
|
+
track(isRef(props.data) || isReactive(props.data) ? props.data : () => props.data, { immediate: false });
|
|
385
|
+
}
|
|
386
|
+
}
|
|
325
387
|
});
|
|
326
388
|
setTimeout(async () => {
|
|
327
389
|
var _a3;
|
|
@@ -375,7 +437,7 @@ var ReactiveView_default = {
|
|
|
375
437
|
if (isReactive(data)) {
|
|
376
438
|
return data;
|
|
377
439
|
} else {
|
|
378
|
-
if (isRef(data) || isFunctionData ||
|
|
440
|
+
if (isRef(data) || isFunctionData || isAsyncData) {
|
|
379
441
|
return reactive(datatype);
|
|
380
442
|
} else {
|
|
381
443
|
const props2 = "data" in vue.vnode.props;
|
|
@@ -393,7 +455,7 @@ var ReactiveView_default = {
|
|
|
393
455
|
};
|
|
394
456
|
const config = {
|
|
395
457
|
data: props.beta ? normalize((_a2 = vue.vnode.props) == null ? void 0 : _a2.data) : reactive(ObjectManager.on(
|
|
396
|
-
|
|
458
|
+
isAsyncData || isFunctionData || isRef(props.data) || isReactive(props.data) ? datatype : "data" in vue.vnode.props ? props.data : datatype
|
|
397
459
|
).clone()),
|
|
398
460
|
defaultData: ObjectManager.on(defaultData).clone(),
|
|
399
461
|
notifications: props.notifications,
|
|
@@ -425,7 +487,7 @@ var ReactiveView_default = {
|
|
|
425
487
|
});
|
|
426
488
|
const component = ref({ parent: { self: vue.proxy }, self: { template, model, diff, emit, dataPath: dataPath2, isValid } });
|
|
427
489
|
if (props.debug) {
|
|
428
|
-
console.warn("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData,
|
|
490
|
+
console.warn("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isAsyncData });
|
|
429
491
|
}
|
|
430
492
|
const watchDataProp = (dataProp) => {
|
|
431
493
|
var _a3, _b3, _c3, _d2;
|
|
@@ -438,14 +500,14 @@ var ReactiveView_default = {
|
|
|
438
500
|
if (context.attrs["data:log"]) {
|
|
439
501
|
console.warn(`[ReactiveView]:data`, { config: config2, dataProp });
|
|
440
502
|
}
|
|
441
|
-
watch(isFunctionData || isRef(dataProp) || isReactive(dataProp) ? dataProp : () => dataProp, (after, before) => {
|
|
503
|
+
subscriptions.push(watch(isFunctionData || isRef(dataProp) || isReactive(dataProp) ? dataProp : () => dataProp, (after, before) => {
|
|
442
504
|
var _a4;
|
|
443
505
|
if (typeof config2.callback === "function") {
|
|
444
506
|
model.replaceData((_a4 = config2.callback(access(component).diff(ObjectManager.on(before), ObjectManager.on(after)), { component })) != null ? _a4 : after);
|
|
445
507
|
} else {
|
|
446
508
|
model.replaceData(after);
|
|
447
509
|
}
|
|
448
|
-
}, config2.options);
|
|
510
|
+
}, config2.options));
|
|
449
511
|
};
|
|
450
512
|
if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
|
|
451
513
|
const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
|
|
@@ -457,20 +519,20 @@ var ReactiveView_default = {
|
|
|
457
519
|
if (context.attrs["model:log"]) {
|
|
458
520
|
console.warn(`[ReactiveView]:model`, { config: config2 });
|
|
459
521
|
}
|
|
460
|
-
watch(() => ObjectManager.on(model.getData()).clone(), (after, before) => {
|
|
522
|
+
subscriptions.push(watch(() => ObjectManager.on(model.getData()).clone(), (after, before) => {
|
|
461
523
|
config2.callback(access(component).diff(ObjectManager.on(before), ObjectManager.on(after)), { component });
|
|
462
|
-
}, config2.options);
|
|
524
|
+
}, config2.options));
|
|
463
525
|
}
|
|
464
526
|
if (props.beta) {
|
|
465
527
|
const isRefData = isRef(props.data);
|
|
466
|
-
if (isRefData || isFunctionData ||
|
|
528
|
+
if (isRefData || isFunctionData || isAsyncData) {
|
|
467
529
|
setTimeout(async () => {
|
|
468
530
|
var _a3, _b3, _c3;
|
|
469
|
-
const [data] =
|
|
531
|
+
const [data] = isAsyncData ? await Promise.all([
|
|
470
532
|
isAsyncFunctionData ? props.data() : props.data,
|
|
471
533
|
(_a3 = defer.value) != null ? _a3 : true
|
|
472
534
|
]) : [props.data];
|
|
473
|
-
watch(isRefData ? data : isFunctionData ? data : typeof data === "function" ? data : () => data, (after, before) => {
|
|
535
|
+
subscriptions.push(watch(isRefData ? data : isFunctionData ? data : typeof data === "function" ? data : () => data, (after, before) => {
|
|
474
536
|
var _a4;
|
|
475
537
|
if (before !== void 0 || after !== void 0) {
|
|
476
538
|
const callback = context.attrs["data:callback"];
|
|
@@ -485,7 +547,7 @@ var ReactiveView_default = {
|
|
|
485
547
|
immediate: (_b3 = context.attrs["data:immediate"]) != null ? _b3 : true,
|
|
486
548
|
deep: (_c3 = context.attrs["data:deep"]) != null ? _c3 : true,
|
|
487
549
|
once: context.attrs["data:once"]
|
|
488
|
-
});
|
|
550
|
+
}));
|
|
489
551
|
});
|
|
490
552
|
}
|
|
491
553
|
} else {
|
|
@@ -643,29 +705,41 @@ function useSubscription() {
|
|
|
643
705
|
const subscriptions = [];
|
|
644
706
|
const subscription = Subscriptions.get();
|
|
645
707
|
return {
|
|
646
|
-
addSubscription(
|
|
647
|
-
subscription.subscribe(
|
|
648
|
-
subscriptions.push(() => subscription.unsubscribe(
|
|
708
|
+
addSubscription(name, handler = () => false, data) {
|
|
709
|
+
subscription.subscribe(name, handler, data);
|
|
710
|
+
subscriptions.push(() => subscription.unsubscribe(name));
|
|
649
711
|
},
|
|
650
|
-
replaceSubscription(
|
|
651
|
-
subscription.replace(
|
|
652
|
-
subscriptions.push(() => subscription.unsubscribe(
|
|
712
|
+
replaceSubscription(name, handler = () => false, data) {
|
|
713
|
+
subscription.replace(name, handler, data);
|
|
714
|
+
subscriptions.push(() => subscription.unsubscribe(name));
|
|
653
715
|
},
|
|
654
716
|
removeSubscriptions() {
|
|
655
717
|
subscriptions.forEach((subscription2) => safeRequest({
|
|
656
718
|
try: () => subscription2()
|
|
657
719
|
}));
|
|
658
720
|
},
|
|
659
|
-
removeSubscription(
|
|
660
|
-
subscription.unsubscribe(
|
|
721
|
+
removeSubscription(name) {
|
|
722
|
+
subscription.unsubscribe(name);
|
|
661
723
|
},
|
|
662
|
-
hasSubscription(
|
|
663
|
-
return subscription.hasSubscription(
|
|
724
|
+
hasSubscription(name) {
|
|
725
|
+
return subscription.hasSubscription(name);
|
|
664
726
|
},
|
|
665
727
|
subscriptions,
|
|
666
728
|
subscription
|
|
667
729
|
};
|
|
668
730
|
}
|
|
731
|
+
var Prop = ({ default: value, type, validator, required } = {}) => {
|
|
732
|
+
const types1 = Array.isArray(type) ? type : [type != null ? type : Array];
|
|
733
|
+
const types2 = types1.includes(Object) ? types1 : types1.concat(Object);
|
|
734
|
+
return __spreadProps(__spreadValues({}, value ? { default: ref2(value) } : {}), {
|
|
735
|
+
required,
|
|
736
|
+
validator: (value2) => {
|
|
737
|
+
return validator ? validator(unref2(value2)) : Array.from(new Set(types2.map((type2) => {
|
|
738
|
+
return typeof type2 === "function" ? type2().constructor.name : type2;
|
|
739
|
+
}))).includes(unref2(value2).constructor.name);
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
};
|
|
669
743
|
function StyleParser(styles = {}) {
|
|
670
744
|
const transform = (style, status = true) => {
|
|
671
745
|
const remove = style.split(/(-{[^}]+})/);
|
|
@@ -823,6 +897,7 @@ var dataPath = (component, path) => {
|
|
|
823
897
|
};
|
|
824
898
|
export {
|
|
825
899
|
MergeStyles,
|
|
900
|
+
Prop,
|
|
826
901
|
StyleParser,
|
|
827
902
|
access,
|
|
828
903
|
dataPath,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@razaman2/reactive-view",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.10",
|
|
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",
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"author": "razaman2",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@razaman2/data-manager": "^3.
|
|
25
|
+
"@razaman2/data-manager": "^3.3.8",
|
|
26
26
|
"@razaman2/event-emitter": "^2.1.1",
|
|
27
27
|
"@razaman2/object-manager": "^3.4.7",
|
|
28
28
|
"date-fns": "^4.1.0",
|
|
29
29
|
"date-fns-tz": "^3.2.0",
|
|
30
|
-
"tailwind-merge": "^3.
|
|
30
|
+
"tailwind-merge": "^3.5.0",
|
|
31
31
|
"uuid": "^13.0.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/uuid": "^11.0.0",
|
|
38
|
-
"tsup": "^8.5.
|
|
38
|
+
"tsup": "^8.5.1",
|
|
39
39
|
"typescript": "^5.9.3",
|
|
40
|
-
"vitest": "^4.
|
|
40
|
+
"vitest": "^4.1.2"
|
|
41
41
|
},
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|