@razaman2/reactive-view 0.1.0-beta.1 → 0.1.0-beta.11
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 +162 -83
- package/dist/index.mjs +160 -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.11";
|
|
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,54 @@ 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
|
+
if (props.debug) {
|
|
432
|
+
console.log(`log output:`, props, (0, import_vue.isRef)(props.data), (0, import_vue.isReactive)(props.data));
|
|
433
|
+
}
|
|
434
|
+
track((0, import_vue.isRef)(props.data) || (0, import_vue.isReactive)(props.data) ? props.data : () => props.data, { immediate: false, deep: false });
|
|
435
|
+
}
|
|
436
|
+
}
|
|
371
437
|
});
|
|
372
438
|
setTimeout(async () => {
|
|
373
439
|
var _a3;
|
|
@@ -421,7 +487,7 @@ var ReactiveView_default = {
|
|
|
421
487
|
if ((0, import_vue.isReactive)(data)) {
|
|
422
488
|
return data;
|
|
423
489
|
} else {
|
|
424
|
-
if ((0, import_vue.isRef)(data) || isFunctionData ||
|
|
490
|
+
if ((0, import_vue.isRef)(data) || isFunctionData || isAsyncData) {
|
|
425
491
|
return (0, import_vue.reactive)(datatype);
|
|
426
492
|
} else {
|
|
427
493
|
const props2 = "data" in vue.vnode.props;
|
|
@@ -439,7 +505,7 @@ var ReactiveView_default = {
|
|
|
439
505
|
};
|
|
440
506
|
const config = {
|
|
441
507
|
data: props.beta ? normalize((_a2 = vue.vnode.props) == null ? void 0 : _a2.data) : (0, import_vue.reactive)(import_object_manager.default.on(
|
|
442
|
-
|
|
508
|
+
isAsyncData || isFunctionData || (0, import_vue.isRef)(props.data) || (0, import_vue.isReactive)(props.data) ? datatype : "data" in vue.vnode.props ? props.data : datatype
|
|
443
509
|
).clone()),
|
|
444
510
|
defaultData: import_object_manager.default.on(defaultData).clone(),
|
|
445
511
|
notifications: props.notifications,
|
|
@@ -471,7 +537,7 @@ var ReactiveView_default = {
|
|
|
471
537
|
});
|
|
472
538
|
const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, diff, emit, dataPath: dataPath2, isValid } });
|
|
473
539
|
if (props.debug) {
|
|
474
|
-
console.warn("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData,
|
|
540
|
+
console.warn("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isAsyncData });
|
|
475
541
|
}
|
|
476
542
|
const watchDataProp = (dataProp) => {
|
|
477
543
|
var _a3, _b3, _c3, _d2;
|
|
@@ -484,14 +550,14 @@ var ReactiveView_default = {
|
|
|
484
550
|
if (context.attrs["data:log"]) {
|
|
485
551
|
console.warn(`[ReactiveView]:data`, { config: config2, dataProp });
|
|
486
552
|
}
|
|
487
|
-
(0, import_vue.watch)(isFunctionData || (0, import_vue.isRef)(dataProp) || (0, import_vue.isReactive)(dataProp) ? dataProp : () => dataProp, (after, before) => {
|
|
553
|
+
subscriptions.push((0, import_vue.watch)(isFunctionData || (0, import_vue.isRef)(dataProp) || (0, import_vue.isReactive)(dataProp) ? dataProp : () => dataProp, (after, before) => {
|
|
488
554
|
var _a4;
|
|
489
555
|
if (typeof config2.callback === "function") {
|
|
490
556
|
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
557
|
} else {
|
|
492
558
|
model.replaceData(after);
|
|
493
559
|
}
|
|
494
|
-
}, config2.options);
|
|
560
|
+
}, config2.options));
|
|
495
561
|
};
|
|
496
562
|
if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
|
|
497
563
|
const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
|
|
@@ -503,20 +569,20 @@ var ReactiveView_default = {
|
|
|
503
569
|
if (context.attrs["model:log"]) {
|
|
504
570
|
console.warn(`[ReactiveView]:model`, { config: config2 });
|
|
505
571
|
}
|
|
506
|
-
(0, import_vue.watch)(() => import_object_manager.default.on(model.getData()).clone(), (after, before) => {
|
|
572
|
+
subscriptions.push((0, import_vue.watch)(() => import_object_manager.default.on(model.getData()).clone(), (after, before) => {
|
|
507
573
|
config2.callback(access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component });
|
|
508
|
-
}, config2.options);
|
|
574
|
+
}, config2.options));
|
|
509
575
|
}
|
|
510
576
|
if (props.beta) {
|
|
511
577
|
const isRefData = (0, import_vue.isRef)(props.data);
|
|
512
|
-
if (isRefData || isFunctionData ||
|
|
578
|
+
if (isRefData || isFunctionData || isAsyncData) {
|
|
513
579
|
setTimeout(async () => {
|
|
514
580
|
var _a3, _b3, _c3;
|
|
515
|
-
const [data] =
|
|
581
|
+
const [data] = isAsyncData ? await Promise.all([
|
|
516
582
|
isAsyncFunctionData ? props.data() : props.data,
|
|
517
583
|
(_a3 = defer.value) != null ? _a3 : true
|
|
518
584
|
]) : [props.data];
|
|
519
|
-
(0, import_vue.watch)(isRefData ? data : isFunctionData ? data : typeof data === "function" ? data : () => data, (after, before) => {
|
|
585
|
+
subscriptions.push((0, import_vue.watch)(isRefData ? data : isFunctionData ? data : typeof data === "function" ? data : () => data, (after, before) => {
|
|
520
586
|
var _a4;
|
|
521
587
|
if (before !== void 0 || after !== void 0) {
|
|
522
588
|
const callback = context.attrs["data:callback"];
|
|
@@ -531,7 +597,7 @@ var ReactiveView_default = {
|
|
|
531
597
|
immediate: (_b3 = context.attrs["data:immediate"]) != null ? _b3 : true,
|
|
532
598
|
deep: (_c3 = context.attrs["data:deep"]) != null ? _c3 : true,
|
|
533
599
|
once: context.attrs["data:once"]
|
|
534
|
-
});
|
|
600
|
+
}));
|
|
535
601
|
});
|
|
536
602
|
}
|
|
537
603
|
} else {
|
|
@@ -689,29 +755,41 @@ function useSubscription() {
|
|
|
689
755
|
const subscriptions = [];
|
|
690
756
|
const subscription = Subscriptions.get();
|
|
691
757
|
return {
|
|
692
|
-
addSubscription(
|
|
693
|
-
subscription.subscribe(
|
|
694
|
-
subscriptions.push(() => subscription.unsubscribe(
|
|
758
|
+
addSubscription(name, handler = () => false, data) {
|
|
759
|
+
subscription.subscribe(name, handler, data);
|
|
760
|
+
subscriptions.push(() => subscription.unsubscribe(name));
|
|
695
761
|
},
|
|
696
|
-
replaceSubscription(
|
|
697
|
-
subscription.replace(
|
|
698
|
-
subscriptions.push(() => subscription.unsubscribe(
|
|
762
|
+
replaceSubscription(name, handler = () => false, data) {
|
|
763
|
+
subscription.replace(name, handler, data);
|
|
764
|
+
subscriptions.push(() => subscription.unsubscribe(name));
|
|
699
765
|
},
|
|
700
766
|
removeSubscriptions() {
|
|
701
767
|
subscriptions.forEach((subscription2) => safeRequest({
|
|
702
768
|
try: () => subscription2()
|
|
703
769
|
}));
|
|
704
770
|
},
|
|
705
|
-
removeSubscription(
|
|
706
|
-
subscription.unsubscribe(
|
|
771
|
+
removeSubscription(name) {
|
|
772
|
+
subscription.unsubscribe(name);
|
|
707
773
|
},
|
|
708
|
-
hasSubscription(
|
|
709
|
-
return subscription.hasSubscription(
|
|
774
|
+
hasSubscription(name) {
|
|
775
|
+
return subscription.hasSubscription(name);
|
|
710
776
|
},
|
|
711
777
|
subscriptions,
|
|
712
778
|
subscription
|
|
713
779
|
};
|
|
714
780
|
}
|
|
781
|
+
var Prop = ({ default: value, type, validator, required } = {}) => {
|
|
782
|
+
const types1 = Array.isArray(type) ? type : [type != null ? type : Array];
|
|
783
|
+
const types2 = types1.includes(Object) ? types1 : types1.concat(Object);
|
|
784
|
+
return __spreadProps(__spreadValues({}, value ? { default: (0, import_vue2.ref)(value) } : {}), {
|
|
785
|
+
required,
|
|
786
|
+
validator: (value2) => {
|
|
787
|
+
return validator ? validator((0, import_vue2.unref)(value2)) : Array.from(new Set(types2.map((type2) => {
|
|
788
|
+
return typeof type2 === "function" ? type2().constructor.name : type2;
|
|
789
|
+
}))).includes((0, import_vue2.unref)(value2).constructor.name);
|
|
790
|
+
}
|
|
791
|
+
});
|
|
792
|
+
};
|
|
715
793
|
function StyleParser(styles = {}) {
|
|
716
794
|
const transform = (style, status = true) => {
|
|
717
795
|
const remove = style.split(/(-{[^}]+})/);
|
|
@@ -870,6 +948,7 @@ var dataPath = (component, path) => {
|
|
|
870
948
|
// Annotate the CommonJS export names for ESM import in node:
|
|
871
949
|
0 && (module.exports = {
|
|
872
950
|
MergeStyles,
|
|
951
|
+
Prop,
|
|
873
952
|
StyleParser,
|
|
874
953
|
access,
|
|
875
954
|
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.11";
|
|
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,54 @@ 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
|
+
if (props.debug) {
|
|
385
|
+
console.log(`log output:`, props, isRef(props.data), isReactive(props.data));
|
|
386
|
+
}
|
|
387
|
+
track(isRef(props.data) || isReactive(props.data) ? props.data : () => props.data, { immediate: false, deep: false });
|
|
388
|
+
}
|
|
389
|
+
}
|
|
325
390
|
});
|
|
326
391
|
setTimeout(async () => {
|
|
327
392
|
var _a3;
|
|
@@ -375,7 +440,7 @@ var ReactiveView_default = {
|
|
|
375
440
|
if (isReactive(data)) {
|
|
376
441
|
return data;
|
|
377
442
|
} else {
|
|
378
|
-
if (isRef(data) || isFunctionData ||
|
|
443
|
+
if (isRef(data) || isFunctionData || isAsyncData) {
|
|
379
444
|
return reactive(datatype);
|
|
380
445
|
} else {
|
|
381
446
|
const props2 = "data" in vue.vnode.props;
|
|
@@ -393,7 +458,7 @@ var ReactiveView_default = {
|
|
|
393
458
|
};
|
|
394
459
|
const config = {
|
|
395
460
|
data: props.beta ? normalize((_a2 = vue.vnode.props) == null ? void 0 : _a2.data) : reactive(ObjectManager.on(
|
|
396
|
-
|
|
461
|
+
isAsyncData || isFunctionData || isRef(props.data) || isReactive(props.data) ? datatype : "data" in vue.vnode.props ? props.data : datatype
|
|
397
462
|
).clone()),
|
|
398
463
|
defaultData: ObjectManager.on(defaultData).clone(),
|
|
399
464
|
notifications: props.notifications,
|
|
@@ -425,7 +490,7 @@ var ReactiveView_default = {
|
|
|
425
490
|
});
|
|
426
491
|
const component = ref({ parent: { self: vue.proxy }, self: { template, model, diff, emit, dataPath: dataPath2, isValid } });
|
|
427
492
|
if (props.debug) {
|
|
428
|
-
console.warn("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData,
|
|
493
|
+
console.warn("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isAsyncData });
|
|
429
494
|
}
|
|
430
495
|
const watchDataProp = (dataProp) => {
|
|
431
496
|
var _a3, _b3, _c3, _d2;
|
|
@@ -438,14 +503,14 @@ var ReactiveView_default = {
|
|
|
438
503
|
if (context.attrs["data:log"]) {
|
|
439
504
|
console.warn(`[ReactiveView]:data`, { config: config2, dataProp });
|
|
440
505
|
}
|
|
441
|
-
watch(isFunctionData || isRef(dataProp) || isReactive(dataProp) ? dataProp : () => dataProp, (after, before) => {
|
|
506
|
+
subscriptions.push(watch(isFunctionData || isRef(dataProp) || isReactive(dataProp) ? dataProp : () => dataProp, (after, before) => {
|
|
442
507
|
var _a4;
|
|
443
508
|
if (typeof config2.callback === "function") {
|
|
444
509
|
model.replaceData((_a4 = config2.callback(access(component).diff(ObjectManager.on(before), ObjectManager.on(after)), { component })) != null ? _a4 : after);
|
|
445
510
|
} else {
|
|
446
511
|
model.replaceData(after);
|
|
447
512
|
}
|
|
448
|
-
}, config2.options);
|
|
513
|
+
}, config2.options));
|
|
449
514
|
};
|
|
450
515
|
if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
|
|
451
516
|
const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
|
|
@@ -457,20 +522,20 @@ var ReactiveView_default = {
|
|
|
457
522
|
if (context.attrs["model:log"]) {
|
|
458
523
|
console.warn(`[ReactiveView]:model`, { config: config2 });
|
|
459
524
|
}
|
|
460
|
-
watch(() => ObjectManager.on(model.getData()).clone(), (after, before) => {
|
|
525
|
+
subscriptions.push(watch(() => ObjectManager.on(model.getData()).clone(), (after, before) => {
|
|
461
526
|
config2.callback(access(component).diff(ObjectManager.on(before), ObjectManager.on(after)), { component });
|
|
462
|
-
}, config2.options);
|
|
527
|
+
}, config2.options));
|
|
463
528
|
}
|
|
464
529
|
if (props.beta) {
|
|
465
530
|
const isRefData = isRef(props.data);
|
|
466
|
-
if (isRefData || isFunctionData ||
|
|
531
|
+
if (isRefData || isFunctionData || isAsyncData) {
|
|
467
532
|
setTimeout(async () => {
|
|
468
533
|
var _a3, _b3, _c3;
|
|
469
|
-
const [data] =
|
|
534
|
+
const [data] = isAsyncData ? await Promise.all([
|
|
470
535
|
isAsyncFunctionData ? props.data() : props.data,
|
|
471
536
|
(_a3 = defer.value) != null ? _a3 : true
|
|
472
537
|
]) : [props.data];
|
|
473
|
-
watch(isRefData ? data : isFunctionData ? data : typeof data === "function" ? data : () => data, (after, before) => {
|
|
538
|
+
subscriptions.push(watch(isRefData ? data : isFunctionData ? data : typeof data === "function" ? data : () => data, (after, before) => {
|
|
474
539
|
var _a4;
|
|
475
540
|
if (before !== void 0 || after !== void 0) {
|
|
476
541
|
const callback = context.attrs["data:callback"];
|
|
@@ -485,7 +550,7 @@ var ReactiveView_default = {
|
|
|
485
550
|
immediate: (_b3 = context.attrs["data:immediate"]) != null ? _b3 : true,
|
|
486
551
|
deep: (_c3 = context.attrs["data:deep"]) != null ? _c3 : true,
|
|
487
552
|
once: context.attrs["data:once"]
|
|
488
|
-
});
|
|
553
|
+
}));
|
|
489
554
|
});
|
|
490
555
|
}
|
|
491
556
|
} else {
|
|
@@ -643,29 +708,41 @@ function useSubscription() {
|
|
|
643
708
|
const subscriptions = [];
|
|
644
709
|
const subscription = Subscriptions.get();
|
|
645
710
|
return {
|
|
646
|
-
addSubscription(
|
|
647
|
-
subscription.subscribe(
|
|
648
|
-
subscriptions.push(() => subscription.unsubscribe(
|
|
711
|
+
addSubscription(name, handler = () => false, data) {
|
|
712
|
+
subscription.subscribe(name, handler, data);
|
|
713
|
+
subscriptions.push(() => subscription.unsubscribe(name));
|
|
649
714
|
},
|
|
650
|
-
replaceSubscription(
|
|
651
|
-
subscription.replace(
|
|
652
|
-
subscriptions.push(() => subscription.unsubscribe(
|
|
715
|
+
replaceSubscription(name, handler = () => false, data) {
|
|
716
|
+
subscription.replace(name, handler, data);
|
|
717
|
+
subscriptions.push(() => subscription.unsubscribe(name));
|
|
653
718
|
},
|
|
654
719
|
removeSubscriptions() {
|
|
655
720
|
subscriptions.forEach((subscription2) => safeRequest({
|
|
656
721
|
try: () => subscription2()
|
|
657
722
|
}));
|
|
658
723
|
},
|
|
659
|
-
removeSubscription(
|
|
660
|
-
subscription.unsubscribe(
|
|
724
|
+
removeSubscription(name) {
|
|
725
|
+
subscription.unsubscribe(name);
|
|
661
726
|
},
|
|
662
|
-
hasSubscription(
|
|
663
|
-
return subscription.hasSubscription(
|
|
727
|
+
hasSubscription(name) {
|
|
728
|
+
return subscription.hasSubscription(name);
|
|
664
729
|
},
|
|
665
730
|
subscriptions,
|
|
666
731
|
subscription
|
|
667
732
|
};
|
|
668
733
|
}
|
|
734
|
+
var Prop = ({ default: value, type, validator, required } = {}) => {
|
|
735
|
+
const types1 = Array.isArray(type) ? type : [type != null ? type : Array];
|
|
736
|
+
const types2 = types1.includes(Object) ? types1 : types1.concat(Object);
|
|
737
|
+
return __spreadProps(__spreadValues({}, value ? { default: ref2(value) } : {}), {
|
|
738
|
+
required,
|
|
739
|
+
validator: (value2) => {
|
|
740
|
+
return validator ? validator(unref2(value2)) : Array.from(new Set(types2.map((type2) => {
|
|
741
|
+
return typeof type2 === "function" ? type2().constructor.name : type2;
|
|
742
|
+
}))).includes(unref2(value2).constructor.name);
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
};
|
|
669
746
|
function StyleParser(styles = {}) {
|
|
670
747
|
const transform = (style, status = true) => {
|
|
671
748
|
const remove = style.split(/(-{[^}]+})/);
|
|
@@ -823,6 +900,7 @@ var dataPath = (component, path) => {
|
|
|
823
900
|
};
|
|
824
901
|
export {
|
|
825
902
|
MergeStyles,
|
|
903
|
+
Prop,
|
|
826
904
|
StyleParser,
|
|
827
905
|
access,
|
|
828
906
|
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.11",
|
|
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"
|