@razaman2/reactive-view 0.1.0-beta.16 → 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/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 -930
- package/dist/index.mjs +931 -869
- package/dist/showComponent.d.ts +5 -0
- package/package.json +25 -8
- package/dist/index.d.mts +0 -148
package/dist/index.js
CHANGED
|
@@ -1,930 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
MergeStyles: () => MergeStyles,
|
|
34
|
-
Prop: () => Prop,
|
|
35
|
-
StyleParser: () => StyleParser,
|
|
36
|
-
access: () => access,
|
|
37
|
-
dataPath: () => dataPath,
|
|
38
|
-
default: () => index_default,
|
|
39
|
-
defineReactiveView: () => defineReactiveView,
|
|
40
|
-
extendVnode: () => extendVnode,
|
|
41
|
-
getData: () => getData,
|
|
42
|
-
getDate: () => getDate,
|
|
43
|
-
getProps: () => getProps,
|
|
44
|
-
getReactiveViewComponent: () => getReactiveViewComponent,
|
|
45
|
-
safeRequest: () => safeRequest,
|
|
46
|
-
setData: () => setData,
|
|
47
|
-
setup: () => setup,
|
|
48
|
-
showComponent: () => showComponent,
|
|
49
|
-
useSubscription: () => useSubscription
|
|
50
|
-
});
|
|
51
|
-
module.exports = __toCommonJS(index_exports);
|
|
52
|
-
var import_object_manager2 = __toESM(require("@razaman2/object-manager"));
|
|
53
|
-
|
|
54
|
-
// src/Subscription.ts
|
|
55
|
-
var Subscription = class _Subscription {
|
|
56
|
-
subscriptions = [];
|
|
57
|
-
data = {};
|
|
58
|
-
static create() {
|
|
59
|
-
return new _Subscription();
|
|
60
|
-
}
|
|
61
|
-
subscribe(name, handler, data) {
|
|
62
|
-
if (this.isNameAvailable(name)) {
|
|
63
|
-
this.subscriptions.push({
|
|
64
|
-
name,
|
|
65
|
-
handler
|
|
66
|
-
});
|
|
67
|
-
this.data[name] = data;
|
|
68
|
-
}
|
|
69
|
-
return this;
|
|
70
|
-
}
|
|
71
|
-
replace(name, handler, data) {
|
|
72
|
-
this.unsubscribe(name);
|
|
73
|
-
return this.subscribe(name, handler, data);
|
|
74
|
-
}
|
|
75
|
-
unsubscribe(param1) {
|
|
76
|
-
if (!Array.isArray(param1)) {
|
|
77
|
-
param1 = param1 ? [param1] : [];
|
|
78
|
-
}
|
|
79
|
-
const log = (name) => {
|
|
80
|
-
return console.log(`%cUnsubscribed From Subscription (${name})`, "background-color: yellow; color: green; font-weight: bold; padding: 3px;");
|
|
81
|
-
};
|
|
82
|
-
if (param1.length) {
|
|
83
|
-
param1.forEach((name) => {
|
|
84
|
-
const subscription = this.find(name);
|
|
85
|
-
if (subscription) {
|
|
86
|
-
subscription.handler();
|
|
87
|
-
this.remove(subscription);
|
|
88
|
-
log(name);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
} else {
|
|
92
|
-
this.subscriptions.forEach((subscription) => {
|
|
93
|
-
subscription.handler();
|
|
94
|
-
log(subscription.name);
|
|
95
|
-
});
|
|
96
|
-
this.subscriptions = [];
|
|
97
|
-
}
|
|
98
|
-
return this;
|
|
99
|
-
}
|
|
100
|
-
size() {
|
|
101
|
-
return this.subscriptions.length;
|
|
102
|
-
}
|
|
103
|
-
hasSubscription(name) {
|
|
104
|
-
return Boolean(this.find(name));
|
|
105
|
-
}
|
|
106
|
-
remove(subscription) {
|
|
107
|
-
this.subscriptions.splice(this.subscriptions.indexOf(subscription), 1);
|
|
108
|
-
}
|
|
109
|
-
find(name) {
|
|
110
|
-
return this.subscriptions.find((subscription) => {
|
|
111
|
-
return subscription.name === name;
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
isNameAvailable(name) {
|
|
115
|
-
if (this.hasSubscription(name)) {
|
|
116
|
-
throw new Error(`There is already a subscription called "${name}".`);
|
|
117
|
-
} else {
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
registrations() {
|
|
122
|
-
return this.subscriptions;
|
|
123
|
-
}
|
|
124
|
-
get(name) {
|
|
125
|
-
const subscription = this.find(name);
|
|
126
|
-
if (subscription) {
|
|
127
|
-
return subscription;
|
|
128
|
-
} else {
|
|
129
|
-
throw new Error(`Subscription "${name}" doesn't exist!`);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
// src/Subscriptions.ts
|
|
135
|
-
var Subscriptions = class _Subscriptions extends Subscription {
|
|
136
|
-
static subscriptions = _Subscriptions.create();
|
|
137
|
-
static get() {
|
|
138
|
-
return this.subscriptions;
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
// src/ReactiveView.ts
|
|
143
|
-
var import_object_manager = __toESM(require("@razaman2/object-manager"));
|
|
144
|
-
var import_data_manager = __toESM(require("@razaman2/data-manager"));
|
|
145
|
-
var import_vue = require("vue");
|
|
146
|
-
|
|
147
|
-
// package.json
|
|
148
|
-
var package_default = {
|
|
149
|
-
name: "@razaman2/reactive-view",
|
|
150
|
-
version: "0.1.0-beta.16",
|
|
151
|
-
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.",
|
|
152
|
-
main: "dist/index.js",
|
|
153
|
-
module: "dist/index.mjs",
|
|
154
|
-
types: "dist/index.d.ts",
|
|
155
|
-
exports: {
|
|
156
|
-
".": {
|
|
157
|
-
types: "./dist/index.d.ts",
|
|
158
|
-
require: "./dist/index.js",
|
|
159
|
-
import: "./dist/index.mjs"
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
scripts: {
|
|
163
|
-
prepublishOnly: "npm run build",
|
|
164
|
-
build: "tsup src/index.ts --format cjs,esm --dts",
|
|
165
|
-
lint: "tsc",
|
|
166
|
-
test: "vitest run",
|
|
167
|
-
"test:watch": "vitest",
|
|
168
|
-
pr: "sh pr.sh"
|
|
169
|
-
},
|
|
170
|
-
keywords: [
|
|
171
|
-
"vue",
|
|
172
|
-
"vue-helper",
|
|
173
|
-
"reactive-view",
|
|
174
|
-
"vue-class-component",
|
|
175
|
-
"reactive-ui"
|
|
176
|
-
],
|
|
177
|
-
repository: {
|
|
178
|
-
type: "git",
|
|
179
|
-
url: "git+https://github.com/razaman2/reactive-view.git"
|
|
180
|
-
},
|
|
181
|
-
bugs: {
|
|
182
|
-
url: "https://github.com/razaman2/reactive-view/issues"
|
|
183
|
-
},
|
|
184
|
-
homepage: "https://github.com/razaman2/reactive-view#readme",
|
|
185
|
-
author: "razaman2",
|
|
186
|
-
license: "MIT",
|
|
187
|
-
dependencies: {
|
|
188
|
-
"@razaman2/data-manager": "^3.3.12",
|
|
189
|
-
"@razaman2/event-emitter": "^2.1.1",
|
|
190
|
-
"@razaman2/object-manager": "^3.4.7",
|
|
191
|
-
"date-fns": "^4.1.0",
|
|
192
|
-
"date-fns-tz": "^3.2.0",
|
|
193
|
-
"tailwind-merge": "^3.5.0",
|
|
194
|
-
uuid: "^13.0.0"
|
|
195
|
-
},
|
|
196
|
-
peerDependencies: {
|
|
197
|
-
vue: ">=3.0.0"
|
|
198
|
-
},
|
|
199
|
-
devDependencies: {
|
|
200
|
-
"@types/uuid": "^11.0.0",
|
|
201
|
-
tsup: "^8.5.1",
|
|
202
|
-
typescript: "^5.9.3",
|
|
203
|
-
vitest: "^4.1.2"
|
|
204
|
-
},
|
|
205
|
-
publishConfig: {
|
|
206
|
-
access: "public"
|
|
207
|
-
},
|
|
208
|
-
files: [
|
|
209
|
-
"dist"
|
|
210
|
-
]
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
// src/ReactiveView.ts
|
|
214
|
-
var setup = {
|
|
215
|
-
type: Function,
|
|
216
|
-
default: (parent = {}, self = {}) => self,
|
|
217
|
-
ReactiveView: true
|
|
218
|
-
};
|
|
219
|
-
var ReactiveView_default = {
|
|
220
|
-
props: {
|
|
221
|
-
setup: {},
|
|
222
|
-
beta: [Boolean, String],
|
|
223
|
-
ReactiveView: {
|
|
224
|
-
type: Boolean,
|
|
225
|
-
default: true
|
|
226
|
-
},
|
|
227
|
-
instance: { default: (0, import_vue.ref)() },
|
|
228
|
-
notifications: Object,
|
|
229
|
-
subscriptions: Object,
|
|
230
|
-
beforeSetData: Function,
|
|
231
|
-
data: { default: (0, import_vue.reactive)({}) },
|
|
232
|
-
defaultData: {},
|
|
233
|
-
getDefaultData: {
|
|
234
|
-
type: Function,
|
|
235
|
-
default: (data) => data
|
|
236
|
-
},
|
|
237
|
-
model: {},
|
|
238
|
-
defer: {},
|
|
239
|
-
logging: {
|
|
240
|
-
validator: (logging) => {
|
|
241
|
-
return ["Boolean"].includes(logging.constructor.name);
|
|
242
|
-
}
|
|
243
|
-
},
|
|
244
|
-
modelName: {
|
|
245
|
-
type: String,
|
|
246
|
-
default: "ReactiveView"
|
|
247
|
-
},
|
|
248
|
-
debug: {
|
|
249
|
-
type: Boolean,
|
|
250
|
-
default: false
|
|
251
|
-
},
|
|
252
|
-
state: { default: (0, import_vue.reactive)({}) }
|
|
253
|
-
},
|
|
254
|
-
setup(props, context) {
|
|
255
|
-
const subscriptions = [];
|
|
256
|
-
(0, import_vue.onBeforeUnmount)(() => subscriptions.forEach((subscription) => subscription()));
|
|
257
|
-
const diff = (before, after) => {
|
|
258
|
-
const changed = (0, import_vue.ref)(false);
|
|
259
|
-
const paths = Array.from(new Set(before.paths().concat(after.paths())));
|
|
260
|
-
const changes = paths.reduce((changes2, path) => {
|
|
261
|
-
if (before.get(path) !== after.get(path)) {
|
|
262
|
-
changes2.set(path, after.get(path));
|
|
263
|
-
changed.value = true;
|
|
264
|
-
}
|
|
265
|
-
return changes2;
|
|
266
|
-
}, import_object_manager.default.on({}));
|
|
267
|
-
return { before: before.get(), after: after.get(), changes: changes.get(), changed: changed.value };
|
|
268
|
-
};
|
|
269
|
-
const dataPath2 = (path) => {
|
|
270
|
-
const handler = context.attrs["data:path"];
|
|
271
|
-
return typeof handler === "function" ? handler(path) : path;
|
|
272
|
-
};
|
|
273
|
-
const template = (component, vue2) => {
|
|
274
|
-
return (0, import_vue.createVNode)("div", context.slots.default ? context.attrs : {
|
|
275
|
-
style: { color: "red", textAlign: "center" },
|
|
276
|
-
...context.attrs
|
|
277
|
-
}, context.slots.default ? context.slots.default({ component, vue: vue2, props, context }) : `${props.modelName}: ${package_default.name}@${package_default.version}`);
|
|
278
|
-
};
|
|
279
|
-
const isValid = (0, import_vue.ref)(false);
|
|
280
|
-
const isReady = (0, import_vue.ref)(false);
|
|
281
|
-
const defer = (0, import_vue.ref)(typeof props.defer === "function" ? props.defer() : props.defer);
|
|
282
|
-
const isFunctionData = ["Function"].includes(props.data?.constructor.name);
|
|
283
|
-
const isAsyncFunctionData = ["AsyncFunction"].includes(props.data?.constructor.name);
|
|
284
|
-
const isAsyncData = ["Promise"].includes(props.data?.constructor.name) || isAsyncFunctionData;
|
|
285
|
-
const vue = (0, import_vue.getCurrentInstance)();
|
|
286
|
-
const defaultData = props.getDefaultData(
|
|
287
|
-
"defaultData" in vue.vnode.props ? vue.vnode.props.defaultData : "data" in vue.vnode.props ? Array.isArray((0, import_vue.unref)(vue.vnode.props.data)) ? [] : {} : {}
|
|
288
|
-
);
|
|
289
|
-
const datatype = Array.isArray(defaultData) ? [] : {};
|
|
290
|
-
const beta = () => {
|
|
291
|
-
const emit = (after, before) => {
|
|
292
|
-
if (vue && vue.vnode.el) {
|
|
293
|
-
const event = new CustomEvent("data:emit", {
|
|
294
|
-
bubbles: true,
|
|
295
|
-
// Key: allows it to travel up
|
|
296
|
-
composed: true,
|
|
297
|
-
// Key: allows it to cross Shadow DOM boundaries
|
|
298
|
-
detail: { before, after }
|
|
299
|
-
// Payload goes here
|
|
300
|
-
});
|
|
301
|
-
access(component).model.setData(after);
|
|
302
|
-
vue.vnode.el.dispatchEvent(event);
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
const proxy = (data) => {
|
|
306
|
-
return new Proxy(data, {
|
|
307
|
-
get(target, key, receiver) {
|
|
308
|
-
if (["setData", "replaceData"].includes(key.toString())) {
|
|
309
|
-
return (...params) => {
|
|
310
|
-
const beforeSetData = access(component).beforeSetData ?? props.beforeSetData;
|
|
311
|
-
if (typeof beforeSetData === "function") {
|
|
312
|
-
const before = import_object_manager.default.on(target.getData());
|
|
313
|
-
const after = params.length ? import_object_manager.default.on(datatype).set(...params) : import_object_manager.default.on(datatype).set(defaultData);
|
|
314
|
-
const diff2 = access(component).diff(before, after);
|
|
315
|
-
if (beforeSetData(diff2, target)) {
|
|
316
|
-
target[key](...params);
|
|
317
|
-
}
|
|
318
|
-
} else {
|
|
319
|
-
target[key](...params);
|
|
320
|
-
}
|
|
321
|
-
return target;
|
|
322
|
-
};
|
|
323
|
-
} else {
|
|
324
|
-
return Reflect.get(target, key, receiver);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
};
|
|
329
|
-
const normalize = (data) => {
|
|
330
|
-
if ((0, import_vue.isRef)(data) || (0, import_vue.isReactive)(data)) {
|
|
331
|
-
return data;
|
|
332
|
-
} else if (isFunctionData || isAsyncData) {
|
|
333
|
-
return (0, import_vue.ref)(datatype);
|
|
334
|
-
} else {
|
|
335
|
-
const props2 = "data" in vue.vnode.props;
|
|
336
|
-
try {
|
|
337
|
-
if (["Array", "Object"].includes(data?.constructor?.name)) {
|
|
338
|
-
return (0, import_vue.ref)(data);
|
|
339
|
-
} else {
|
|
340
|
-
return (0, import_vue.ref)(props2 ? { "": data } : datatype);
|
|
341
|
-
}
|
|
342
|
-
} catch {
|
|
343
|
-
return (0, import_vue.ref)(props2 ? { "": data } : datatype);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
};
|
|
347
|
-
const config = {
|
|
348
|
-
data: normalize(vue.vnode.props?.data),
|
|
349
|
-
defaultData: import_object_manager.default.on(defaultData).clone(),
|
|
350
|
-
notifications: props.notifications,
|
|
351
|
-
subscriptions: props.subscriptions,
|
|
352
|
-
name: props.modelName,
|
|
353
|
-
logging: props.logging
|
|
354
|
-
};
|
|
355
|
-
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);
|
|
356
|
-
const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, diff, emit, dataPath: dataPath2, model: proxy(model), isValid } });
|
|
357
|
-
if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
|
|
358
|
-
const config2 = {
|
|
359
|
-
callback: typeof context.attrs["onUpdate:model"] === "function" ? context.attrs["onUpdate:model"] : context.attrs["update:model"],
|
|
360
|
-
options: {
|
|
361
|
-
immediate: context.attrs["model:immediate"],
|
|
362
|
-
deep: context.attrs["model:deep"],
|
|
363
|
-
once: context.attrs["model:once"]
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
const source = () => import_object_manager.default.on(model.getData()).clone();
|
|
367
|
-
subscriptions.push((0, import_vue.watch)(source, (after, before) => {
|
|
368
|
-
const diff2 = access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after));
|
|
369
|
-
if (props.debug) {
|
|
370
|
-
console.warn(`[${props.modelName}]:model`, { diff: diff2, before, after });
|
|
371
|
-
}
|
|
372
|
-
if (diff2.changed) {
|
|
373
|
-
config2.callback(diff2, { component });
|
|
374
|
-
}
|
|
375
|
-
}, config2.options));
|
|
376
|
-
}
|
|
377
|
-
setTimeout(async () => {
|
|
378
|
-
if (props.model !== false && (isFunctionData || isAsyncData)) {
|
|
379
|
-
if (!("defaultData" in vue.vnode.props)) {
|
|
380
|
-
console.warn(`${props.modelName}: defaultData is required for promise or function data.`, props.data);
|
|
381
|
-
}
|
|
382
|
-
const [data] = isAsyncData ? await Promise.all([
|
|
383
|
-
isAsyncFunctionData ? props.data() : props.data,
|
|
384
|
-
defer.value ?? true
|
|
385
|
-
]) : [props.data];
|
|
386
|
-
const source = typeof data === "function" ? data : (() => data);
|
|
387
|
-
subscriptions.push((0, import_vue.watch)(source, async (after, before) => {
|
|
388
|
-
const diff2 = access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after));
|
|
389
|
-
const callback = context.attrs["data:callback"];
|
|
390
|
-
if (props.debug) {
|
|
391
|
-
console.warn(`[${props.modelName}]:data`, { diff: diff2, data, callback, before, after, props, context, component });
|
|
392
|
-
}
|
|
393
|
-
if (typeof callback === "function") {
|
|
394
|
-
callback(diff2, { component });
|
|
395
|
-
} else {
|
|
396
|
-
model.replaceData(after);
|
|
397
|
-
}
|
|
398
|
-
}, {
|
|
399
|
-
immediate: context.attrs["data:immediate"] ?? true,
|
|
400
|
-
deep: context.attrs["data:deep"],
|
|
401
|
-
once: context.attrs["data:once"]
|
|
402
|
-
}));
|
|
403
|
-
}
|
|
404
|
-
});
|
|
405
|
-
setTimeout(async () => {
|
|
406
|
-
isReady.value = await defer.value ?? true;
|
|
407
|
-
});
|
|
408
|
-
component.value = [access(component)].reduce((options, parent) => {
|
|
409
|
-
while (parent) {
|
|
410
|
-
if (typeof parent.setup === "function") {
|
|
411
|
-
options = { parent: options, self: parent.setup(component, options) ?? {} };
|
|
412
|
-
if (access(parent.$parent).ReactiveView) {
|
|
413
|
-
break;
|
|
414
|
-
} else {
|
|
415
|
-
parent = access(parent.$parent);
|
|
416
|
-
}
|
|
417
|
-
} else {
|
|
418
|
-
break;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
return options;
|
|
422
|
-
}, component.value);
|
|
423
|
-
props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
|
|
424
|
-
return (vue2) => {
|
|
425
|
-
if (isReady.value) {
|
|
426
|
-
return access(component).template(component, vue2);
|
|
427
|
-
} else {
|
|
428
|
-
return context.slots.loading?.({ component });
|
|
429
|
-
}
|
|
430
|
-
};
|
|
431
|
-
};
|
|
432
|
-
const current = () => {
|
|
433
|
-
const emit = (after, before) => {
|
|
434
|
-
if (vue && vue.vnode.el) {
|
|
435
|
-
const event = new CustomEvent("data:emit", {
|
|
436
|
-
bubbles: true,
|
|
437
|
-
// Key: allows it to travel up
|
|
438
|
-
composed: true,
|
|
439
|
-
// Key: allows it to cross Shadow DOM boundaries
|
|
440
|
-
detail: { before, after }
|
|
441
|
-
// Payload goes here
|
|
442
|
-
});
|
|
443
|
-
vue.vnode.el.dispatchEvent(event);
|
|
444
|
-
}
|
|
445
|
-
};
|
|
446
|
-
const normalize = (data) => {
|
|
447
|
-
if (props.debug) {
|
|
448
|
-
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) });
|
|
449
|
-
}
|
|
450
|
-
if ((0, import_vue.isReactive)(data)) {
|
|
451
|
-
return data;
|
|
452
|
-
} else {
|
|
453
|
-
if ((0, import_vue.isRef)(data) || isFunctionData || isAsyncData) {
|
|
454
|
-
return (0, import_vue.reactive)(datatype);
|
|
455
|
-
} else {
|
|
456
|
-
const props2 = "data" in vue.vnode.props;
|
|
457
|
-
try {
|
|
458
|
-
if (["Array", "Object"].includes(data?.constructor?.name)) {
|
|
459
|
-
return (0, import_vue.reactive)(props2 ? data : datatype);
|
|
460
|
-
} else {
|
|
461
|
-
return (0, import_vue.reactive)(props2 ? { "": data } : datatype);
|
|
462
|
-
}
|
|
463
|
-
} catch {
|
|
464
|
-
return (0, import_vue.reactive)(props2 ? { "": data } : datatype);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
};
|
|
469
|
-
const config = {
|
|
470
|
-
data: props.beta ? normalize(vue.vnode.props?.data) : (0, import_vue.reactive)(import_object_manager.default.on(
|
|
471
|
-
isAsyncData || isFunctionData || (0, import_vue.isRef)(props.data) || (0, import_vue.isReactive)(props.data) ? datatype : "data" in vue.vnode.props ? props.data : datatype
|
|
472
|
-
).clone()),
|
|
473
|
-
defaultData: import_object_manager.default.on(defaultData).clone(),
|
|
474
|
-
notifications: props.notifications,
|
|
475
|
-
subscriptions: props.subscriptions,
|
|
476
|
-
name: props.modelName,
|
|
477
|
-
logging: props.logging
|
|
478
|
-
};
|
|
479
|
-
const model = new Proxy(props.model ? typeof props.model === "function" ? props.model(config) : props.model : new import_data_manager.default(config), {
|
|
480
|
-
get(target, key, receiver) {
|
|
481
|
-
if (["setData", "replaceData"].includes(key.toString())) {
|
|
482
|
-
return (...params) => {
|
|
483
|
-
const beforeSetData = access(component).beforeSetData ?? props.beforeSetData;
|
|
484
|
-
if (typeof beforeSetData === "function") {
|
|
485
|
-
const before = import_object_manager.default.on(target.getData());
|
|
486
|
-
const after = params.length ? import_object_manager.default.on(datatype).set(...params) : import_object_manager.default.on(datatype).set(defaultData);
|
|
487
|
-
if (beforeSetData(access(component).diff(before, after), target)) {
|
|
488
|
-
target[key](...params);
|
|
489
|
-
}
|
|
490
|
-
} else {
|
|
491
|
-
target[key](...params);
|
|
492
|
-
}
|
|
493
|
-
return target;
|
|
494
|
-
};
|
|
495
|
-
} else {
|
|
496
|
-
return Reflect.get(target, key, receiver);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
const component = (0, import_vue.ref)({ parent: { self: vue.proxy }, self: { template, model, diff, emit, dataPath: dataPath2, isValid } });
|
|
501
|
-
if (props.debug) {
|
|
502
|
-
console.warn("[ReactiveView]:", { props, context, vue, defer, config, model, component, datatype, defaultData, isValid, isReady, isFunctionData, isAsyncFunctionData, isAsyncData });
|
|
503
|
-
}
|
|
504
|
-
const watchDataProp = (dataProp) => {
|
|
505
|
-
const config2 = typeof context.attrs["onUpdate:data"] === "function" ? { callback: context.attrs["onUpdate:data"] } : {
|
|
506
|
-
callback: (context.attrs["onUpdate:data"] ?? {}).callback ?? context.attrs["data:callback"],
|
|
507
|
-
options: Object.assign({
|
|
508
|
-
deep: context.attrs["data:deep"] ?? true,
|
|
509
|
-
...context.attrs["data:immediate"] ? { immediate: context.attrs["data:immediate"] } : {},
|
|
510
|
-
...context.attrs["data:once"] ? { once: context.attrs["data:once"] } : {}
|
|
511
|
-
}, (context.attrs["onUpdate:data"] ?? {}).options)
|
|
512
|
-
};
|
|
513
|
-
if (context.attrs["data:log"]) {
|
|
514
|
-
console.warn(`[ReactiveView]:data`, { config: config2, dataProp });
|
|
515
|
-
}
|
|
516
|
-
subscriptions.push((0, import_vue.watch)(isFunctionData || (0, import_vue.isRef)(dataProp) || (0, import_vue.isReactive)(dataProp) ? dataProp : () => dataProp, (after, before) => {
|
|
517
|
-
if (typeof config2.callback === "function") {
|
|
518
|
-
model.replaceData(config2.callback(access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component }) ?? after);
|
|
519
|
-
} else {
|
|
520
|
-
model.replaceData(after);
|
|
521
|
-
}
|
|
522
|
-
}, config2.options));
|
|
523
|
-
};
|
|
524
|
-
if (context.attrs["onUpdate:model"] || context.attrs["update:model"]) {
|
|
525
|
-
const config2 = typeof context.attrs["onUpdate:model"] === "function" ? {
|
|
526
|
-
callback: context.attrs["onUpdate:model"],
|
|
527
|
-
options: Object.assign({
|
|
528
|
-
deep: context.attrs["model:deep"] ?? true,
|
|
529
|
-
...context.attrs["model:immediate"] ? { immediate: context.attrs["model:immediate"] } : {},
|
|
530
|
-
...context.attrs["model:once"] ? { once: context.attrs["model:once"] } : {}
|
|
531
|
-
}, (context.attrs["onUpdate:model"] ?? {}).options)
|
|
532
|
-
} : context.attrs["onUpdate:model"] ?? {};
|
|
533
|
-
if (context.attrs["model:log"]) {
|
|
534
|
-
console.warn(`[ReactiveView]:model`, { config: config2 });
|
|
535
|
-
}
|
|
536
|
-
subscriptions.push((0, import_vue.watch)(() => import_object_manager.default.on(model.getData()).clone(), (after, before) => {
|
|
537
|
-
config2.callback(access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after)), { component });
|
|
538
|
-
}, config2.options));
|
|
539
|
-
}
|
|
540
|
-
if (props.beta) {
|
|
541
|
-
const isRefData = (0, import_vue.isRef)(props.data);
|
|
542
|
-
if (isRefData || isFunctionData || isAsyncData) {
|
|
543
|
-
setTimeout(async () => {
|
|
544
|
-
const [data] = isAsyncData ? await Promise.all([
|
|
545
|
-
isAsyncFunctionData ? props.data() : props.data,
|
|
546
|
-
defer.value ?? true
|
|
547
|
-
]) : [props.data];
|
|
548
|
-
subscriptions.push((0, import_vue.watch)(isRefData ? data : isFunctionData ? data : typeof data === "function" ? data : () => data, (after, before) => {
|
|
549
|
-
if (before !== void 0 || after !== void 0) {
|
|
550
|
-
const callback = context.attrs["data:callback"];
|
|
551
|
-
if (typeof callback === "function") {
|
|
552
|
-
const diff2 = access(component).diff(import_object_manager.default.on(before), import_object_manager.default.on(after));
|
|
553
|
-
model.replaceData(callback(diff2, { component }) ?? after);
|
|
554
|
-
} else {
|
|
555
|
-
model.replaceData(after);
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
}, {
|
|
559
|
-
immediate: context.attrs["data:immediate"] ?? true,
|
|
560
|
-
deep: context.attrs["data:deep"] ?? true,
|
|
561
|
-
once: context.attrs["data:once"]
|
|
562
|
-
}));
|
|
563
|
-
});
|
|
564
|
-
}
|
|
565
|
-
} else {
|
|
566
|
-
setTimeout(async () => {
|
|
567
|
-
const [data] = await Promise.all([
|
|
568
|
-
isAsyncFunctionData ? props.data() : props.data,
|
|
569
|
-
defer.value ?? true
|
|
570
|
-
]);
|
|
571
|
-
watchDataProp(data);
|
|
572
|
-
});
|
|
573
|
-
}
|
|
574
|
-
setTimeout(async () => {
|
|
575
|
-
isReady.value = await defer.value ?? true;
|
|
576
|
-
});
|
|
577
|
-
component.value = [access(component)].reduce((options, parent) => {
|
|
578
|
-
while (parent) {
|
|
579
|
-
if (typeof parent.setup === "function") {
|
|
580
|
-
options = { parent: options, self: parent.setup(component, options) ?? {} };
|
|
581
|
-
if (access(parent.$parent).ReactiveView) {
|
|
582
|
-
break;
|
|
583
|
-
} else {
|
|
584
|
-
parent = access(parent.$parent);
|
|
585
|
-
}
|
|
586
|
-
} else {
|
|
587
|
-
break;
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
return options;
|
|
591
|
-
}, component.value);
|
|
592
|
-
props.instance.value = typeof props.instance === "function" ? props.instance(component.value) : component.value;
|
|
593
|
-
return (vue2) => {
|
|
594
|
-
if (isReady.value) {
|
|
595
|
-
return access(component).template(component, vue2);
|
|
596
|
-
} else {
|
|
597
|
-
return context.slots.loading?.({ component });
|
|
598
|
-
}
|
|
599
|
-
};
|
|
600
|
-
};
|
|
601
|
-
return props.beta === "next" ? beta() : current();
|
|
602
|
-
}
|
|
603
|
-
};
|
|
604
|
-
|
|
605
|
-
// src/index.ts
|
|
606
|
-
var import_vue2 = require("vue");
|
|
607
|
-
var import_date_fns_tz = require("date-fns-tz");
|
|
608
|
-
var import_tailwind_merge = require("tailwind-merge");
|
|
609
|
-
var ObjectManager2 = import_object_manager2.default.default || import_object_manager2.default;
|
|
610
|
-
var { version } = package_default;
|
|
611
|
-
console.log(`%c[ReactiveView]: ${version}`, "background-color: red; color: yellow;");
|
|
612
|
-
var index_default = ReactiveView_default;
|
|
613
|
-
function safeRequest(request) {
|
|
614
|
-
return new Promise(async (resolve) => {
|
|
615
|
-
const { message } = request.loading ?? {};
|
|
616
|
-
if (request.loading) {
|
|
617
|
-
request.loading.status = true;
|
|
618
|
-
if (request.message) {
|
|
619
|
-
request.loading.message = request.message;
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
try {
|
|
623
|
-
resolve(await request.try());
|
|
624
|
-
} catch (e) {
|
|
625
|
-
if (request.alternative ?? true) {
|
|
626
|
-
resolve(request.catch ? await request.catch(e) : console.log(e));
|
|
627
|
-
}
|
|
628
|
-
} finally {
|
|
629
|
-
await request.finally?.();
|
|
630
|
-
if (request.loading) {
|
|
631
|
-
request.loading.status = false;
|
|
632
|
-
}
|
|
633
|
-
if (request.loading && message) {
|
|
634
|
-
request.loading.message = message;
|
|
635
|
-
}
|
|
636
|
-
await request.complete?.();
|
|
637
|
-
}
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
function getProps(props = {}, param2) {
|
|
641
|
-
const exclude = Array.isArray(param2) || typeof param2 === "string" ? param2 : param2.exclude;
|
|
642
|
-
const exclusions = (Array.isArray(exclude) ? exclude : [exclude]).join("|");
|
|
643
|
-
const include = param2.include ?? {};
|
|
644
|
-
return Object.entries(include).reduce((props2, [key, val]) => {
|
|
645
|
-
props2[key] = val;
|
|
646
|
-
return props2;
|
|
647
|
-
}, Object.entries(props).reduce((props2, [key, val]) => {
|
|
648
|
-
if (!RegExp(`(^|\\|)${key}($|\\|)`, "i").test(exclusions)) {
|
|
649
|
-
props2[key] = val;
|
|
650
|
-
}
|
|
651
|
-
return props2;
|
|
652
|
-
}, {}));
|
|
653
|
-
}
|
|
654
|
-
function getReactiveViewComponent(component, options = {}) {
|
|
655
|
-
const model = (component2) => {
|
|
656
|
-
try {
|
|
657
|
-
return (component2.type || component2).props.hasOwnProperty("model");
|
|
658
|
-
} catch {
|
|
659
|
-
return false;
|
|
660
|
-
}
|
|
661
|
-
};
|
|
662
|
-
const props = getProps(options, "setup");
|
|
663
|
-
const slots = typeof component === "function" ? component : () => {
|
|
664
|
-
return (component.type || component).setup ? (0, import_vue2.createVNode)(component, component.setup ? {} : props) : component;
|
|
665
|
-
};
|
|
666
|
-
return model(component) ? (0, import_vue2.createVNode)(component, props) : (0, import_vue2.createVNode)(ReactiveView_default, props, slots);
|
|
667
|
-
}
|
|
668
|
-
function getDate(param1, param2) {
|
|
669
|
-
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
670
|
-
const format = "MM/dd/yyyy h:mm a";
|
|
671
|
-
const options = typeof param2 === "string" ? { format: param2, timezone } : { format: param2?.format ?? format, timezone: param2?.timezone ?? timezone };
|
|
672
|
-
const datetime = () => {
|
|
673
|
-
try {
|
|
674
|
-
return param1 instanceof Date ? param1 : param1.toDate();
|
|
675
|
-
} catch (e) {
|
|
676
|
-
return /* @__PURE__ */ new Date();
|
|
677
|
-
}
|
|
678
|
-
};
|
|
679
|
-
return (0, import_date_fns_tz.formatInTimeZone)(datetime(), options.timezone, options.format);
|
|
680
|
-
}
|
|
681
|
-
function access(view = {}, alternative) {
|
|
682
|
-
const resolve = (target) => {
|
|
683
|
-
return new Proxy((0, import_vue2.toRaw)(target), {
|
|
684
|
-
get(target2, key) {
|
|
685
|
-
const component = { tree: target2 };
|
|
686
|
-
do {
|
|
687
|
-
if (key in component.tree) {
|
|
688
|
-
return component.tree[key];
|
|
689
|
-
} else if ("self" in component.tree && key in component.tree.self) {
|
|
690
|
-
return component.tree.self[key];
|
|
691
|
-
} else {
|
|
692
|
-
component.tree = "parent" in component.tree && component.tree.parent;
|
|
693
|
-
}
|
|
694
|
-
} while (component.tree);
|
|
695
|
-
try {
|
|
696
|
-
return new alternative();
|
|
697
|
-
} catch {
|
|
698
|
-
return alternative;
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
});
|
|
702
|
-
};
|
|
703
|
-
try {
|
|
704
|
-
const component = (0, import_vue2.unref)(typeof view === "function" ? view() : view) ?? {};
|
|
705
|
-
return resolve("instance" in component ? component.instance : component);
|
|
706
|
-
} catch {
|
|
707
|
-
return resolve(view);
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
function useSubscription() {
|
|
711
|
-
const subscriptions = [];
|
|
712
|
-
const subscription = Subscriptions.get();
|
|
713
|
-
return {
|
|
714
|
-
addSubscription(name, handler = () => false, data) {
|
|
715
|
-
subscription.subscribe(name, handler, data);
|
|
716
|
-
subscriptions.push(() => subscription.unsubscribe(name));
|
|
717
|
-
},
|
|
718
|
-
replaceSubscription(name, handler = () => false, data) {
|
|
719
|
-
subscription.replace(name, handler, data);
|
|
720
|
-
subscriptions.push(() => subscription.unsubscribe(name));
|
|
721
|
-
},
|
|
722
|
-
removeSubscriptions() {
|
|
723
|
-
subscriptions.forEach((subscription2) => safeRequest({
|
|
724
|
-
try: () => subscription2()
|
|
725
|
-
}));
|
|
726
|
-
},
|
|
727
|
-
removeSubscription(name) {
|
|
728
|
-
subscription.unsubscribe(name);
|
|
729
|
-
},
|
|
730
|
-
hasSubscription(name) {
|
|
731
|
-
return subscription.hasSubscription(name);
|
|
732
|
-
},
|
|
733
|
-
subscriptions,
|
|
734
|
-
subscription
|
|
735
|
-
};
|
|
736
|
-
}
|
|
737
|
-
var Prop = ({ default: value, type, validator, required } = {}) => {
|
|
738
|
-
const types1 = Array.isArray(type) ? type : [type ?? Array];
|
|
739
|
-
const types2 = types1.includes(Object) ? types1 : types1.concat(Object);
|
|
740
|
-
return {
|
|
741
|
-
...value ? { default: (0, import_vue2.isRef)(value) || (0, import_vue2.isReactive)(value) ? value : (0, import_vue2.ref)(value) } : {},
|
|
742
|
-
required,
|
|
743
|
-
validator: (value2) => {
|
|
744
|
-
try {
|
|
745
|
-
return validator ? validator((0, import_vue2.unref)(value2)) : Array.from(new Set(types2.map((type2) => {
|
|
746
|
-
return typeof type2 === "function" ? type2().constructor.name : type2;
|
|
747
|
-
}))).includes((0, import_vue2.unref)(value2).constructor.name);
|
|
748
|
-
} catch {
|
|
749
|
-
return !required;
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
};
|
|
753
|
-
};
|
|
754
|
-
function StyleParser(styles = {}) {
|
|
755
|
-
const transform = (style, status = true) => {
|
|
756
|
-
const remove = style.split(/(-{[^}]+})/);
|
|
757
|
-
return remove.reduce((object, style2) => {
|
|
758
|
-
const remove2 = /-{(.+?)}/.exec(style2);
|
|
759
|
-
(remove2 ? remove2[1] ?? style2 : style2).split(/\s+/).forEach((item) => {
|
|
760
|
-
if (item) {
|
|
761
|
-
Object.assign(object, { [item]: remove2 ? false : status });
|
|
762
|
-
}
|
|
763
|
-
});
|
|
764
|
-
return object;
|
|
765
|
-
}, {});
|
|
766
|
-
};
|
|
767
|
-
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]) => {
|
|
768
|
-
return {
|
|
769
|
-
...acc,
|
|
770
|
-
...transform(styles2, value)
|
|
771
|
-
};
|
|
772
|
-
}, {});
|
|
773
|
-
}
|
|
774
|
-
function MergeStyles(...params) {
|
|
775
|
-
return new Proxy(params.reduce((styles, style, index, items) => {
|
|
776
|
-
const item = items[items.length - index - 1] ?? {};
|
|
777
|
-
return {
|
|
778
|
-
...StyleParser(typeof item === "function" ? item(items.slice(0, index - 1)) : item),
|
|
779
|
-
...styles
|
|
780
|
-
};
|
|
781
|
-
}, {}), {
|
|
782
|
-
get: (target, key, receiver) => {
|
|
783
|
-
const styles = Object.entries(target).reduce((styles2, [key2, val]) => {
|
|
784
|
-
return val ? styles2.concat(key2) : styles2;
|
|
785
|
-
}, []);
|
|
786
|
-
if (key === "string") {
|
|
787
|
-
return styles.join(" ");
|
|
788
|
-
} else if (key === "array") {
|
|
789
|
-
return styles;
|
|
790
|
-
} else {
|
|
791
|
-
return Reflect.get(target, key, receiver);
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
});
|
|
795
|
-
}
|
|
796
|
-
var extendVnode = (component, element) => {
|
|
797
|
-
return new Proxy(access(component), {
|
|
798
|
-
get: (target, key) => {
|
|
799
|
-
const getVnode = () => {
|
|
800
|
-
try {
|
|
801
|
-
return target[key]();
|
|
802
|
-
} catch {
|
|
803
|
-
throw new Error(`${key} does not exist as vnode on component.`);
|
|
804
|
-
}
|
|
805
|
-
};
|
|
806
|
-
const vnode = getVnode();
|
|
807
|
-
return (props = {}, slots) => {
|
|
808
|
-
const isFunctionClass = typeof props.class === "function";
|
|
809
|
-
const isFunctionStyle = typeof props.style === "function";
|
|
810
|
-
const { class: classes, style: styles, ...rest } = vnode.props ?? {};
|
|
811
|
-
const finalClasses = (0, import_tailwind_merge.twMerge)(isFunctionClass ? "" : classes, MergeStyles(isFunctionClass ? props.class(classes) : props.class).string);
|
|
812
|
-
const finalStyles = MergeStyles(styles, isFunctionStyle ? props.style(styles) : props.style);
|
|
813
|
-
const functionalProps = Object.entries(props).reduce((props2, [key2, value]) => {
|
|
814
|
-
if (!["class", "style", "setup"].includes(key2) && typeof value === "function") {
|
|
815
|
-
props2[key2] = value(vnode.props?.[key2]);
|
|
816
|
-
}
|
|
817
|
-
return props2;
|
|
818
|
-
}, props);
|
|
819
|
-
const finalProps = Object.assign(rest, functionalProps, { class: finalClasses, style: finalStyles });
|
|
820
|
-
const finalSlots = slots ? typeof slots === "function" ? slots(vnode.children) : slots : vnode.children;
|
|
821
|
-
const finalElement = ["undefined"].includes(typeof element) ? vnode.type : element;
|
|
822
|
-
return (0, import_vue2.h)(finalElement, finalProps, finalSlots);
|
|
823
|
-
};
|
|
824
|
-
}
|
|
825
|
-
});
|
|
826
|
-
};
|
|
827
|
-
function defineReactiveView(param1, param2) {
|
|
828
|
-
const instance = (0, import_vue2.ref)();
|
|
829
|
-
return (0, import_vue2.defineComponent)({
|
|
830
|
-
name: param1?.modelName,
|
|
831
|
-
props: { setup, ...param1 ? param1.props : {} },
|
|
832
|
-
setup() {
|
|
833
|
-
const { setup: setup2, props, ...rest } = param1 ?? {};
|
|
834
|
-
return (component) => {
|
|
835
|
-
const props2 = Object.entries(rest).reduce((props3, [key, val]) => {
|
|
836
|
-
return Object.assign(props3, { [key]: typeof val === "function" ? val(component, instance) : val });
|
|
837
|
-
}, {});
|
|
838
|
-
const slots = typeof param1?.slots === "function" ? param1.slots(component) : Array.isArray(param1?.slots) ? () => param1.slots : param1?.slots;
|
|
839
|
-
return (0, import_vue2.createVNode)(param2 ?? ReactiveView_default, {
|
|
840
|
-
...props2,
|
|
841
|
-
...Object.assign({}, props2, typeof setup2 === "function" ? {
|
|
842
|
-
setup: (self, parent) => setup2(self, parent, component)
|
|
843
|
-
} : {}),
|
|
844
|
-
instance
|
|
845
|
-
}, slots);
|
|
846
|
-
};
|
|
847
|
-
}
|
|
848
|
-
});
|
|
849
|
-
}
|
|
850
|
-
function showComponent(component, options = {}) {
|
|
851
|
-
if (options.router) {
|
|
852
|
-
console.warn("[ReactiveView]: Deprecated {router} option used with {showComponent()}. \nUse {plugins} option instead.");
|
|
853
|
-
}
|
|
854
|
-
if (!options.key || !document.getElementById(options.key)) {
|
|
855
|
-
const container = options.container || "app-dialogs";
|
|
856
|
-
const dialogs = document.getElementById(container) || document.createElement("div");
|
|
857
|
-
if (!dialogs.hasAttribute("id")) {
|
|
858
|
-
dialogs.setAttribute("id", container);
|
|
859
|
-
document.body.appendChild(dialogs);
|
|
860
|
-
}
|
|
861
|
-
const dialog = document.createElement("div");
|
|
862
|
-
const id = options.key ?? `dialog_${dialogs.children.length + 1}`;
|
|
863
|
-
dialog.setAttribute("id", id);
|
|
864
|
-
dialogs.appendChild(dialog);
|
|
865
|
-
const app = (0, import_vue2.createApp)(
|
|
866
|
-
{
|
|
867
|
-
setup() {
|
|
868
|
-
return () => component;
|
|
869
|
-
}
|
|
870
|
-
},
|
|
871
|
-
{
|
|
872
|
-
__cleanup__: () => {
|
|
873
|
-
document.querySelectorAll(`#${id}`).forEach((element) => element.remove());
|
|
874
|
-
app.unmount();
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
);
|
|
878
|
-
if (options.router) {
|
|
879
|
-
return app.use(options.router).mount(`#${id}`);
|
|
880
|
-
} else if (options.plugins) {
|
|
881
|
-
return options.plugins.reduce((app2, plugin) => {
|
|
882
|
-
return app2.use(...Array.isArray(plugin) ? plugin : [plugin]);
|
|
883
|
-
}, app).mount(`#${id}`);
|
|
884
|
-
} else {
|
|
885
|
-
return app.mount(`#${id}`);
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
var getData = (component, path, alternative) => {
|
|
890
|
-
const vue = access(component);
|
|
891
|
-
const data = ObjectManager2.on(componentState(vue));
|
|
892
|
-
if (path) {
|
|
893
|
-
return data.get(dataPath(vue, path), alternative);
|
|
894
|
-
} else {
|
|
895
|
-
return data.get();
|
|
896
|
-
}
|
|
897
|
-
};
|
|
898
|
-
var setData = (component, data, path) => {
|
|
899
|
-
const vue = access(component);
|
|
900
|
-
const diff = {
|
|
901
|
-
before: ObjectManager2.on(componentState(vue)).clone(),
|
|
902
|
-
after: path ? ObjectManager2.on(componentState(vue)).set(dataPath(vue, path), data).get() : ObjectManager2.on(componentState(vue)).set(data).get()
|
|
903
|
-
};
|
|
904
|
-
return "state" in vue ? diff : vue.$emit("update:state", diff);
|
|
905
|
-
};
|
|
906
|
-
var componentState = (component) => {
|
|
907
|
-
return (0, import_vue2.unref)("state" in component ? component.state : component.$attrs.state);
|
|
908
|
-
};
|
|
909
|
-
var dataPath = (component, path) => {
|
|
910
|
-
return typeof component.$attrs["data:path"] === "function" ? component.$attrs["data:path"](path) : path;
|
|
911
|
-
};
|
|
912
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
913
|
-
0 && (module.exports = {
|
|
914
|
-
MergeStyles,
|
|
915
|
-
Prop,
|
|
916
|
-
StyleParser,
|
|
917
|
-
access,
|
|
918
|
-
dataPath,
|
|
919
|
-
defineReactiveView,
|
|
920
|
-
extendVnode,
|
|
921
|
-
getData,
|
|
922
|
-
getDate,
|
|
923
|
-
getProps,
|
|
924
|
-
getReactiveViewComponent,
|
|
925
|
-
safeRequest,
|
|
926
|
-
setData,
|
|
927
|
-
setup,
|
|
928
|
-
showComponent,
|
|
929
|
-
useSubscription
|
|
930
|
-
});
|
|
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;
|