@razaman2/reactive-view 0.1.0-beta.15 → 0.1.0-beta.17
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/LICENSE +21 -21
- package/README.md +1 -1
- package/dist/ReactiveView.d.ts +48 -0
- package/dist/Subscription.d.ts +17 -0
- package/dist/Subscriptions.d.ts +5 -0
- package/dist/Types.d.ts +28 -0
- package/dist/components/CustomAlert.vue.d.ts +47 -0
- package/dist/components/CustomButton.vue.d.ts +3 -0
- package/dist/components/CustomModal.vue.d.ts +3 -0
- package/dist/components/TestComponent.vue.d.ts +6 -0
- package/dist/index.d.ts +31 -119
- package/dist/index.js +1 -964
- package/dist/index.mjs +931 -906
- package/dist/showComponent.d.ts +5 -0
- package/package.json +81 -48
- package/dist/index.d.mts +0 -148
package/dist/index.js
CHANGED
|
@@ -1,964 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defProps = Object.defineProperties;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __spreadValues = (a, b) => {
|
|
14
|
-
for (var prop in b || (b = {}))
|
|
15
|
-
if (__hasOwnProp.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
if (__getOwnPropSymbols)
|
|
18
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
-
if (__propIsEnum.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
};
|
|
24
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
-
var __objRest = (source, exclude) => {
|
|
26
|
-
var target = {};
|
|
27
|
-
for (var prop in source)
|
|
28
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
if (source != null && __getOwnPropSymbols)
|
|
31
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
-
target[prop] = source[prop];
|
|
34
|
-
}
|
|
35
|
-
return target;
|
|
36
|
-
};
|
|
37
|
-
var __export = (target, all) => {
|
|
38
|
-
for (var name in all)
|
|
39
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
-
};
|
|
41
|
-
var __copyProps = (to, from, except, desc) => {
|
|
42
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
-
for (let key of __getOwnPropNames(from))
|
|
44
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
-
}
|
|
47
|
-
return to;
|
|
48
|
-
};
|
|
49
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
50
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
51
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
52
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
53
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
54
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
55
|
-
mod
|
|
56
|
-
));
|
|
57
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
|
-
|
|
59
|
-
// src/index.ts
|
|
60
|
-
var index_exports = {};
|
|
61
|
-
__export(index_exports, {
|
|
62
|
-
MergeStyles: () => MergeStyles,
|
|
63
|
-
Prop: () => Prop,
|
|
64
|
-
StyleParser: () => StyleParser,
|
|
65
|
-
access: () => access,
|
|
66
|
-
dataPath: () => dataPath,
|
|
67
|
-
default: () => index_default,
|
|
68
|
-
defineReactiveView: () => defineReactiveView,
|
|
69
|
-
extendVnode: () => extendVnode,
|
|
70
|
-
getData: () => getData,
|
|
71
|
-
getDate: () => getDate,
|
|
72
|
-
getProps: () => getProps,
|
|
73
|
-
getReactiveViewComponent: () => getReactiveViewComponent,
|
|
74
|
-
safeRequest: () => safeRequest,
|
|
75
|
-
setData: () => setData,
|
|
76
|
-
setup: () => setup,
|
|
77
|
-
showComponent: () => showComponent,
|
|
78
|
-
useSubscription: () => useSubscription
|
|
79
|
-
});
|
|
80
|
-
module.exports = __toCommonJS(index_exports);
|
|
81
|
-
var import_object_manager2 = __toESM(require("@razaman2/object-manager"));
|
|
82
|
-
|
|
83
|
-
// src/Subscription.ts
|
|
84
|
-
var Subscription = class _Subscription {
|
|
85
|
-
constructor() {
|
|
86
|
-
this.subscriptions = [];
|
|
87
|
-
this.data = {};
|
|
88
|
-
}
|
|
89
|
-
static create() {
|
|
90
|
-
return new _Subscription();
|
|
91
|
-
}
|
|
92
|
-
subscribe(name, handler, data) {
|
|
93
|
-
if (this.isNameAvailable(name)) {
|
|
94
|
-
this.subscriptions.push({
|
|
95
|
-
name,
|
|
96
|
-
handler
|
|
97
|
-
});
|
|
98
|
-
this.data[name] = data;
|
|
99
|
-
}
|
|
100
|
-
return this;
|
|
101
|
-
}
|
|
102
|
-
replace(name, handler, data) {
|
|
103
|
-
this.unsubscribe(name);
|
|
104
|
-
return this.subscribe(name, handler, data);
|
|
105
|
-
}
|
|
106
|
-
unsubscribe(param1) {
|
|
107
|
-
if (!Array.isArray(param1)) {
|
|
108
|
-
param1 = param1 ? [param1] : [];
|
|
109
|
-
}
|
|
110
|
-
const log = (name) => {
|
|
111
|
-
return console.log(`%cUnsubscribed From Subscription (${name})`, "background-color: yellow; color: green; font-weight: bold; padding: 3px;");
|
|
112
|
-
};
|
|
113
|
-
if (param1.length) {
|
|
114
|
-
param1.forEach((name) => {
|
|
115
|
-
const subscription = this.find(name);
|
|
116
|
-
if (subscription) {
|
|
117
|
-
subscription.handler();
|
|
118
|
-
this.remove(subscription);
|
|
119
|
-
log(name);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
} else {
|
|
123
|
-
this.subscriptions.forEach((subscription) => {
|
|
124
|
-
subscription.handler();
|
|
125
|
-
log(subscription.name);
|
|
126
|
-
});
|
|
127
|
-
this.subscriptions = [];
|
|
128
|
-
}
|
|
129
|
-
return this;
|
|
130
|
-
}
|
|
131
|
-
size() {
|
|
132
|
-
return this.subscriptions.length;
|
|
133
|
-
}
|
|
134
|
-
hasSubscription(name) {
|
|
135
|
-
return Boolean(this.find(name));
|
|
136
|
-
}
|
|
137
|
-
remove(subscription) {
|
|
138
|
-
this.subscriptions.splice(this.subscriptions.indexOf(subscription), 1);
|
|
139
|
-
}
|
|
140
|
-
find(name) {
|
|
141
|
-
return this.subscriptions.find((subscription) => {
|
|
142
|
-
return subscription.name === name;
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
isNameAvailable(name) {
|
|
146
|
-
if (this.hasSubscription(name)) {
|
|
147
|
-
throw new Error(`There is already a subscription called "${name}".`);
|
|
148
|
-
} else {
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
registrations() {
|
|
153
|
-
return this.subscriptions;
|
|
154
|
-
}
|
|
155
|
-
get(name) {
|
|
156
|
-
const subscription = this.find(name);
|
|
157
|
-
if (subscription) {
|
|
158
|
-
return subscription;
|
|
159
|
-
} else {
|
|
160
|
-
throw new Error(`Subscription "${name}" doesn't exist!`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
// src/Subscriptions.ts
|
|
166
|
-
var _Subscriptions = class _Subscriptions extends Subscription {
|
|
167
|
-
static get() {
|
|
168
|
-
return this.subscriptions;
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
_Subscriptions.subscriptions = _Subscriptions.create();
|
|
172
|
-
var Subscriptions = _Subscriptions;
|
|
173
|
-
|
|
174
|
-
// src/ReactiveView.ts
|
|
175
|
-
var import_object_manager = __toESM(require("@razaman2/object-manager"));
|
|
176
|
-
var import_data_manager = __toESM(require("@razaman2/data-manager"));
|
|
177
|
-
var import_vue = require("vue");
|
|
178
|
-
|
|
179
|
-
// package.json
|
|
180
|
-
var version = "0.1.0-beta.15";
|
|
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
|
-
};
|
|
229
|
-
|
|
230
|
-
// src/ReactiveView.ts
|
|
231
|
-
var setup = {
|
|
232
|
-
type: Function,
|
|
233
|
-
default: (parent = {}, self = {}) => self,
|
|
234
|
-
ReactiveView: true
|
|
235
|
-
};
|
|
236
|
-
var ReactiveView_default = {
|
|
237
|
-
props: {
|
|
238
|
-
setup: {},
|
|
239
|
-
beta: [Boolean, String],
|
|
240
|
-
ReactiveView: {
|
|
241
|
-
type: Boolean,
|
|
242
|
-
default: true
|
|
243
|
-
},
|
|
244
|
-
instance: { default: (0, import_vue.ref)() },
|
|
245
|
-
notifications: Object,
|
|
246
|
-
subscriptions: Object,
|
|
247
|
-
beforeSetData: Function,
|
|
248
|
-
data: { default: (0, import_vue.reactive)({}) },
|
|
249
|
-
defaultData: {},
|
|
250
|
-
getDefaultData: {
|
|
251
|
-
type: Function,
|
|
252
|
-
default: (data) => data
|
|
253
|
-
},
|
|
254
|
-
model: {},
|
|
255
|
-
defer: {},
|
|
256
|
-
logging: {
|
|
257
|
-
validator: (logging) => {
|
|
258
|
-
return ["Boolean"].includes(logging.constructor.name);
|
|
259
|
-
}
|
|
260
|
-
},
|
|
261
|
-
modelName: {
|
|
262
|
-
type: String,
|
|
263
|
-
default: "ReactiveView"
|
|
264
|
-
},
|
|
265
|
-
debug: {
|
|
266
|
-
type: Boolean,
|
|
267
|
-
default: false
|
|
268
|
-
},
|
|
269
|
-
state: { default: (0, import_vue.reactive)({}) }
|
|
270
|
-
},
|
|
271
|
-
setup(props, context) {
|
|
272
|
-
var _a, _b, _c;
|
|
273
|
-
const subscriptions = [];
|
|
274
|
-
(0, import_vue.onBeforeUnmount)(() => subscriptions.forEach((subscription) => subscription()));
|
|
275
|
-
const diff = (before, after) => {
|
|
276
|
-
const changed = (0, import_vue.ref)(false);
|
|
277
|
-
const paths = Array.from(new Set(before.paths().concat(after.paths())));
|
|
278
|
-
const changes = paths.reduce((changes2, path) => {
|
|
279
|
-
if (before.get(path) !== after.get(path)) {
|
|
280
|
-
changes2.set(path, after.get(path));
|
|
281
|
-
changed.value = true;
|
|
282
|
-
}
|
|
283
|
-
return changes2;
|
|
284
|
-
}, import_object_manager.default.on({}));
|
|
285
|
-
return { before: before.get(), after: after.get(), changes: changes.get(), changed: changed.value };
|
|
286
|
-
};
|
|
287
|
-
const dataPath2 = (path) => {
|
|
288
|
-
try {
|
|
289
|
-
return context.attrs["data:path"](path);
|
|
290
|
-
} catch (e) {
|
|
291
|
-
return path;
|
|
292
|
-
}
|
|
293
|
-
};
|
|
294
|
-
const template = (component, vue2) => {
|
|
295
|
-
return (0, import_vue.createVNode)("div", context.slots.default ? context.attrs : __spreadValues({
|
|
296
|
-
style: { color: "red", textAlign: "center" }
|
|
297
|
-
}, context.attrs), context.slots.default ? context.slots.default({ component, vue: vue2, props, context }) : `${props.modelName}: ${package_default.name}@${package_default.version}`);
|
|
298
|
-
};
|
|
299
|
-
const isValid = (0, import_vue.ref)(false);
|
|
300
|
-
const isReady = (0, import_vue.ref)(false);
|
|
301
|
-
const defer = (0, import_vue.ref)(typeof props.defer === "function" ? props.defer() : props.defer);
|
|
302
|
-
const isFunctionData = ["Function"].includes((_a = props.data) == null ? void 0 : _a.constructor.name);
|
|
303
|
-
const isAsyncFunctionData = ["AsyncFunction"].includes((_b = props.data) == null ? void 0 : _b.constructor.name);
|
|
304
|
-
const isAsyncData = ["Promise"].includes((_c = props.data) == null ? void 0 : _c.constructor.name) || isAsyncFunctionData;
|
|
305
|
-
const vue = (0, import_vue.getCurrentInstance)();
|
|
306
|
-
const defaultData = props.getDefaultData(
|
|
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)) ? [] : {} : {}
|
|
308
|
-
);
|
|
309
|
-
const datatype = Array.isArray(defaultData) ? [] : {};
|
|
310
|
-
const beta = () => {
|
|
311
|
-
var _a2;
|
|
312
|
-
const emit = (after, before) => {
|
|
313
|
-
if (vue && vue.vnode.el) {
|
|
314
|
-
const event = new CustomEvent("data:emit", {
|
|
315
|
-
bubbles: true,
|
|
316
|
-
// Key: allows it to travel up
|
|
317
|
-
composed: true,
|
|
318
|
-
// Key: allows it to cross Shadow DOM boundaries
|
|
319
|
-
detail: { before, after }
|
|
320
|
-
// Payload goes here
|
|
321
|
-
});
|
|
322
|
-
access(component).model.setData(after);
|
|
323
|
-
vue.vnode.el.dispatchEvent(event);
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
const proxy = (data) => {
|
|
327
|
-
return new Proxy(data, {
|
|
328
|
-
get(target, key, receiver) {
|
|
329
|
-
if (["setData", "replaceData"].includes(key.toString())) {
|
|
330
|
-
return (...params) => {
|
|
331
|
-
var _a3;
|
|
332
|
-
const beforeSetData = (_a3 = access(component).beforeSetData) != null ? _a3 : props.beforeSetData;
|
|
333
|
-
if (typeof beforeSetData === "function") {
|
|
334
|
-
const before = import_object_manager.default.on(target.getData());
|
|
335
|
-
const after = params.length ? import_object_manager.default.on(datatype).set(...params) : import_object_manager.default.on(datatype).set(defaultData);
|
|
336
|
-
const diff2 = access(component).diff(before, after);
|
|
337
|
-
if (beforeSetData(diff2, target)) {
|
|
338
|
-
target[key](...params);
|
|
339
|
-
}
|
|
340
|
-
} else {
|
|
341
|
-
target[key](...params);
|
|
342
|
-
}
|
|
343
|
-
return target;
|
|
344
|
-
};
|
|
345
|
-
} else {
|
|
346
|
-
return Reflect.get(target, key, receiver);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
};
|
|
351
|
-
const normalize = (data) => {
|
|
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);
|
|
356
|
-
} else {
|
|
357
|
-
const props2 = "data" in vue.vnode.props;
|
|
358
|
-
try {
|
|
359
|
-
if (["Array", "Object"].includes(data.constructor.name)) {
|
|
360
|
-
return (0, import_vue.ref)(data);
|
|
361
|
-
} else {
|
|
362
|
-
return (0, import_vue.ref)(props2 ? { "": data } : datatype);
|
|
363
|
-
}
|
|
364
|
-
} catch (e) {
|
|
365
|
-
return (0, import_vue.ref)(props2 ? { "": data } : datatype);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
};
|
|
369
|
-
const config = {
|
|
370
|
-
data: normalize((_a2 = vue.vnode.props) == null ? void 0 : _a2.data),
|
|
371
|
-
defaultData: import_object_manager.default.on(defaultData).clone(),
|
|
372
|
-
notifications: props.notifications,
|
|
373
|
-
subscriptions: props.subscriptions,
|
|
374
|
-
name: props.modelName,
|
|
375
|
-
logging: props.logging
|
|
376
|
-
};
|
|
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);
|
|
378
|
-
const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, diff, emit, dataPath: dataPath2, model: proxy(model), isValid } });
|
|
379
|
-
if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
|
|
380
|
-
const config2 = {
|
|
381
|
-
callback: typeof context.attrs["onUpdate:model"] === "function" ? context.attrs["onUpdate:model"] : context.attrs["update:model"],
|
|
382
|
-
options: {
|
|
383
|
-
immediate: context.attrs["model:immediate"],
|
|
384
|
-
deep: context.attrs["model:deep"],
|
|
385
|
-
once: context.attrs["model:once"]
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
const source = () => import_object_manager.default.on(model.getData()).clone();
|
|
389
|
-
subscriptions.push((0, import_vue.watch)(source, (after, before) => {
|
|
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
|
-
}
|
|
394
|
-
if (diff2.changed) {
|
|
395
|
-
config2.callback(diff2, { component });
|
|
396
|
-
}
|
|
397
|
-
}, config2.options));
|
|
398
|
-
}
|
|
399
|
-
const track = (source, options = {}) => {
|
|
400
|
-
var _a3, _b2, _c2, _d, _e;
|
|
401
|
-
subscriptions.push((0, import_vue.watch)(source, async (after, before) => {
|
|
402
|
-
const diff2 = access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after));
|
|
403
|
-
const callback = context.attrs["data:callback"];
|
|
404
|
-
if (typeof callback === "function") {
|
|
405
|
-
callback(diff2, { component });
|
|
406
|
-
} else {
|
|
407
|
-
model.replaceData(after);
|
|
408
|
-
}
|
|
409
|
-
}, {
|
|
410
|
-
immediate: (_b2 = (_a3 = context.attrs["data:immediate"]) != null ? _a3 : options.immediate) != null ? _b2 : true,
|
|
411
|
-
deep: (_d = (_c2 = context.attrs["data:deep"]) != null ? _c2 : options.deep) != null ? _d : true,
|
|
412
|
-
once: (_e = context.attrs["data:once"]) != null ? _e : options.once
|
|
413
|
-
}));
|
|
414
|
-
};
|
|
415
|
-
setTimeout(async () => {
|
|
416
|
-
var _a3;
|
|
417
|
-
if (props.model !== false) {
|
|
418
|
-
if (isFunctionData || isAsyncData) {
|
|
419
|
-
if (!("defaultData" in vue.vnode.props)) {
|
|
420
|
-
console.warn(`${props.modelName}: defaultData is required for promise or function data.`, props.data);
|
|
421
|
-
}
|
|
422
|
-
const [data] = isAsyncData ? await Promise.all([
|
|
423
|
-
isAsyncFunctionData ? props.data() : props.data,
|
|
424
|
-
(_a3 = defer.value) != null ? _a3 : true
|
|
425
|
-
]) : [props.data];
|
|
426
|
-
track(typeof data === "function" ? data : (() => data));
|
|
427
|
-
} else {
|
|
428
|
-
track((0, import_vue.isRef)(props.data) || (0, import_vue.isReactive)(props.data) ? props.data : () => props.data, { immediate: false, deep: false });
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
});
|
|
432
|
-
setTimeout(async () => {
|
|
433
|
-
var _a3;
|
|
434
|
-
isReady.value = (_a3 = await defer.value) != null ? _a3 : true;
|
|
435
|
-
});
|
|
436
|
-
component.value = [access(component)].reduce((options, parent) => {
|
|
437
|
-
var _a3;
|
|
438
|
-
while (parent) {
|
|
439
|
-
if (typeof parent.setup === "function") {
|
|
440
|
-
options = { parent: options, self: (_a3 = parent.setup(component, options)) != null ? _a3 : {} };
|
|
441
|
-
if (access(parent.$parent).ReactiveView) {
|
|
442
|
-
break;
|
|
443
|
-
} else {
|
|
444
|
-
parent = access(parent.$parent);
|
|
445
|
-
}
|
|
446
|
-
} else {
|
|
447
|
-
break;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
return options;
|
|
451
|
-
}, component.value);
|
|
452
|
-
props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
|
|
453
|
-
return (vue2) => {
|
|
454
|
-
var _a3, _b2;
|
|
455
|
-
if (isReady.value) {
|
|
456
|
-
return access(component).template(component, vue2);
|
|
457
|
-
} else {
|
|
458
|
-
return (_b2 = (_a3 = context.slots).loading) == null ? void 0 : _b2.call(_a3, { component });
|
|
459
|
-
}
|
|
460
|
-
};
|
|
461
|
-
};
|
|
462
|
-
const current = () => {
|
|
463
|
-
var _a2, _b2, _c2, _d;
|
|
464
|
-
const emit = (after, before) => {
|
|
465
|
-
if (vue && vue.vnode.el) {
|
|
466
|
-
const event = new CustomEvent("data:emit", {
|
|
467
|
-
bubbles: true,
|
|
468
|
-
// Key: allows it to travel up
|
|
469
|
-
composed: true,
|
|
470
|
-
// Key: allows it to cross Shadow DOM boundaries
|
|
471
|
-
detail: { before, after }
|
|
472
|
-
// Payload goes here
|
|
473
|
-
});
|
|
474
|
-
vue.vnode.el.dispatchEvent(event);
|
|
475
|
-
}
|
|
476
|
-
};
|
|
477
|
-
const normalize = (data) => {
|
|
478
|
-
if (props.debug) {
|
|
479
|
-
console.warn(`[ReactiveView]: using beta props data in [${props.modelName}] component`, { vue, data, defaultData, isRef: (0, import_vue.isRef)(data), isReactive: (0, import_vue.isReactive)(data) });
|
|
480
|
-
}
|
|
481
|
-
if ((0, import_vue.isReactive)(data)) {
|
|
482
|
-
return data;
|
|
483
|
-
} else {
|
|
484
|
-
if ((0, import_vue.isRef)(data) || isFunctionData || isAsyncData) {
|
|
485
|
-
return (0, import_vue.reactive)(datatype);
|
|
486
|
-
} else {
|
|
487
|
-
const props2 = "data" in vue.vnode.props;
|
|
488
|
-
try {
|
|
489
|
-
if (["Array", "Object"].includes(data.constructor.name)) {
|
|
490
|
-
return (0, import_vue.reactive)(props2 ? data : datatype);
|
|
491
|
-
} else {
|
|
492
|
-
return (0, import_vue.reactive)(props2 ? { "": data } : datatype);
|
|
493
|
-
}
|
|
494
|
-
} catch (e) {
|
|
495
|
-
return (0, import_vue.reactive)(props2 ? { "": data } : datatype);
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
};
|
|
500
|
-
const config = {
|
|
501
|
-
data: props.beta ? normalize((_a2 = vue.vnode.props) == null ? void 0 : _a2.data) : (0, import_vue.reactive)(import_object_manager.default.on(
|
|
502
|
-
isAsyncData || isFunctionData || (0, import_vue.isRef)(props.data) || (0, import_vue.isReactive)(props.data) ? datatype : "data" in vue.vnode.props ? props.data : datatype
|
|
503
|
-
).clone()),
|
|
504
|
-
defaultData: import_object_manager.default.on(defaultData).clone(),
|
|
505
|
-
notifications: props.notifications,
|
|
506
|
-
subscriptions: props.subscriptions,
|
|
507
|
-
name: props.modelName,
|
|
508
|
-
logging: props.logging
|
|
509
|
-
};
|
|
510
|
-
const model = new Proxy(props.model ? typeof props.model === "function" ? props.model(config) : props.model : new import_data_manager.default(config), {
|
|
511
|
-
get(target, key, receiver) {
|
|
512
|
-
if (["setData", "replaceData"].includes(key.toString())) {
|
|
513
|
-
return (...params) => {
|
|
514
|
-
var _a3;
|
|
515
|
-
const beforeSetData = (_a3 = access(component).beforeSetData) != null ? _a3 : props.beforeSetData;
|
|
516
|
-
if (typeof beforeSetData === "function") {
|
|
517
|
-
const before = import_object_manager.default.on(target.getData());
|
|
518
|
-
const after = params.length ? import_object_manager.default.on(datatype).set(...params) : import_object_manager.default.on(datatype).set(defaultData);
|
|
519
|
-
if (beforeSetData(access(component).diff(before, after), target)) {
|
|
520
|
-
target[key](...params);
|
|
521
|
-
}
|
|
522
|
-
} else {
|
|
523
|
-
target[key](...params);
|
|
524
|
-
}
|
|
525
|
-
return target;
|
|
526
|
-
};
|
|
527
|
-
} else {
|
|
528
|
-
return Reflect.get(target, key, receiver);
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
});
|
|
532
|
-
const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, diff, emit, dataPath: dataPath2, isValid } });
|
|
533
|
-
if (props.debug) {
|
|
534
|
-
console.warn("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isAsyncData });
|
|
535
|
-
}
|
|
536
|
-
const watchDataProp = (dataProp) => {
|
|
537
|
-
var _a3, _b3, _c3, _d2;
|
|
538
|
-
const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
|
|
539
|
-
callback: (_b3 = ((_a3 = context.attrs["onUpdate:data"]) != null ? _a3 : {}).callback) != null ? _b3 : context.attrs["data:callback"],
|
|
540
|
-
options: Object.assign(__spreadValues(__spreadValues({
|
|
541
|
-
deep: (_c3 = context.attrs["data:deep"]) != null ? _c3 : true
|
|
542
|
-
}, context.attrs["data:immediate"] ? { immediate: context.attrs["data:immediate"] } : {}), context.attrs["data:once"] ? { once: context.attrs["data:once"] } : {}), ((_d2 = context.attrs["onUpdate:data"]) != null ? _d2 : {}).options)
|
|
543
|
-
};
|
|
544
|
-
if (context.attrs["data:log"]) {
|
|
545
|
-
console.warn(`[ReactiveView]:data`, { config: config2, dataProp });
|
|
546
|
-
}
|
|
547
|
-
subscriptions.push((0, import_vue.watch)(isFunctionData || (0, import_vue.isRef)(dataProp) || (0, import_vue.isReactive)(dataProp) ? dataProp : () => dataProp, (after, before) => {
|
|
548
|
-
var _a4;
|
|
549
|
-
if (typeof config2.callback === "function") {
|
|
550
|
-
model.replaceData((_a4 = config2.callback(access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component })) != null ? _a4 : after);
|
|
551
|
-
} else {
|
|
552
|
-
model.replaceData(after);
|
|
553
|
-
}
|
|
554
|
-
}, config2.options));
|
|
555
|
-
};
|
|
556
|
-
if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
|
|
557
|
-
const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
|
|
558
|
-
callback: context.attrs["onUpdate:model"],
|
|
559
|
-
options: Object.assign(__spreadValues(__spreadValues({
|
|
560
|
-
deep: (_b2 = context.attrs["model:deep"]) != null ? _b2 : true
|
|
561
|
-
}, context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {}), context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}), ((_c2 = context.attrs["onUpdate:model"]) != null ? _c2 : {}).options)
|
|
562
|
-
} : (_d = context.attrs["onUpdate:model"]) != null ? _d : {};
|
|
563
|
-
if (context.attrs["model:log"]) {
|
|
564
|
-
console.warn(`[ReactiveView]:model`, { config: config2 });
|
|
565
|
-
}
|
|
566
|
-
subscriptions.push((0, import_vue.watch)(() => import_object_manager.default.on(model.getData()).clone(), (after, before) => {
|
|
567
|
-
config2.callback(access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component });
|
|
568
|
-
}, config2.options));
|
|
569
|
-
}
|
|
570
|
-
if (props.beta) {
|
|
571
|
-
const isRefData = (0, import_vue.isRef)(props.data);
|
|
572
|
-
if (isRefData || isFunctionData || isAsyncData) {
|
|
573
|
-
setTimeout(async () => {
|
|
574
|
-
var _a3, _b3, _c3;
|
|
575
|
-
const [data] = isAsyncData ? await Promise.all([
|
|
576
|
-
isAsyncFunctionData ? props.data() : props.data,
|
|
577
|
-
(_a3 = defer.value) != null ? _a3 : true
|
|
578
|
-
]) : [props.data];
|
|
579
|
-
subscriptions.push((0, import_vue.watch)(isRefData ? data : isFunctionData ? data : typeof data === "function" ? data : () => data, (after, before) => {
|
|
580
|
-
var _a4;
|
|
581
|
-
if (before !== void 0 || after !== void 0) {
|
|
582
|
-
const callback = context.attrs["data:callback"];
|
|
583
|
-
if (typeof callback === "function") {
|
|
584
|
-
const diff2 = access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after));
|
|
585
|
-
model.replaceData((_a4 = callback(diff2, { component })) != null ? _a4 : after);
|
|
586
|
-
} else {
|
|
587
|
-
model.replaceData(after);
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
}, {
|
|
591
|
-
immediate: (_b3 = context.attrs["data:immediate"]) != null ? _b3 : true,
|
|
592
|
-
deep: (_c3 = context.attrs["data:deep"]) != null ? _c3 : true,
|
|
593
|
-
once: context.attrs["data:once"]
|
|
594
|
-
}));
|
|
595
|
-
});
|
|
596
|
-
}
|
|
597
|
-
} else {
|
|
598
|
-
setTimeout(async () => {
|
|
599
|
-
var _a3;
|
|
600
|
-
const [data] = await Promise.all([
|
|
601
|
-
isAsyncFunctionData ? props.data() : props.data,
|
|
602
|
-
(_a3 = defer.value) != null ? _a3 : true
|
|
603
|
-
]);
|
|
604
|
-
watchDataProp(data);
|
|
605
|
-
});
|
|
606
|
-
}
|
|
607
|
-
setTimeout(async () => {
|
|
608
|
-
var _a3;
|
|
609
|
-
isReady.value = (_a3 = await defer.value) != null ? _a3 : true;
|
|
610
|
-
});
|
|
611
|
-
component.value = [access(component)].reduce((options, parent) => {
|
|
612
|
-
var _a3;
|
|
613
|
-
while (parent) {
|
|
614
|
-
if (typeof parent.setup === "function") {
|
|
615
|
-
options = { parent: options, self: (_a3 = parent.setup(component, options)) != null ? _a3 : {} };
|
|
616
|
-
if (access(parent.$parent).ReactiveView) {
|
|
617
|
-
break;
|
|
618
|
-
} else {
|
|
619
|
-
parent = access(parent.$parent);
|
|
620
|
-
}
|
|
621
|
-
} else {
|
|
622
|
-
break;
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
return options;
|
|
626
|
-
}, component.value);
|
|
627
|
-
props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
|
|
628
|
-
return (vue2) => {
|
|
629
|
-
var _a3, _b3;
|
|
630
|
-
if (isReady.value) {
|
|
631
|
-
return access(component).template(component, vue2);
|
|
632
|
-
} else {
|
|
633
|
-
return (_b3 = (_a3 = context.slots).loading) == null ? void 0 : _b3.call(_a3, { component });
|
|
634
|
-
}
|
|
635
|
-
};
|
|
636
|
-
};
|
|
637
|
-
return props.beta === "next" ? beta() : current();
|
|
638
|
-
}
|
|
639
|
-
};
|
|
640
|
-
|
|
641
|
-
// src/index.ts
|
|
642
|
-
var import_vue2 = require("vue");
|
|
643
|
-
var import_date_fns_tz = require("date-fns-tz");
|
|
644
|
-
var import_tailwind_merge = require("tailwind-merge");
|
|
645
|
-
console.log(`%c[ReactiveView]: ${version}`, "background-color: red; color: yellow;");
|
|
646
|
-
var index_default = ReactiveView_default;
|
|
647
|
-
function safeRequest(request) {
|
|
648
|
-
return new Promise(async (resolve) => {
|
|
649
|
-
var _a, _b, _c, _d;
|
|
650
|
-
const { message } = (_a = request.loading) != null ? _a : {};
|
|
651
|
-
if (request.loading) {
|
|
652
|
-
request.loading.status = true;
|
|
653
|
-
if (request.message) {
|
|
654
|
-
request.loading.message = request.message;
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
try {
|
|
658
|
-
resolve(await request.try());
|
|
659
|
-
} catch (e) {
|
|
660
|
-
if ((_b = request.alternative) != null ? _b : true) {
|
|
661
|
-
resolve(request.catch ? await request.catch(e) : console.log(e));
|
|
662
|
-
}
|
|
663
|
-
} finally {
|
|
664
|
-
await ((_c = request.finally) == null ? void 0 : _c.call(request));
|
|
665
|
-
if (request.loading) {
|
|
666
|
-
request.loading.status = false;
|
|
667
|
-
}
|
|
668
|
-
if (request.loading && message) {
|
|
669
|
-
request.loading.message = message;
|
|
670
|
-
}
|
|
671
|
-
await ((_d = request.complete) == null ? void 0 : _d.call(request));
|
|
672
|
-
}
|
|
673
|
-
});
|
|
674
|
-
}
|
|
675
|
-
function getProps(props = {}, param2) {
|
|
676
|
-
var _a;
|
|
677
|
-
const exclude = Array.isArray(param2) || typeof param2 === "string" ? param2 : param2.exclude;
|
|
678
|
-
const exclusions = (Array.isArray(exclude) ? exclude : [exclude]).join("|");
|
|
679
|
-
const include = (_a = param2.include) != null ? _a : {};
|
|
680
|
-
return Object.entries(include).reduce((props2, [key, val]) => {
|
|
681
|
-
props2[key] = val;
|
|
682
|
-
return props2;
|
|
683
|
-
}, Object.entries(props).reduce((props2, [key, val]) => {
|
|
684
|
-
if (!RegExp(`(^|\\|)${key}($|\\|)`, "i").test(exclusions)) {
|
|
685
|
-
props2[key] = val;
|
|
686
|
-
}
|
|
687
|
-
return props2;
|
|
688
|
-
}, {}));
|
|
689
|
-
}
|
|
690
|
-
function getReactiveViewComponent(component, options = {}) {
|
|
691
|
-
const model = (component2) => {
|
|
692
|
-
try {
|
|
693
|
-
return (component2.type || component2).props.hasOwnProperty("model");
|
|
694
|
-
} catch (e) {
|
|
695
|
-
return false;
|
|
696
|
-
}
|
|
697
|
-
};
|
|
698
|
-
const props = getProps(options, "setup");
|
|
699
|
-
const slots = typeof component === "function" ? component : () => {
|
|
700
|
-
return (component.type || component).setup ? (0, import_vue2.createVNode)(component, component.setup ? {} : props) : component;
|
|
701
|
-
};
|
|
702
|
-
return model(component) ? (0, import_vue2.createVNode)(component, props) : (0, import_vue2.createVNode)(ReactiveView_default, props, slots);
|
|
703
|
-
}
|
|
704
|
-
function getDate(param1, param2) {
|
|
705
|
-
var _a, _b;
|
|
706
|
-
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
707
|
-
const format = "MM/dd/yyyy h:mm a";
|
|
708
|
-
const options = typeof param2 === "string" ? { format: param2, timezone } : { format: (_a = param2 == null ? void 0 : param2.format) != null ? _a : format, timezone: (_b = param2 == null ? void 0 : param2.timezone) != null ? _b : timezone };
|
|
709
|
-
const datetime = () => {
|
|
710
|
-
try {
|
|
711
|
-
return param1 instanceof Date ? param1 : param1.toDate();
|
|
712
|
-
} catch (e) {
|
|
713
|
-
return /* @__PURE__ */ new Date();
|
|
714
|
-
}
|
|
715
|
-
};
|
|
716
|
-
return (0, import_date_fns_tz.formatInTimeZone)(datetime(), options.timezone, options.format);
|
|
717
|
-
}
|
|
718
|
-
function access(view = {}, alternative) {
|
|
719
|
-
var _a;
|
|
720
|
-
const resolve = (target) => {
|
|
721
|
-
return new Proxy((0, import_vue2.toRaw)(target), {
|
|
722
|
-
get(target2, key) {
|
|
723
|
-
const component = { tree: target2 };
|
|
724
|
-
do {
|
|
725
|
-
if (key in component.tree) {
|
|
726
|
-
return component.tree[key];
|
|
727
|
-
} else if ("self" in component.tree && key in component.tree.self) {
|
|
728
|
-
return component.tree.self[key];
|
|
729
|
-
} else {
|
|
730
|
-
component.tree = "parent" in component.tree && component.tree.parent;
|
|
731
|
-
}
|
|
732
|
-
} while (component.tree);
|
|
733
|
-
try {
|
|
734
|
-
return new alternative();
|
|
735
|
-
} catch (e) {
|
|
736
|
-
return alternative;
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
});
|
|
740
|
-
};
|
|
741
|
-
try {
|
|
742
|
-
const component = (_a = (0, import_vue2.unref)(typeof view === "function" ? view() : view)) != null ? _a : {};
|
|
743
|
-
return resolve("instance" in component ? component.instance : component);
|
|
744
|
-
} catch (e) {
|
|
745
|
-
return resolve(view);
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
function useSubscription() {
|
|
749
|
-
const subscriptions = [];
|
|
750
|
-
const subscription = Subscriptions.get();
|
|
751
|
-
return {
|
|
752
|
-
addSubscription(name, handler = () => false, data) {
|
|
753
|
-
subscription.subscribe(name, handler, data);
|
|
754
|
-
subscriptions.push(() => subscription.unsubscribe(name));
|
|
755
|
-
},
|
|
756
|
-
replaceSubscription(name, handler = () => false, data) {
|
|
757
|
-
subscription.replace(name, handler, data);
|
|
758
|
-
subscriptions.push(() => subscription.unsubscribe(name));
|
|
759
|
-
},
|
|
760
|
-
removeSubscriptions() {
|
|
761
|
-
subscriptions.forEach((subscription2) => safeRequest({
|
|
762
|
-
try: () => subscription2()
|
|
763
|
-
}));
|
|
764
|
-
},
|
|
765
|
-
removeSubscription(name) {
|
|
766
|
-
subscription.unsubscribe(name);
|
|
767
|
-
},
|
|
768
|
-
hasSubscription(name) {
|
|
769
|
-
return subscription.hasSubscription(name);
|
|
770
|
-
},
|
|
771
|
-
subscriptions,
|
|
772
|
-
subscription
|
|
773
|
-
};
|
|
774
|
-
}
|
|
775
|
-
var Prop = ({ default: value, type, validator, required } = {}) => {
|
|
776
|
-
const types1 = Array.isArray(type) ? type : [type != null ? type : Array];
|
|
777
|
-
const types2 = types1.includes(Object) ? types1 : types1.concat(Object);
|
|
778
|
-
return __spreadProps(__spreadValues({}, value ? { default: (0, import_vue2.isRef)(value) || (0, import_vue2.isReactive)(value) ? value : (0, import_vue2.ref)(value) } : {}), {
|
|
779
|
-
required,
|
|
780
|
-
validator: (value2) => {
|
|
781
|
-
try {
|
|
782
|
-
return validator ? validator((0, import_vue2.unref)(value2)) : Array.from(new Set(types2.map((type2) => {
|
|
783
|
-
return typeof type2 === "function" ? type2().constructor.name : type2;
|
|
784
|
-
}))).includes((0, import_vue2.unref)(value2).constructor.name);
|
|
785
|
-
} catch (e) {
|
|
786
|
-
return !required;
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
});
|
|
790
|
-
};
|
|
791
|
-
function StyleParser(styles = {}) {
|
|
792
|
-
const transform = (style, status = true) => {
|
|
793
|
-
const remove = style.split(/(-{[^}]+})/);
|
|
794
|
-
return remove.reduce((object, style2) => {
|
|
795
|
-
var _a;
|
|
796
|
-
const remove2 = /-{(.+?)}/.exec(style2);
|
|
797
|
-
(remove2 ? (_a = remove2[1]) != null ? _a : style2 : style2).split(/\s+/).forEach((item) => {
|
|
798
|
-
if (item) {
|
|
799
|
-
Object.assign(object, { [item]: remove2 ? false : status });
|
|
800
|
-
}
|
|
801
|
-
});
|
|
802
|
-
return object;
|
|
803
|
-
}, {});
|
|
804
|
-
};
|
|
805
|
-
return Array.isArray(styles) ? styles.reduce((styles2, style) => Object.assign(transform(style), styles2), {}) : typeof styles === "string" ? transform(styles) : Object.entries(styles).reduce((acc, [styles2, value]) => {
|
|
806
|
-
return __spreadValues(__spreadValues({}, acc), transform(styles2, value));
|
|
807
|
-
}, {});
|
|
808
|
-
}
|
|
809
|
-
function MergeStyles(...params) {
|
|
810
|
-
return new Proxy(params.reduce((styles, style, index, items) => {
|
|
811
|
-
var _a;
|
|
812
|
-
const item = (_a = items[items.length - index - 1]) != null ? _a : {};
|
|
813
|
-
return __spreadValues(__spreadValues({}, StyleParser(typeof item === "function" ? item(items.slice(0, index - 1)) : item)), styles);
|
|
814
|
-
}, {}), {
|
|
815
|
-
get: (target, key, receiver) => {
|
|
816
|
-
const styles = Object.entries(target).reduce((styles2, [key2, val]) => {
|
|
817
|
-
return val ? styles2.concat(key2) : styles2;
|
|
818
|
-
}, []);
|
|
819
|
-
if (key === "string") {
|
|
820
|
-
return styles.join(" ");
|
|
821
|
-
} else if (key === "array") {
|
|
822
|
-
return styles;
|
|
823
|
-
} else {
|
|
824
|
-
return Reflect.get(target, key, receiver);
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
});
|
|
828
|
-
}
|
|
829
|
-
var extendVnode = (component, element) => {
|
|
830
|
-
return new Proxy(access(component), {
|
|
831
|
-
get: (target, key) => {
|
|
832
|
-
const getVnode = () => {
|
|
833
|
-
try {
|
|
834
|
-
return target[key]();
|
|
835
|
-
} catch (e) {
|
|
836
|
-
throw new Error(`${key} does not exist as vnode on component.`);
|
|
837
|
-
}
|
|
838
|
-
};
|
|
839
|
-
const vnode = getVnode();
|
|
840
|
-
return (props = {}, slots) => {
|
|
841
|
-
var _a;
|
|
842
|
-
const isFunctionClass = typeof props.class === "function";
|
|
843
|
-
const isFunctionStyle = typeof props.style === "function";
|
|
844
|
-
const _b = (_a = vnode.props) != null ? _a : {}, { class: classes, style: styles } = _b, rest = __objRest(_b, ["class", "style"]);
|
|
845
|
-
const finalClasses = (0, import_tailwind_merge.twMerge)(isFunctionClass ? "" : classes, MergeStyles(isFunctionClass ? props.class(classes) : props.class).string);
|
|
846
|
-
const finalStyles = MergeStyles(styles, isFunctionStyle ? props.style(styles) : props.style);
|
|
847
|
-
const functionalProps = Object.entries(props).reduce((props2, [key2, value]) => {
|
|
848
|
-
var _a2;
|
|
849
|
-
if (!["class", "style", "setup"].includes(key2) && typeof value === "function") {
|
|
850
|
-
props2[key2] = value((_a2 = vnode.props) == null ? void 0 : _a2[key2]);
|
|
851
|
-
}
|
|
852
|
-
return props2;
|
|
853
|
-
}, props);
|
|
854
|
-
const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
|
|
855
|
-
const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
|
|
856
|
-
const finalElement = ["undefined"].includes(typeof element) ? vnode.type : element;
|
|
857
|
-
return (0, import_vue2.h)(finalElement, finalProps, finalSlots);
|
|
858
|
-
};
|
|
859
|
-
}
|
|
860
|
-
});
|
|
861
|
-
};
|
|
862
|
-
function defineReactiveView(param1, param2) {
|
|
863
|
-
const instance = (0, import_vue2.ref)();
|
|
864
|
-
return (0, import_vue2.defineComponent)({
|
|
865
|
-
name: param1 == null ? void 0 : param1.modelName,
|
|
866
|
-
props: __spreadValues({ setup }, param1 ? param1.props : {}),
|
|
867
|
-
setup() {
|
|
868
|
-
const _a = param1 != null ? param1 : {}, { setup: setup2, props } = _a, rest = __objRest(_a, ["setup", "props"]);
|
|
869
|
-
return (component) => {
|
|
870
|
-
const props2 = Object.entries(rest).reduce((props3, [key, val]) => {
|
|
871
|
-
return Object.assign(props3, { [key]: typeof val === "function" ? val(component, instance) : val });
|
|
872
|
-
}, {});
|
|
873
|
-
const slots = typeof (param1 == null ? void 0 : param1.slots) === "function" ? param1.slots(component) : Array.isArray(param1 == null ? void 0 : param1.slots) ? () => param1.slots : param1 == null ? void 0 : param1.slots;
|
|
874
|
-
return (0, import_vue2.createVNode)(param2 != null ? param2 : ReactiveView_default, __spreadProps(__spreadValues(__spreadValues({}, props2), Object.assign({}, props2, typeof setup2 === "function" ? {
|
|
875
|
-
setup: (self, parent) => setup2(self, parent, component)
|
|
876
|
-
} : {})), {
|
|
877
|
-
instance
|
|
878
|
-
}), slots);
|
|
879
|
-
};
|
|
880
|
-
}
|
|
881
|
-
});
|
|
882
|
-
}
|
|
883
|
-
function showComponent(component, options = {}) {
|
|
884
|
-
var _a;
|
|
885
|
-
if (options.router) {
|
|
886
|
-
console.warn("[ReactiveView]: Deprecated {router} option used with {showComponent()}. \nUse {plugins} option instead.");
|
|
887
|
-
}
|
|
888
|
-
if (!options.key || !document.getElementById(options.key)) {
|
|
889
|
-
const container = options.container || "app-dialogs";
|
|
890
|
-
const dialogs = document.getElementById(container) || document.createElement("div");
|
|
891
|
-
if (!dialogs.hasAttribute("id")) {
|
|
892
|
-
dialogs.setAttribute("id", container);
|
|
893
|
-
document.body.appendChild(dialogs);
|
|
894
|
-
}
|
|
895
|
-
const dialog = document.createElement("div");
|
|
896
|
-
const id = (_a = options.key) != null ? _a : `dialog_${dialogs.children.length + 1}`;
|
|
897
|
-
dialog.setAttribute("id", id);
|
|
898
|
-
dialogs.appendChild(dialog);
|
|
899
|
-
const app = (0, import_vue2.createApp)(
|
|
900
|
-
{
|
|
901
|
-
setup() {
|
|
902
|
-
return () => component;
|
|
903
|
-
}
|
|
904
|
-
},
|
|
905
|
-
{
|
|
906
|
-
__cleanup__: () => {
|
|
907
|
-
document.querySelectorAll(`#${id}`).forEach((element) => element.remove());
|
|
908
|
-
app.unmount();
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
);
|
|
912
|
-
if (options.router) {
|
|
913
|
-
return app.use(options.router).mount(`#${id}`);
|
|
914
|
-
} else if (options.plugins) {
|
|
915
|
-
return options.plugins.reduce((app2, plugin) => {
|
|
916
|
-
return app2.use(...Array.isArray(plugin) ? plugin : [plugin]);
|
|
917
|
-
}, app).mount(`#${id}`);
|
|
918
|
-
} else {
|
|
919
|
-
return app.mount(`#${id}`);
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
|
-
var getData = (component, path, alternative) => {
|
|
924
|
-
const vue = access(component);
|
|
925
|
-
const data = import_object_manager2.default.on(componentState(vue));
|
|
926
|
-
if (path) {
|
|
927
|
-
return data.get(dataPath(vue, path), alternative);
|
|
928
|
-
} else {
|
|
929
|
-
return data.get();
|
|
930
|
-
}
|
|
931
|
-
};
|
|
932
|
-
var setData = (component, data, path) => {
|
|
933
|
-
const vue = access(component);
|
|
934
|
-
const diff = {
|
|
935
|
-
before: import_object_manager2.default.on(componentState(vue)).clone(),
|
|
936
|
-
after: path ? import_object_manager2.default.on(componentState(vue)).set(dataPath(vue, path), data).get() : import_object_manager2.default.on(componentState(vue)).set(data).get()
|
|
937
|
-
};
|
|
938
|
-
return "state" in vue ? diff : vue.$emit("update:state", diff);
|
|
939
|
-
};
|
|
940
|
-
var componentState = (component) => {
|
|
941
|
-
return (0, import_vue2.unref)("state" in component ? component.state : component.$attrs.state);
|
|
942
|
-
};
|
|
943
|
-
var dataPath = (component, path) => {
|
|
944
|
-
return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
|
|
945
|
-
};
|
|
946
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
947
|
-
0 && (module.exports = {
|
|
948
|
-
MergeStyles,
|
|
949
|
-
Prop,
|
|
950
|
-
StyleParser,
|
|
951
|
-
access,
|
|
952
|
-
dataPath,
|
|
953
|
-
defineReactiveView,
|
|
954
|
-
extendVnode,
|
|
955
|
-
getData,
|
|
956
|
-
getDate,
|
|
957
|
-
getProps,
|
|
958
|
-
getReactiveViewComponent,
|
|
959
|
-
safeRequest,
|
|
960
|
-
setData,
|
|
961
|
-
setup,
|
|
962
|
-
showComponent,
|
|
963
|
-
useSubscription
|
|
964
|
-
});
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`@razaman2/object-manager`);c=s(c);let l=require(`@razaman2/data-manager`);l=s(l);let u=require(`vue`),d=require(`date-fns-tz`),f=require(`tailwind-merge`);var p=class e{subscriptions=[];data={};static create(){return new e}subscribe(e,t,n){return this.isNameAvailable(e)&&(this.subscriptions.push({name:e,handler:t}),this.data[e]=n),this}replace(e,t,n){return this.unsubscribe(e),this.subscribe(e,t,n)}unsubscribe(e){Array.isArray(e)||(e=e?[e]:[]);let t=e=>console.log(`%cUnsubscribed From Subscription (${e})`,`background-color: yellow; color: green; font-weight: bold; padding: 3px;`);return e.length?e.forEach(e=>{let n=this.find(e);n&&(n.handler(),this.remove(n),t(e))}):(this.subscriptions.forEach(e=>{e.handler(),t(e.name)}),this.subscriptions=[]),this}size(){return this.subscriptions.length}hasSubscription(e){return!!this.find(e)}remove(e){this.subscriptions.splice(this.subscriptions.indexOf(e),1)}find(e){return this.subscriptions.find(t=>t.name===e)}isNameAvailable(e){if(this.hasSubscription(e))throw Error(`There is already a subscription called "${e}".`);return!0}registrations(){return this.subscriptions}get(e){let t=this.find(e);if(t)return t;throw Error(`Subscription "${e}" doesn't exist!`)}},m=class e extends p{static subscriptions=e.create();static get(){return this.subscriptions}},h={name:`@razaman2/reactive-view`,version:`0.1.0-beta.17`,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.`,main:`dist/index.js`,module:`dist/index.mjs`,types:`dist/index.d.ts`,exports:{".":{types:`./dist/index.d.ts`,require:`./dist/index.js`,import:`./dist/index.mjs`}},scripts:{prepublishOnly:`npm run build`,build:`vue-tsc -p tsconfig.build.json && vite build`,lint:`eslint "src/**/*.ts" "tests/**/*.ts"`,"lint:fix":`eslint "src/**/*.ts" "tests/**/*.ts" --fix`,format:`prettier --write "src/**/*.ts" "tests/**/*.ts"`,typecheck:`tsc`,test:`vitest run`,"test:watch":`vitest`,pr:`sh pr.sh`},keywords:[`vue`,`vue-helper`,`reactive-view`,`vue-class-component`,`reactive-ui`],repository:{type:`git`,url:`git+https://github.com/razaman2/reactive-view.git`},bugs:{url:`https://github.com/razaman2/reactive-view/issues`},homepage:`https://github.com/razaman2/reactive-view#readme`,author:`razaman2`,license:`MIT`,dependencies:{"@razaman2/data-manager":`^3.3.12`,"@razaman2/event-emitter":`^2.1.1`,"@razaman2/object-manager":`^3.4.7`,"date-fns":`^4.1.0`,"date-fns-tz":`^3.2.0`,"tailwind-merge":`^3.5.0`},peerDependencies:{vue:`>=3.0.0`},devDependencies:{"@eslint/js":`^10.0.1`,"@stylistic/eslint-plugin":`^5.10.0`,"@typescript-eslint/eslint-plugin":`^8.59.2`,"@typescript-eslint/parser":`^8.59.2`,"@vitejs/plugin-vue":`^6.0.6`,"@vitejs/plugin-vue-jsx":`^5.1.5`,"@vue/server-renderer":`^3.5.34`,"@vue/test-utils":`^2.4.10`,eslint:`^10.3.0`,"eslint-config-prettier":`^10.1.8`,"eslint-plugin-prettier":`^5.5.5`,"eslint-plugin-vue":`^10.9.1`,jsdom:`^29.1.1`,prettier:`^3.8.3`,typescript:`^5.9.3`,"typescript-eslint":`^8.59.2`,vite:`^8.0.11`,vitest:`^4.1.5`,"vue-tsc":`^3.2.8`},publishConfig:{access:`public`},files:[`dist`]},g={type:Function,default:(e={},t={})=>t,ReactiveView:!0},_={props:{setup:{},beta:[Boolean,String],ReactiveView:{type:Boolean,default:!0},instance:{default:(0,u.ref)()},notifications:Object,subscriptions:Object,beforeSetData:Function,data:{default:(0,u.reactive)({})},defaultData:{},getDefaultData:{type:Function,default:e=>e},model:{},defer:{},logging:{validator:e=>[`Boolean`].includes(e.constructor.name)},modelName:{type:String,default:`ReactiveView`},debug:{type:Boolean,default:!1},state:{default:(0,u.reactive)({})}},setup(e,t){let n=[];(0,u.onBeforeUnmount)(()=>n.forEach(e=>e()));let r=(e,t)=>{let n=(0,u.ref)(!1),r=Array.from(new Set(e.paths().concat(t.paths()))).reduce((r,i)=>(e.get(i)!==t.get(i)&&(r.set(i,t.get(i)),n.value=!0),r),c.default.on({}));return{before:e.get(),after:t.get(),changes:r.get(),changed:n.value}},i=e=>{let n=t.attrs[`data:path`];return typeof n==`function`?n(e):e},a=(n,r)=>(0,u.createVNode)(`div`,t.slots.default?t.attrs:{style:{color:`red`,textAlign:`center`},...t.attrs},t.slots.default?t.slots.default({component:n,vue:r,props:e,context:t}):`${e.modelName}: ${h.name}@${h.version}`),o=(0,u.ref)(!1),s=(0,u.ref)(!1),d=(0,u.ref)(typeof e.defer==`function`?e.defer():e.defer),f=[`Function`].includes(e.data?.constructor.name),p=[`AsyncFunction`].includes(e.data?.constructor.name),m=[`Promise`].includes(e.data?.constructor.name)||p,g=(0,u.getCurrentInstance)(),_=e.getDefaultData(`defaultData`in g.vnode.props?g.vnode.props.defaultData:`data`in g.vnode.props&&Array.isArray((0,u.unref)(g.vnode.props.data))?[]:{}),v=Array.isArray(_)?[]:{};return e.beta===`current`?(()=>{let h=(e,t)=>{if(g&&g.vnode.el){let n=new CustomEvent(`data:emit`,{bubbles:!0,composed:!0,detail:{before:t,after:e}});g.vnode.el.dispatchEvent(n)}},y={data:e.beta?(t=>{if(e.debug&&console.warn(`[ReactiveView]: using beta props data in [${e.modelName}] component`,{vue:g,data:t,defaultData:_,isRef:(0,u.isRef)(t),isReactive:(0,u.isReactive)(t)}),(0,u.isReactive)(t))return t;if((0,u.isRef)(t)||f||m)return(0,u.reactive)(v);{let e=`data`in g.vnode.props;try{return[`Array`,`Object`].includes(t?.constructor?.name)?(0,u.reactive)(e?t:v):(0,u.reactive)(e?{"":t}:v)}catch{return(0,u.reactive)(e?{"":t}:v)}}})(g.vnode.props?.data):(0,u.reactive)(c.default.on(m||f||(0,u.isRef)(e.data)||(0,u.isReactive)(e.data)?v:`data`in g.vnode.props?e.data:v).clone()),defaultData:c.default.on(_).clone(),notifications:e.notifications,subscriptions:e.subscriptions,name:e.modelName,logging:e.logging},b=new Proxy(e.model?typeof e.model==`function`?e.model(y):e.model:new l.default(y),{get(t,n,r){return[`setData`,`replaceData`].includes(n.toString())?(...r)=>{let i=O(x).beforeSetData??e.beforeSetData;if(typeof i==`function`){let e=c.default.on(t.getData()),a=r.length?c.default.on(v).set(...r):c.default.on(v).set(_);i(O(x).diff(e,a),t)&&t[n](...r)}else t[n](...r);return t}:Reflect.get(t,n,r)}}),x=(0,u.ref)({parent:{self:g.proxy},self:{template:a,model:b,diff:r,emit:h,dataPath:i,isValid:o}});e.debug&&console.warn(`[ReactiveView]:`,{props:e,context:t,vue:g,defer:d,config:y,model:b,component:x,datatype:v,defaultData:_,isValid:o,isReady:s,isFunctionData:f,isAsyncFunctionData:p,isAsyncData:m});let S=e=>{let r=typeof t.attrs[`onUpdate:data`]==`function`?{callback:t.attrs[`onUpdate:data`]}:{callback:(t.attrs[`onUpdate:data`]??{}).callback??t.attrs[`data:callback`],options:Object.assign({deep:t.attrs[`data:deep`]??!0,...t.attrs[`data:immediate`]?{immediate:t.attrs[`data:immediate`]}:{},...t.attrs[`data:once`]?{once:t.attrs[`data:once`]}:{}},(t.attrs[`onUpdate:data`]??{}).options)};t.attrs[`data:log`]&&console.warn(`[ReactiveView]:data`,{config:r,dataProp:e}),n.push((0,u.watch)(f||(0,u.isRef)(e)||(0,u.isReactive)(e)?e:()=>e,(e,t)=>{typeof r.callback==`function`?b.replaceData(r.callback(O(x).diff(c.default.on(t),c.default.on(e)),{component:x})??e):b.replaceData(e)},r.options))};if(t.attrs[`onUpdate:model`]||t.attrs[`update:model`]){let e=typeof t.attrs[`onUpdate:model`]==`function`?{callback:t.attrs[`onUpdate:model`],options:Object.assign({deep:t.attrs[`model:deep`]??!0,...t.attrs[`model:immediate`]?{immediate:t.attrs[`model:immediate`]}:{},...t.attrs[`model:once`]?{once:t.attrs[`model:once`]}:{}},(t.attrs[`onUpdate:model`]??{}).options)}:t.attrs[`onUpdate:model`]??{};t.attrs[`model:log`]&&console.warn(`[ReactiveView]:model`,{config:e}),n.push((0,u.watch)(()=>c.default.on(b.getData()).clone(),(t,n)=>{e.callback(O(x).diff(c.default.on(n),c.default.on(t)),{component:x})},e.options))}if(e.beta){let r=(0,u.isRef)(e.data);(r||f||m)&&setTimeout(async()=>{let[i]=m?await Promise.all([p?e.data():e.data,d.value??!0]):[e.data];n.push((0,u.watch)(r||f||typeof i==`function`?i:()=>i,(e,n)=>{if(n!==void 0||e!==void 0){let r=t.attrs[`data:callback`];if(typeof r==`function`){let t=O(x).diff(c.default.on(n),c.default.on(e));b.replaceData(r(t,{component:x})??e)}else b.replaceData(e)}},{immediate:t.attrs[`data:immediate`]??!0,deep:t.attrs[`data:deep`]??!0,once:t.attrs[`data:once`]}))})}else setTimeout(async()=>{let[t]=await Promise.all([p?e.data():e.data,d.value??!0]);S(t)});return setTimeout(async()=>{s.value=await d.value??!0}),x.value=[O(x)].reduce((e,t)=>{for(;t&&typeof t.setup==`function`&&(e={parent:e,self:t.setup(x,e)??{}},!O(t.$parent).ReactiveView);)t=O(t.$parent);return e},x.value),e.instance.value=typeof e.instance==`function`?e.instance(x.value):x.value,e=>s.value?O(x).template(x,e):t.slots.loading?.({component:x})})():(()=>{let h=(e,t)=>{if(g&&g.vnode.el){let n=new CustomEvent(`emit:data`,{bubbles:!0,composed:!0,detail:{before:t,after:e}});O(C).setData(e),g.vnode.el.dispatchEvent(n),g.vnode.el.dispatchEvent(new CustomEvent(`data:emit`,{bubbles:!0,composed:!0,detail:{before:t,after:e}}))}},y=e=>O(C).model.setData(e),b=t=>new Proxy(t,{get(t,n,r){return[`setData`,`replaceData`].includes(n.toString())?(...r)=>{let i=O(C).beforeSetData??e.beforeSetData;if(typeof i==`function`){let e=c.default.on(t.getData()),a=r.length?c.default.on(v).set(...r):c.default.on(v).set(_);i(O(C).diff(e,a),t)&&t[n](...r)}else t[n](...r);return t}:Reflect.get(t,n,r)}}),x={data:(e=>{if((0,u.isRef)(e)||(0,u.isReactive)(e))return e;if(f||m)return(0,u.ref)(v);{let t=`data`in g.vnode.props;try{return[`Array`,`Object`].includes(e?.constructor?.name)?(0,u.ref)(e):(0,u.ref)(t?{"":e}:v)}catch{return(0,u.ref)(t?{"":e}:v)}}})(g.vnode.props?.data),defaultData:c.default.on(_).clone(),notifications:e.notifications,subscriptions:e.subscriptions,name:e.modelName,logging:e.logging},S=e.model?typeof e.model==`function`?e.model(x):e.model:l.default.setConfig({beforeGetData:e=>(0,u.isRef)(e)?(0,u.unref)(e):e},x),C=(0,u.ref)({parent:{self:g.proxy},self:{template:a,diff:r,emit:h,setData:y,dataPath:i,model:b(S),isValid:o}});if(t.attrs[`onUpdate:model`]||t.attrs[`update:model`]){let r={callback:typeof t.attrs[`onUpdate:model`]==`function`?t.attrs[`onUpdate:model`]:t.attrs[`update:model`],options:{immediate:t.attrs[`model:immediate`],deep:t.attrs[`model:deep`],once:t.attrs[`model:once`]}};n.push((0,u.watch)(()=>c.default.on(S.getData()).clone(),(t,n)=>{let i=O(C).diff(c.default.on(n),c.default.on(t));e.debug&&console.warn(`[${e.modelName}]:model`,{diff:i,before:n,after:t}),i.changed&&r.callback(i,{component:C})},r.options))}return(0,u.nextTick)(async()=>{if(e.model!==!1){(f||m)&&!(`defaultData`in g.vnode.props)&&console.warn(`${e.modelName}: defaultData is required for promise or function data.`,e.data);let[r]=m?await Promise.all([p?e.data():e.data,d.value??!0]):[e.data],i=(0,u.isRef)(r)||(0,u.isReactive)(r),a=typeof r==`function`||i?r:()=>r;n.push((0,u.watch)(a,async(n,i)=>{let a=O(C).diff(c.default.on(i),c.default.on(n)),o=t.attrs[`data:callback`];e.debug&&console.warn(`[${e.modelName}]:data`,{diff:a,data:r,callback:o,props:e,context:t,component:C}),typeof o==`function`?o(a,{component:C}):S.replaceData(n)},{immediate:t.attrs[`data:immediate`]??!i,deep:t.attrs[`data:deep`],once:t.attrs[`data:once`]}))}}),(0,u.nextTick)(async()=>{s.value=await d.value??!0}),C.value=[O(C)].reduce((e,t)=>{for(;t&&typeof t.setup==`function`&&(e={parent:e,self:t.setup(C,e)??{}},!O(t.$parent).ReactiveView);)t=O(t.$parent);return e},C.value),e.instance.value=typeof e.instance==`function`?e.instance(C.value):C.value,e=>s.value?O(C).template(C,e):t.slots.loading?.({component:C})})()}};function v(e,t={}){let n=e=>{let n=t.id??`dialog_${e.children.length+1}`,r=document.createElement(`div`);return r.setAttribute(`id`,n),e.appendChild(r),r},r=e=>{let t=document.getElementById(e);if(t)return n(t);{let t=document.createElement(`div`);return t.setAttribute(`id`,e),document.body.appendChild(t),n(t)}},i=t.container||`app-dialogs`,a=r(i),o=(0,u.createVNode)({setup:()=>()=>e},{container:i,unmount:()=>{(0,u.render)(null,a),a.remove()}}),s=t.app??document.querySelector(`[data-v-app]`);try{o.appContext=s.__vue_app__._context,(0,u.render)(o,a)}catch{console.warn(`[ReactiveView]: showComponent called without an active app context.`)}}var y=P({modelName:`CustomButton`,props:{label:[Number,String],tag:{type:String,default:`button`},loading:{type:[Boolean,Function],default:!1},padding:{type:Boolean,default:!0},buttonClass:{},loadingClass:{}},setup(e,t,n){let r=typeof n.loading==`function`?n.loading:()=>n.loading,i=(0,u.ref)(!1);return(0,u.watchEffect)(()=>{i.value=r()}),{template:()=>(0,u.createVNode)(n.tag,{class:(0,f.twMerge)(M({"px-0 h-min":!n.padding,"btn uppercase rounded-lg text-sm font-normal leading-none":!0}).string,M(n.buttonClass).string)},{default:()=>[O(e).buttonLoading(),(0,u.createVNode)(`div`,{class:{hidden:i.value,contents:!0}},[O(e).buttonIcon(),n.$slots.default?n.$slots.default({component:e}):n.label])]}),buttonIcon:()=>{if(n.$slots.icon)return n.$slots.icon({component:e})},buttonLoading:()=>{if(i.value)return n.$slots.loading?n.$slots.loading({component:e}):(0,u.createVNode)(`span`,{class:M(`loading`,n.loadingClass)},null)}}}}),b=P({modelName:`CustomModal`,props:{title:{type:[Boolean,Number,String],default:`Modal Title`},persistent:{type:Boolean,default:!1},header:{type:Boolean,default:!0},actions:{type:Boolean,default:!0},ok:{type:Boolean,default:!0},cancel:{type:Boolean,default:!1},close:{type:Boolean,default:!0},show:{type:Boolean,default:!0},whenOk:{type:Function,default:()=>{}},whenCancel:{type:Function,default:()=>{}},whenClose:{type:Function,default:()=>{}},whenEscape:{type:Function,default:()=>{}},whenDismiss:{type:Function,default:()=>{}},whenRouteChange:{type:Function,default:()=>{}},class:{},headerClass:{},titleClass:{},actionsClass:{},backdropClass:{},timeout:{default:!1,validator:e=>typeof e==`number`||e===!1},modal:{type:Boolean,default:!1},id:[Number,String]},setup:(e,t,n)=>{(0,u.provide)(`dialog`,e);let r=(0,u.ref)(),i=(0,u.ref)(),a=document.getElementById(n.$attrs.container??`app-dialogs`),o=(0,u.computed)(()=>O(e).trigger??n.$slots.trigger),s=(0,u.computed)(()=>o.value?!1:n.show),c=(0,u.computed)(()=>!0),l=e=>{throw Error(e)},d=()=>(0,u.createVNode)(`div`,null,[(0,u.createVNode)(`dialog`,(0,u.mergeProps)({class:`modal`,ref:r},o.value||O(e).watch?{}:a?{id:a.lastChild?.id}:l(`Modal should be called with showComponent.ts | trigger element | trigger slot`)),[O(e).modalBox(),O(e).modalBackdrop()]),o.value?.({component:e})]),p=()=>(0,u.createVNode)(`div`,{class:(0,f.twMerge)(M(`modal-box flex flex-col p-0`,n.class).string,M(n.class).string)},[O(e).modalHeader(),O(e).modalContent(),O(e).modalActions()]),m=()=>n.$slots.default?n.$slots.default({component:e}):(0,u.createVNode)(`div`,{class:`px-4`},[(0,u.createTextVNode)(`No Content`)]),h=()=>(0,u.createVNode)(`div`,{class:(0,f.twMerge)(`modal-backdrop`,M({"pointer-events-none":n.persistent}).string,M(n.backdropClass).string),onClick:()=>O(e).hide(`backdrop`)},null),g=()=>{if(n.actions)return(0,u.createVNode)(`div`,{style:`margin: 0;`,class:(0,f.twMerge)(`modal-action px-4 pb-4`,M(n.actionsClass).string)},[O(e).okButton(),O(e).cancelButton()])},_=()=>{if(n.header)return(0,u.createVNode)(`div`,{class:(0,f.twMerge)(`flex items-center justify-between px-4 pt-4`,M(n.headerClass).string)},[O(e).title(),O(e).closeButton()])},v=()=>{if(n.close)return(0,u.createVNode)((0,u.resolveComponent)(`i-mdi-close`),{class:`cursor-pointer rounded-full text-xl transition duration-500 hover:scale-80 hover:ring`,onClick:async()=>{await n.whenClose(),O(e).hide(`close`)}},null)},b=()=>{if(n.ok)return(0,u.createVNode)(y,{label:`ok`,class:`btn-sm btn-success text-white`,onClick:()=>O(e).triggerOk(),disabled:!O(e).isValid},null)},x=()=>{if(n.cancel)return(0,u.createVNode)(y,{label:`cancel`,class:`btn-sm btn-error text-white`,onClick:async()=>{await n.whenCancel(),O(e).hide(`cancel`)}},null)},S=()=>{if([`String`,`Number`].includes(n.title.constructor.name))return(0,u.createVNode)(`h3`,{class:(0,f.twMerge)(`w-full text-center font-bold`,M(n.titleClass).string)},[n.title])},C=()=>r.value[n.modal?`showModal`:`show`](),w=e=>r.value.close(e),T=()=>r.value.open,E=e=>{n.$attrs.unmount?.(e),clearTimeout(i.value)};return setTimeout(()=>{let t=`open`;r.value&&(new MutationObserver(async()=>{if(O(e).showing())try{await(await import(`@razaman2/event-emitter`)).default.global().emit(`dialog:${t}`,{type:t,component:e,id:n.id})}finally{}}).observe(r.value,{attributes:!0,attributeFilter:[t]}),r.value.addEventListener(`close`,async t=>{let r=t.target.returnValue||`escape`;try{await(await import(`@razaman2/event-emitter`)).default.global().emit(`dialog:close`,{e:t,type:r,component:e,id:n.id})}finally{await n.whenDismiss({type:r}),E({type:r})}}),typeof n.timeout==`number`&&(i.value=setTimeout(()=>O(e).hide(`timeout`),n.timeout)),O(e).watch?(0,u.watch)(O(e).watch,t=>{r.value&&t?O(e).show():r.value&&O(e).hide()},{deep:!0}):s.value&&O(e).show()),document.addEventListener(`keydown`,async e=>{let t=e.key===`Escape`;n.persistent&&t?(e.stopPropagation(),e.preventDefault()):t&&await n.whenEscape()})}),{template:d,title:S,modalBox:p,modalHeader:_,modalContent:m,modalActions:g,modalBackdrop:h,closeButton:v,okButton:b,cancelButton:x,show:C,hide:w,showing:T,triggerOk:async()=>{await n.whenOk(O(e).model.getData()),O(e).hide(`ok`)},isValid:c,modalRef:r}}}),x={props:{setup:g,title:{type:String},description:{type:String},close:{type:Boolean,default:!0},timeout:{default:3e3,validator:e=>typeof e==`number`||e===!1}},setup(e,t){return e=>(0,u.createVNode)(C,{modelName:`CustomAlert`,setup:n=>{let r={default:(0,u.createVNode)(`path`,{"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z`},null),"alert-info":(0,u.createVNode)(`path`,{"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z`},null),"alert-success":(0,u.createVNode)(`path`,{"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z`},null),"alert-warning":(0,u.createVNode)(`path`,{"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z`},null),"alert-error":(0,u.createVNode)(`path`,{"stroke-linecap":`round`,"stroke-linejoin":`round`,"stroke-width":`2`,d:`M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z`},null)},i=/alert-(info|success|warning|error)/.exec(e.$attrs.class)?.shift();return e.timeout&&(0,u.onMounted)(()=>{setTimeout(()=>O(n).hide(`timeout`),e.timeout)}),{template:()=>(0,u.createVNode)(`div`,{role:`alert`,class:`alert`},[O(n).alertIcon(),(0,u.createVNode)(`div`,null,[O(n).alertTitle(),e.$slots.default?e.$slots.default({component:n}):O(n).alertDescription()]),O(n).alertClose()]),alertIcon:()=>(0,u.createVNode)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,class:{[i?`stroke-current`:`stroke-black`]:!0,"h-6 w-6 shrink-0":!0},fill:`none`,viewBox:`0 0 24 24`},[r[i]||r.default]),alertTitle:()=>(0,u.createVNode)(`h3`,{class:`font-bold`},[e.title]),alertDescription:()=>(0,u.createVNode)(`div`,{class:`text-xs`},[e.description]),alertClose:()=>{if(e.close)return(0,u.createVNode)((0,u.resolveComponent)(`i-mdi-close`),{id:`alert-close`,class:`text-xl cursor-pointer rounded-full hover:scale-80 hover:ring transition duration-500`,onClick:()=>O(n).hide(`close`)},null)},hide:n=>{e.$el.remove(),t.emit(`close`,n)}}}},e.$slots)}},S=c.default.default||c.default;console.log(`%c[ReactiveView]: ${h.version}`,`background-color: red; color: yellow;`);var C=_;async function w(e){let{message:t}=e.loading??{};e.loading&&(e.loading.status=!0,e.message&&(e.loading.message=e.message));try{return await e.try()}catch(t){if(e.alternative??!0)return e.catch?await e.catch(t):console.log(t)}finally{await e.finally?.(),e.loading&&(e.loading.status=!1),e.loading&&t&&(e.loading.message=t),await e.complete?.()}}function T(e={},t){let n=Array.isArray(t)||typeof t==`string`?t:t.exclude,r=(Array.isArray(n)?n:[n]).join(`|`),i=t.include??{};return Object.entries(i).reduce((e,[t,n])=>(e[t]=n,e),Object.entries(e).reduce((e,[t,n])=>(RegExp(`(^|\\|)${t}($|\\|)`,`i`).test(r)||(e[t]=n),e),{}))}function E(e,t={}){let n=e=>{try{let t=(e.type||e).props;return t&&Object.prototype.hasOwnProperty.call(t,`model`)}catch{return!1}},r=T(t,`setup`),i=typeof e==`function`?e:()=>(e.type||e).setup?(0,u.createVNode)(e,e.setup?{}:r):e;return n(e)?(0,u.createVNode)(e,r):(0,u.createVNode)(_,r,i)}function D(e,t){let n=Intl.DateTimeFormat().resolvedOptions().timeZone,r=typeof t==`string`?{format:t,timezone:n}:{format:t?.format??`MM/dd/yyyy h:mm a`,timezone:t?.timezone??n};return(0,d.formatInTimeZone)((()=>{try{return e instanceof Date?e:e.toDate()}catch{return new Date}})(),r.timezone,r.format)}function O(e={},t){let n=e=>new Proxy((0,u.toRaw)(e),{get(e,n){let r={tree:e};do if(n in r.tree)return r.tree[n];else if(`self`in r.tree&&n in r.tree.self)return r.tree.self[n];else r.tree=`parent`in r.tree&&r.tree.parent;while(r.tree);try{return new t}catch{return t}}});try{let t=(0,u.unref)(typeof e==`function`?e():e)??{};return n(`instance`in t?t.instance:t)}catch{return n(e)}}function k(){let e=[],t=m.get();return{addSubscription(n,r,i){t.subscribe(n,r,i),e.push(()=>t.unsubscribe(n))},replaceSubscription(n,r,i){t.replace(n,r,i),e.push(()=>t.unsubscribe(n))},removeSubscriptions(){e.forEach(e=>w({try:()=>e()}))},removeSubscription(e){t.unsubscribe(e)},hasSubscription(e){return t.hasSubscription(e)},subscriptions:e,subscription:t}}var A=({default:e,type:t,validator:n,required:r}={})=>{let i=Array.isArray(t)?t:[t??Array],a=i.includes(Object)?i:i.concat(Object);return{...e?{default:(0,u.isRef)(e)||(0,u.isReactive)(e)?e:(0,u.ref)(e)}:{},required:r,validator:e=>{try{return n?n((0,u.unref)(e)):Array.from(new Set(a.map(e=>typeof e==`function`?e().constructor.name:e))).includes((0,u.unref)(e).constructor.name)}catch{return!r}}}};function j(e={}){let t=(e,t=!0)=>e.split(/(-{[^}]+})/).reduce((e,n)=>{let r=/-{(.+?)}/.exec(n);return(r?r[1]??n:n).split(/\s+/).forEach(n=>{n&&Object.assign(e,{[n]:r?!1:t})}),e},{});return Array.isArray(e)?e.reduce((e,n)=>Object.assign(t(n),e),{}):typeof e==`string`?t(e):Object.entries(e).reduce((e,[n,r])=>({...e,...t(n,r)}),{})}function M(...e){return new Proxy(e.reduce((e,t,n,r)=>{let i=r[r.length-n-1]??{};return{...j(typeof i==`function`?i(r.slice(0,n-1)):i),...e}},{}),{get:(e,t,n)=>{let r=Object.entries(e).reduce((e,[t,n])=>n?e.concat(t):e,[]);return t===`string`?r.join(` `):t===`array`?r:Reflect.get(e,t,n)}})}var N=(e,t)=>new Proxy(O(e),{get:(e,n)=>{let r=(()=>{try{return e[n]()}catch{throw Error(`${n} does not exist as vnode on component.`)}})();return(e={},n)=>{let i=typeof e.class==`function`,a=typeof e.style==`function`,{class:o,style:s,...c}=r.props??{},l=(0,f.twMerge)(i?``:o,M(i?e.class(o):e.class).string),d=M(s,a?e.style(s):e.style),p=Object.entries(e).reduce((e,[t,n])=>(![`class`,`style`,`setup`].includes(t)&&typeof n==`function`&&(e[t]=n(r.props?.[t])),e),e),m=Object.assign(c,p,{class:l,style:d}),h=n?typeof n==`function`?n(r.children):n:r.children;return(0,u.h)([`undefined`].includes(typeof t)?r.type:t,m,h)}}});function P(e,t){let n=(0,u.ref)();return(0,u.defineComponent)({name:e?.modelName,props:{setup:g,...e?e.props:{}},setup(){let{setup:r,props:i,...a}=e??{};return i=>{let o=Object.entries(a).reduce((e,[t,r])=>Object.assign(e,{[t]:typeof r==`function`?r(i,n):r}),{}),s=typeof e?.slots==`function`?e.slots(i):Array.isArray(e?.slots)?()=>e.slots:e?.slots;return(0,u.createVNode)(t??_,{...o,...Object.assign({},o,typeof r==`function`?{setup:(e,t)=>r(e,t,i)}:{}),instance:n},s)}}})}var F=(e,t,n)=>{let r=O(e),i=S.on(L(r));return t?i.get(R(r,t),n):i.get()},I=(e,t,n)=>{let r=O(e),i={before:S.on(L(r)).clone(),after:n?S.on(L(r)).set(R(r,n),t).get():S.on(L(r)).set(t).get()};return`state`in r?i:r.$emit(`update:state`,i)},L=e=>(0,u.unref)(`state`in e?e.state:e.$attrs.state),R=(e,t)=>typeof e.$attrs[`data:path`]==`function`?e.$attrs[`data:path`](t):t;exports.CustomAlert=x,exports.CustomButton=y,exports.CustomModal=b,exports.MergeStyles=M,exports.Prop=A,exports.StyleParser=j,exports.access=O,exports.dataPath=R,exports.default=C,exports.defineReactiveView=P,exports.extendVnode=N,exports.getData=F,exports.getDate=D,exports.getProps=T,exports.getReactiveViewComponent=E,exports.safeRequest=w,exports.setData=I,exports.setup=g,exports.showComponent=v,exports.useSubscription=k;
|