@domyjs/collapse 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +750 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +30 -0
package/dist/index.d.ts
ADDED
@@ -0,0 +1,750 @@
|
|
1
|
+
type AppState = {
|
2
|
+
isSetuped: boolean;
|
3
|
+
isMounted: boolean;
|
4
|
+
isUnmounted: boolean;
|
5
|
+
};
|
6
|
+
type State = {
|
7
|
+
data: Record<string, unknown>;
|
8
|
+
componentInfos?: ComponentInfos;
|
9
|
+
refs: Record<string, Element>;
|
10
|
+
};
|
11
|
+
declare namespace ReactiveUtils {
|
12
|
+
/* eslint @typescript-eslint/no-this-alias: "off" */
|
13
|
+
type Listener = OnGetListener | OnSetListener;
|
14
|
+
type OnGetListener = {
|
15
|
+
type: "onGet";
|
16
|
+
fn: (props: {
|
17
|
+
reactiveVariable: ReactiveVariable;
|
18
|
+
path: string;
|
19
|
+
}) => void;
|
20
|
+
};
|
21
|
+
type OnSetListener = {
|
22
|
+
type: "onSet";
|
23
|
+
fn: (props: {
|
24
|
+
reactiveVariable: ReactiveVariable;
|
25
|
+
path: string;
|
26
|
+
prevValue: any;
|
27
|
+
newValue: any;
|
28
|
+
}) => void | Promise<void>;
|
29
|
+
};
|
30
|
+
const isProxySymbol: unique symbol;
|
31
|
+
const isSignalSymbol: unique symbol;
|
32
|
+
const skipReactivitySymbol: unique symbol;
|
33
|
+
/**
|
34
|
+
* Allow to create a DeepProxy to listen to any change into an object
|
35
|
+
* @author yoannchb-pro
|
36
|
+
*/
|
37
|
+
class ReactiveVariable {
|
38
|
+
private target;
|
39
|
+
name: string;
|
40
|
+
private proxy;
|
41
|
+
private onSetListeners;
|
42
|
+
private onGetListeners;
|
43
|
+
static IS_GLOBAL_LOCK: boolean;
|
44
|
+
constructor(target: any);
|
45
|
+
getProxy(): any;
|
46
|
+
/**
|
47
|
+
* Check if the current target is already a proxy
|
48
|
+
* @param target
|
49
|
+
* @returns
|
50
|
+
*/
|
51
|
+
static isReactive(target: any): boolean;
|
52
|
+
/**
|
53
|
+
* Check if the current target is a signal instead of a reactive
|
54
|
+
* @param target
|
55
|
+
* @returns
|
56
|
+
*/
|
57
|
+
static isSignal(target: any): boolean;
|
58
|
+
/**
|
59
|
+
* Check we should skip the reactivity on the current element
|
60
|
+
* @param target
|
61
|
+
* @returns
|
62
|
+
*/
|
63
|
+
static shouldBeSkip(target: any): boolean;
|
64
|
+
clearListeners(): void;
|
65
|
+
attachListener(l: Listener): () => void;
|
66
|
+
removeListener(l: Listener): void;
|
67
|
+
private canAttachProxy;
|
68
|
+
private isCollection;
|
69
|
+
private createCollectionHandler;
|
70
|
+
private createHandler;
|
71
|
+
private createProxy;
|
72
|
+
private callOnGetListeners;
|
73
|
+
private callOnSetListeners;
|
74
|
+
}
|
75
|
+
/**
|
76
|
+
* Attach a listener to all reactive variables
|
77
|
+
* @param listener
|
78
|
+
*
|
79
|
+
* @author yoannchb-pro
|
80
|
+
*/
|
81
|
+
function globalWatch(listener: Listener, tracking?: boolean): () => void;
|
82
|
+
/**
|
83
|
+
* Will return true if a obj is a signal/reactive
|
84
|
+
* @param obj
|
85
|
+
* @returns
|
86
|
+
*
|
87
|
+
* @author yoannchb-pro
|
88
|
+
*/
|
89
|
+
function isReactive(obj: any): boolean;
|
90
|
+
/**
|
91
|
+
* Will return true if the obj is a signal
|
92
|
+
* @param obj
|
93
|
+
* @returns
|
94
|
+
*
|
95
|
+
* @author yoannchb-pro
|
96
|
+
*/
|
97
|
+
function isSignal(obj: any): boolean;
|
98
|
+
type MatchingResult = {
|
99
|
+
isMatching: boolean;
|
100
|
+
params: Record<string, string>;
|
101
|
+
};
|
102
|
+
/**
|
103
|
+
* Check if a path match a certain rule
|
104
|
+
* Example:
|
105
|
+
* path: todos.0.isComplete
|
106
|
+
* reg: todos.*.isComplete or todos, todos.* or todos.*.*
|
107
|
+
* Will give true
|
108
|
+
* reg: todos.1.isComplete, todos.*.name, todos.*.*.id
|
109
|
+
* Will give false
|
110
|
+
* @param reg
|
111
|
+
* @param path
|
112
|
+
* @returns
|
113
|
+
*
|
114
|
+
* @author yoannchb-pro
|
115
|
+
*/
|
116
|
+
function matchPath(reg: string, path: string): MatchingResult;
|
117
|
+
/**
|
118
|
+
* Transform an object into a reactive object to listen to any change
|
119
|
+
* @param obj
|
120
|
+
* @returns
|
121
|
+
*
|
122
|
+
* @author yoannchb-pro
|
123
|
+
*/
|
124
|
+
function reactive<T>(obj: T): T;
|
125
|
+
/**
|
126
|
+
* Register a name for a reactive variable
|
127
|
+
* It allow us to have a correct path name
|
128
|
+
* Example of use case:
|
129
|
+
* cont count = signal(0);
|
130
|
+
* watch(({ path }) => console.log(path), [count]);
|
131
|
+
* count.value += 1;
|
132
|
+
*
|
133
|
+
* The path is going to be "value" instead of "count.value" because we don't know the variable name
|
134
|
+
* So to fixe that we just need to put registerName("count", count) after the variable declaration
|
135
|
+
* @param name
|
136
|
+
* @param obj
|
137
|
+
* @returns
|
138
|
+
*
|
139
|
+
* @author yoannchb-pro
|
140
|
+
*/
|
141
|
+
function registerName(name: string, obj: any): void;
|
142
|
+
/**
|
143
|
+
* Transform a primitive into a reactive object to listen to any change
|
144
|
+
* @param obj
|
145
|
+
* @returns
|
146
|
+
*
|
147
|
+
* @author yoannchb-pro
|
148
|
+
*/
|
149
|
+
function signal<T>(obj: T): {
|
150
|
+
value: T;
|
151
|
+
};
|
152
|
+
/**
|
153
|
+
* Attach a listener to some reactives variables
|
154
|
+
* @param listener
|
155
|
+
* @param effect
|
156
|
+
*
|
157
|
+
* @author yoannchb-pro
|
158
|
+
*/
|
159
|
+
function watch(listener: Listener, effect: () => any): () => void;
|
160
|
+
/**
|
161
|
+
* Allow us to lock every watcher if we need to do a set/get action on the object without calling the watcher
|
162
|
+
*
|
163
|
+
* @author yoannchb-pro
|
164
|
+
*/
|
165
|
+
function lockWatchers(): void;
|
166
|
+
/**
|
167
|
+
* Unlock every watchers
|
168
|
+
*
|
169
|
+
* @author yoannchb-pro
|
170
|
+
*/
|
171
|
+
function unlockWatchers(): void;
|
172
|
+
/**
|
173
|
+
* Will delete the reactivity of a data
|
174
|
+
* @param obj
|
175
|
+
* @returns
|
176
|
+
*
|
177
|
+
* @author yoannchb-pro
|
178
|
+
*/
|
179
|
+
function unReactive<T = any>(obj: T): T;
|
180
|
+
/**
|
181
|
+
* Skip the reactivity on an element we don't wanna listen to in a reactivity variable
|
182
|
+
* Example:
|
183
|
+
* const myElement = reactive({ el: skipReactive({ ... }), name: 'div' })
|
184
|
+
* @param obj
|
185
|
+
* @returns
|
186
|
+
*
|
187
|
+
* @author yoannchb-pro
|
188
|
+
*/
|
189
|
+
function skipReactive<T = any>(obj: T): T;
|
190
|
+
type Effect = () => any;
|
191
|
+
type UnEffect = () => void;
|
192
|
+
type WatchEffectOptions = {
|
193
|
+
noSelfUpdate?: boolean; // Avoid the effect to launch the function again
|
194
|
+
onDepChange?: (uneffect: UnEffect) => void;
|
195
|
+
};
|
196
|
+
/**
|
197
|
+
* Act like a watcher but get his dependencies it self by running one time the instance
|
198
|
+
* Example:
|
199
|
+
* const todo = reactive({ title: "Yoann", isCompleted: false });
|
200
|
+
* const uneffect = watchEffect(() => console.log(todo.title)); // Will display: "Yoann" when initialising
|
201
|
+
* todo.isCompleted = true; // Don't call the effect
|
202
|
+
* todo.title = "Pierre"; // Will call the effect and display "Pierre"
|
203
|
+
* @param effectFn
|
204
|
+
*
|
205
|
+
* @author yoannchb-pro
|
206
|
+
*/
|
207
|
+
function watchEffect(effect: Effect, opts?: WatchEffectOptions): UnEffect;
|
208
|
+
type Dep = {
|
209
|
+
type: "reactive_variable_creation";
|
210
|
+
reactiveVariable: ReactiveVariable;
|
211
|
+
clean: () => void;
|
212
|
+
} | {
|
213
|
+
type: "watcher" | "effect" | "global_watcher";
|
214
|
+
clean: () => void;
|
215
|
+
};
|
216
|
+
let trackCallback: ((dep: Dep) => void) | null;
|
217
|
+
/**
|
218
|
+
* Allow us to track inside a function:
|
219
|
+
* - reactive variable (signal + reactive)
|
220
|
+
* - watcher
|
221
|
+
* - effects
|
222
|
+
* - global watchers
|
223
|
+
* @param fn
|
224
|
+
* @returns
|
225
|
+
*
|
226
|
+
* @author yoannchb-pro
|
227
|
+
*/
|
228
|
+
function trackDeps(fn: () => any): Dep[];
|
229
|
+
const isComputedSymbol: unique symbol;
|
230
|
+
/**
|
231
|
+
* Will return a boolean determining if an object is a computed value or not
|
232
|
+
* @param obj
|
233
|
+
* @returns
|
234
|
+
*
|
235
|
+
* @author yoannchb-pro
|
236
|
+
*/
|
237
|
+
function isComputed(obj: any): boolean;
|
238
|
+
/**
|
239
|
+
* Create a computed variable based on a signal
|
240
|
+
* Example:
|
241
|
+
* const count = signal(1);
|
242
|
+
* const doubleCount = computed(() => count.value * 2);
|
243
|
+
* console.log(doubleCount); // 2
|
244
|
+
* @param getter
|
245
|
+
* @param setter
|
246
|
+
* @returns
|
247
|
+
*
|
248
|
+
* @author yoannchb-pro
|
249
|
+
*/
|
250
|
+
function computed<T extends () => unknown, R extends ReturnType<T>>(getter: () => R, setter?: (newValue: R) => void): {
|
251
|
+
[isComputedSymbol]: boolean;
|
252
|
+
value: R;
|
253
|
+
};
|
254
|
+
}
|
255
|
+
type Config = {
|
256
|
+
avoidDeprecatedWith?: boolean;
|
257
|
+
CSP?: boolean;
|
258
|
+
};
|
259
|
+
type Props = {
|
260
|
+
domyHelperId?: number;
|
261
|
+
el?: Element | Text;
|
262
|
+
state: State;
|
263
|
+
scopedNodeData: Record<string, any>[];
|
264
|
+
config: Config;
|
265
|
+
pluginHelper: PluginHelper;
|
266
|
+
};
|
267
|
+
/**
|
268
|
+
* Return a context with all what domy need to render
|
269
|
+
* Like variables, methods, helpers ...
|
270
|
+
* @param el
|
271
|
+
* @param state
|
272
|
+
* @param scopedNodeData
|
273
|
+
* @returns
|
274
|
+
*
|
275
|
+
* @author yoannchb-pro
|
276
|
+
*/
|
277
|
+
declare function getContext(props: Props): {
|
278
|
+
[x: `$${string}`]: any;
|
279
|
+
};
|
280
|
+
type QueueElement = () => any;
|
281
|
+
/**
|
282
|
+
* Scheduler function to add a job to the queue
|
283
|
+
* @param job
|
284
|
+
*
|
285
|
+
* @author yoannchb-pro
|
286
|
+
*/
|
287
|
+
declare function queueJob(job: QueueElement, id: number): void;
|
288
|
+
/**
|
289
|
+
* Return an unique queue id
|
290
|
+
* @returns
|
291
|
+
*
|
292
|
+
* @author yoannchb-pro
|
293
|
+
*/
|
294
|
+
declare function getUniqueQueueId(): number;
|
295
|
+
/**
|
296
|
+
* Call a function with error handling
|
297
|
+
* @param fn
|
298
|
+
* @returns
|
299
|
+
*
|
300
|
+
* @author yoannchb-pro
|
301
|
+
*/
|
302
|
+
declare function callWithErrorHandling<T extends (...args: any[]) => any>(fn: T, onError?: (err: any) => void): {
|
303
|
+
hasError: true;
|
304
|
+
err: any;
|
305
|
+
} | {
|
306
|
+
hasError: false;
|
307
|
+
result: ReturnType<T>;
|
308
|
+
};
|
309
|
+
/**
|
310
|
+
* Fixe an attribute name to avoid setAttribute throwing error
|
311
|
+
* @param attrName
|
312
|
+
* @returns
|
313
|
+
*
|
314
|
+
* @author yoannchb-pro
|
315
|
+
*/
|
316
|
+
declare function fixeAttrName(attrName: string): string;
|
317
|
+
/**
|
318
|
+
* Retrieve some utils informations from a domy attribute
|
319
|
+
* @param attr
|
320
|
+
* @returns
|
321
|
+
*
|
322
|
+
* @author yoannchb-pro
|
323
|
+
*/
|
324
|
+
declare function getDomyAttributeInformations(attr: Attr): {
|
325
|
+
prefix: string;
|
326
|
+
directive: string;
|
327
|
+
modifiers: string[];
|
328
|
+
attrName: string;
|
329
|
+
};
|
330
|
+
/**
|
331
|
+
* Execute a function after the animation/transition on an element is finish
|
332
|
+
* @param el
|
333
|
+
* @param action
|
334
|
+
* @returns
|
335
|
+
*
|
336
|
+
* @author yoannchb-pro
|
337
|
+
*/
|
338
|
+
declare function executeActionAfterAnimation(el: Element, action: () => void): () => void;
|
339
|
+
/**
|
340
|
+
* Get function (like get in lodash)
|
341
|
+
* @param object
|
342
|
+
* @param path
|
343
|
+
* @param defaultValue
|
344
|
+
* @returns
|
345
|
+
*
|
346
|
+
* @author yoannchb-pro
|
347
|
+
*/
|
348
|
+
declare function get<T = any>(object: Array<any> | Record<string, any>, path: string, defaultValue?: any): T | undefined;
|
349
|
+
/**
|
350
|
+
* Set function (like set in lodash)
|
351
|
+
* @param object
|
352
|
+
* @param path
|
353
|
+
* @param value
|
354
|
+
* @returns
|
355
|
+
*
|
356
|
+
* @author yoannchb-pro
|
357
|
+
*/
|
358
|
+
declare function set<T>(object: T, path: string, value: any): T;
|
359
|
+
type Props$0 = {
|
360
|
+
shouldBeDisplay: () => boolean;
|
361
|
+
domy: DomyDirectiveHelper;
|
362
|
+
};
|
363
|
+
/**
|
364
|
+
* Handle the visibility of an element with the transition
|
365
|
+
* @param props
|
366
|
+
* @returns
|
367
|
+
*
|
368
|
+
* @author yoannchb-pro
|
369
|
+
*/
|
370
|
+
declare function getElementVisibilityHandler(props: Props$0): {
|
371
|
+
effect: () => void;
|
372
|
+
cleanup: () => void;
|
373
|
+
};
|
374
|
+
/**
|
375
|
+
* Return the list of previous conditions elements before an element
|
376
|
+
* Useful for d-else and d-else-if directives
|
377
|
+
* @param element
|
378
|
+
* @param previousAuthorizedAttrs
|
379
|
+
* @returns
|
380
|
+
*
|
381
|
+
* @author yoannchb-pro
|
382
|
+
*/
|
383
|
+
declare function getPreviousConditionsElements(element: HTMLElement, previousAuthorizedAttrs: string[]): Element[];
|
384
|
+
/**
|
385
|
+
* Return the get and set method for a reactive variable
|
386
|
+
* It allow us to keep the proxy and to handle signals
|
387
|
+
* @param obj
|
388
|
+
* @param key
|
389
|
+
* @returns
|
390
|
+
*
|
391
|
+
* @author yoannchb-pro
|
392
|
+
*/
|
393
|
+
declare function getReactiveHandler(obj: Record<string, any>, key: string): PropertyDescriptor;
|
394
|
+
/**
|
395
|
+
* Handle class attribute if it's a string or an object like
|
396
|
+
* { show: true }
|
397
|
+
* or
|
398
|
+
* ["show"]
|
399
|
+
* @param executedValue
|
400
|
+
* @param defaultClass
|
401
|
+
*
|
402
|
+
* @author yoannchb-pro
|
403
|
+
*/
|
404
|
+
declare function handleClass(executedValue: any, defaultClass?: string): {
|
405
|
+
class: string;
|
406
|
+
cleanedClass: (newDefaultClass: string) => string;
|
407
|
+
};
|
408
|
+
/**
|
409
|
+
* Handle style attribute if it's an object
|
410
|
+
* { backgroundColor: '#fff', color: 'red' .... }
|
411
|
+
* @param executedValue
|
412
|
+
* @param defaultStyle
|
413
|
+
*
|
414
|
+
* @author yoannchb-pro
|
415
|
+
*/
|
416
|
+
declare function handleStyle(executedValue: any, defaultStyle?: string): {
|
417
|
+
style: string;
|
418
|
+
cleanedStyle: (newDefaultStyle: string) => string;
|
419
|
+
};
|
420
|
+
/**
|
421
|
+
* Check if the current attribute is a binding attribute
|
422
|
+
* @param attr
|
423
|
+
* @returns
|
424
|
+
*
|
425
|
+
* @author yoannchb-pro
|
426
|
+
*/
|
427
|
+
declare function isBindAttr(attr: string): boolean;
|
428
|
+
/**
|
429
|
+
* Check if the current attribute is an event attribute
|
430
|
+
* @param attr
|
431
|
+
* @returns
|
432
|
+
*
|
433
|
+
* @author yoannchb-pro
|
434
|
+
*/
|
435
|
+
declare function isEventAttr(attr: string): boolean;
|
436
|
+
declare function isDNameAttr(attr: string): boolean;
|
437
|
+
/**
|
438
|
+
* Check if the current attribute is a domy attribute
|
439
|
+
* It could be a prefix like d-on:click
|
440
|
+
* Or it could be a simple attribute like d-for
|
441
|
+
* @param attr
|
442
|
+
* @returns
|
443
|
+
*
|
444
|
+
* @author yoannchb-pro
|
445
|
+
*/
|
446
|
+
declare function isDomyAttr(PLUGINS: Plugins, attr: string): boolean;
|
447
|
+
/**
|
448
|
+
* Check if the current attribute is a normal attribute
|
449
|
+
* @param attr
|
450
|
+
* @returns
|
451
|
+
*
|
452
|
+
* @author yoannchb-pro
|
453
|
+
*/
|
454
|
+
declare function isNormalAttr(PLUGINS: Plugins, attr: string): boolean;
|
455
|
+
/**
|
456
|
+
* Convert a kebab string into a camelCase string
|
457
|
+
* Example: show-error -> showError
|
458
|
+
* @param str
|
459
|
+
* @returns
|
460
|
+
*
|
461
|
+
* @author yoannchb-pro
|
462
|
+
*/
|
463
|
+
declare function kebabToCamelCase(str: string): string;
|
464
|
+
/**
|
465
|
+
* Warn log function for domy
|
466
|
+
* @param msg
|
467
|
+
*
|
468
|
+
* @author yoannchb-pro
|
469
|
+
*/
|
470
|
+
declare function warn(msg: string): void;
|
471
|
+
/**
|
472
|
+
* Error log function for domy
|
473
|
+
* @param err
|
474
|
+
*
|
475
|
+
* @author yoannchb-pro
|
476
|
+
*/
|
477
|
+
declare function error(...errs: (Error | string)[]): void;
|
478
|
+
/**
|
479
|
+
* Allow us to merge conditions for d-else and d-else-if
|
480
|
+
* @param conditions
|
481
|
+
* @returns
|
482
|
+
*
|
483
|
+
* @author yoannchb-pro
|
484
|
+
*/
|
485
|
+
declare function mergeToNegativeCondition(conditions: string[]): string;
|
486
|
+
/**
|
487
|
+
* Convert a string to kebab case
|
488
|
+
* Example:
|
489
|
+
* console.log(toKebabCase('HelloWorld')); // hello-world
|
490
|
+
* console.log(toKebabCase('myVariableName')); // my-variable-name
|
491
|
+
* console.log(toKebabCase('Hello World Today')); // hello-world-today
|
492
|
+
* @param str
|
493
|
+
* @returns
|
494
|
+
*
|
495
|
+
* @author yoannchb-pro
|
496
|
+
*/
|
497
|
+
declare function toKebabCase(str: string): string;
|
498
|
+
// A list of utils we can access in helpers
|
499
|
+
declare const helpersUtils: {
|
500
|
+
handleClass: typeof handleClass;
|
501
|
+
handleStyle: typeof handleStyle;
|
502
|
+
callWithErrorHandling: typeof callWithErrorHandling;
|
503
|
+
toKebabCase: typeof toKebabCase;
|
504
|
+
kebabToCamelCase: typeof kebabToCamelCase;
|
505
|
+
getElementVisibilityHandler: typeof getElementVisibilityHandler;
|
506
|
+
get: typeof get;
|
507
|
+
set: typeof set;
|
508
|
+
getPreviousConditionsElements: typeof getPreviousConditionsElements;
|
509
|
+
executeActionAfterAnimation: typeof executeActionAfterAnimation;
|
510
|
+
getReactiveHandler: typeof getReactiveHandler;
|
511
|
+
mergeToNegativeCondition: typeof mergeToNegativeCondition;
|
512
|
+
fixeAttrName: typeof fixeAttrName;
|
513
|
+
getDomyAttributeInformations: typeof getDomyAttributeInformations;
|
514
|
+
isDomyAttr: typeof isDomyAttr;
|
515
|
+
isNormalAttr: typeof isNormalAttr;
|
516
|
+
isEventAttr: typeof isEventAttr;
|
517
|
+
isBindAttr: typeof isBindAttr;
|
518
|
+
isDNameAttr: typeof isDNameAttr;
|
519
|
+
warn: typeof warn;
|
520
|
+
error: typeof error;
|
521
|
+
};
|
522
|
+
type Helpers = Record<`$${string}`, any>;
|
523
|
+
type Props$1 = {
|
524
|
+
domyHelperId?: number;
|
525
|
+
el?: Element | Text;
|
526
|
+
state: State;
|
527
|
+
config: Config;
|
528
|
+
scopedNodeData: Record<string, any>[];
|
529
|
+
pluginHelper: PluginHelper;
|
530
|
+
};
|
531
|
+
/**
|
532
|
+
* Return the initialised helpers with everything it need
|
533
|
+
* @param el
|
534
|
+
* @param state
|
535
|
+
* @param scopedNodeData
|
536
|
+
* @returns
|
537
|
+
*
|
538
|
+
* @author yoannchb-pro
|
539
|
+
*/
|
540
|
+
declare function getHelpers(props: Props$1): Helpers;
|
541
|
+
type Options = {
|
542
|
+
dontQueueOnFirstExecution?: boolean;
|
543
|
+
effectId?: number;
|
544
|
+
};
|
545
|
+
/**
|
546
|
+
* Allow to queue an effect
|
547
|
+
* @param effect
|
548
|
+
* @param opts
|
549
|
+
*
|
550
|
+
* @author yoannchb-pro
|
551
|
+
*/
|
552
|
+
declare function queuedWatchEffect(effect: () => any, opts?: Options): () => void;
|
553
|
+
// A list of utils we can access in directives/prefix
|
554
|
+
declare const directivesUtils: {
|
555
|
+
getHelpers: typeof getHelpers;
|
556
|
+
queuedWatchEffect: typeof queuedWatchEffect;
|
557
|
+
handleClass: typeof handleClass;
|
558
|
+
handleStyle: typeof handleStyle;
|
559
|
+
callWithErrorHandling: typeof callWithErrorHandling;
|
560
|
+
toKebabCase: typeof toKebabCase;
|
561
|
+
kebabToCamelCase: typeof kebabToCamelCase;
|
562
|
+
getElementVisibilityHandler: typeof getElementVisibilityHandler;
|
563
|
+
get: typeof get;
|
564
|
+
set: typeof set;
|
565
|
+
getPreviousConditionsElements: typeof getPreviousConditionsElements;
|
566
|
+
executeActionAfterAnimation: typeof executeActionAfterAnimation;
|
567
|
+
getReactiveHandler: typeof getReactiveHandler;
|
568
|
+
mergeToNegativeCondition: typeof mergeToNegativeCondition;
|
569
|
+
fixeAttrName: typeof fixeAttrName;
|
570
|
+
getDomyAttributeInformations: typeof getDomyAttributeInformations;
|
571
|
+
isDomyAttr: typeof isDomyAttr;
|
572
|
+
isNormalAttr: typeof isNormalAttr;
|
573
|
+
isEventAttr: typeof isEventAttr;
|
574
|
+
isBindAttr: typeof isBindAttr;
|
575
|
+
isDNameAttr: typeof isDNameAttr;
|
576
|
+
warn: typeof warn;
|
577
|
+
error: typeof error;
|
578
|
+
};
|
579
|
+
type Observer = {
|
580
|
+
type: keyof AppState;
|
581
|
+
callback: () => void;
|
582
|
+
};
|
583
|
+
/**
|
584
|
+
* Register the current lifecycle state of the current app
|
585
|
+
*
|
586
|
+
* @author yoannchb-pro
|
587
|
+
*/
|
588
|
+
declare class AppStateObserver {
|
589
|
+
private observers;
|
590
|
+
private appState;
|
591
|
+
get isMounted(): boolean;
|
592
|
+
get isSetuped(): boolean;
|
593
|
+
get isUnmounted(): boolean;
|
594
|
+
set isMounted(newValue: boolean);
|
595
|
+
set isSetuped(newValue: boolean);
|
596
|
+
set isUnmounted(newValue: boolean);
|
597
|
+
private callObservers;
|
598
|
+
addObserver(observer: Observer): () => void;
|
599
|
+
removeObserver(observer: Observer): void;
|
600
|
+
}
|
601
|
+
type Transition = {
|
602
|
+
enterTransition: string;
|
603
|
+
enterTransitionTo: string;
|
604
|
+
outTransition: string;
|
605
|
+
outTransitionTo: string;
|
606
|
+
init: boolean;
|
607
|
+
};
|
608
|
+
type TransitionType = "enterTransition" | "outTransition";
|
609
|
+
/**
|
610
|
+
* Utilitary class to handle properly an element
|
611
|
+
*/
|
612
|
+
declare class Block {
|
613
|
+
private element;
|
614
|
+
name: string | null;
|
615
|
+
key: string | null;
|
616
|
+
private pluginsData;
|
617
|
+
transition: Transition | null;
|
618
|
+
private cleanupTransition;
|
619
|
+
private cleanups;
|
620
|
+
private onElChangeCbList;
|
621
|
+
parentBlock: Block | null;
|
622
|
+
constructor(element: Element | Block);
|
623
|
+
getDataForPluginId(pluginId: string): any;
|
624
|
+
setDataForPluginId(pluginId: string, data: any): void;
|
625
|
+
cleanTransition(): void;
|
626
|
+
private callCbForElementChange;
|
627
|
+
createNewElementBlock(): Block;
|
628
|
+
attachListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
629
|
+
onElementChange(cb: (newEl: Element) => void): void;
|
630
|
+
setEl(newEl: Element | Block): void;
|
631
|
+
getEl(): Element;
|
632
|
+
applyTransition(transitionType: TransitionType, action?: () => void): void;
|
633
|
+
replaceWith(newEl: Element | Block): void;
|
634
|
+
remove(): void;
|
635
|
+
isTemplate(): boolean;
|
636
|
+
isTextNode(): boolean;
|
637
|
+
addCleanup(cleanup: () => void): void;
|
638
|
+
unmount(): void;
|
639
|
+
}
|
640
|
+
type Props$2 = {
|
641
|
+
element: Element | Block;
|
642
|
+
scopedNodeData: Record<string, any>[];
|
643
|
+
byPassAttributes?: string[];
|
644
|
+
skipChildRendering?: boolean;
|
645
|
+
renderWithoutListeningToChange?: boolean;
|
646
|
+
};
|
647
|
+
/**
|
648
|
+
* Deep render an element (with the childs and textContent)
|
649
|
+
* It will keep the config for all the specified target only
|
650
|
+
* @param config
|
651
|
+
*
|
652
|
+
* @author yoannchb-pro
|
653
|
+
*/
|
654
|
+
declare function createDeepRenderFn(appId: number, appState: AppStateObserver, state: State, config: Config, components: Components, pluginHelper: PluginHelper): (props: Props$2) => Block;
|
655
|
+
type DomyDirectiveFn = (domy: DomyDirectiveHelper) => DomyDirectiveReturn;
|
656
|
+
type DomySpecialFn = (domy: DomySpecialHelper) => any;
|
657
|
+
type DomyDirectiveReturn = {
|
658
|
+
skipChildsRendering?: boolean;
|
659
|
+
skipOtherAttributesRendering?: boolean;
|
660
|
+
skipComponentRendering?: boolean;
|
661
|
+
} | void;
|
662
|
+
type DomySpecialHelper = {
|
663
|
+
domyHelperId?: number;
|
664
|
+
el?: Element | Text;
|
665
|
+
state: State;
|
666
|
+
scopedNodeData: Record<string, any>[];
|
667
|
+
config: Config;
|
668
|
+
utils: typeof helpersUtils;
|
669
|
+
} & typeof ReactiveUtils;
|
670
|
+
type DomyDirectiveHelper = {
|
671
|
+
domyHelperId: number;
|
672
|
+
pluginHelper: PluginHelper;
|
673
|
+
appState: AppStateObserver;
|
674
|
+
block: Block;
|
675
|
+
config: Config;
|
676
|
+
state: State;
|
677
|
+
scopedNodeData: Record<string, any>[];
|
678
|
+
prefix: string;
|
679
|
+
directive: string;
|
680
|
+
modifiers: string[];
|
681
|
+
attrName: string;
|
682
|
+
attr: {
|
683
|
+
name: string;
|
684
|
+
value: string;
|
685
|
+
};
|
686
|
+
utils: typeof directivesUtils;
|
687
|
+
onElementMounted(cb: () => void): void;
|
688
|
+
onAppMounted(cb: () => void): void;
|
689
|
+
getUniqueQueueId: typeof getUniqueQueueId;
|
690
|
+
queueJob: typeof queueJob;
|
691
|
+
effect(cb: () => void): (() => void) | void;
|
692
|
+
cleanup(cb: () => void): void;
|
693
|
+
evaluate(code: string, scope?: Record<string, any>): any;
|
694
|
+
deepRender: ReturnType<typeof createDeepRenderFn>;
|
695
|
+
addScopeToNode(obj: Record<string, any>): void;
|
696
|
+
removeScopeToNode(obj: Record<string, any>): void;
|
697
|
+
getContext: typeof getContext;
|
698
|
+
} & typeof ReactiveUtils;
|
699
|
+
type DomyPluginDefinition = {
|
700
|
+
prefix(name: string, fn: DomyDirectiveFn): void;
|
701
|
+
directive(name: string, fn: DomyDirectiveFn): void;
|
702
|
+
helper(name: string, fn: DomySpecialFn): void;
|
703
|
+
};
|
704
|
+
type DomyPlugin = (domy: DomyPluginDefinition) => void;
|
705
|
+
type PluginHelper = ReturnType<typeof createPluginRegistrer>;
|
706
|
+
type Plugins = {
|
707
|
+
prefixes: Record<string, DomyDirectiveFn>;
|
708
|
+
directives: Record<string, DomyDirectiveFn>;
|
709
|
+
helpers: Record<string, DomySpecialFn>;
|
710
|
+
};
|
711
|
+
/**
|
712
|
+
* Allow to register plugin for the current instance
|
713
|
+
* @returns
|
714
|
+
*
|
715
|
+
* @author yoannchb-pro
|
716
|
+
*/
|
717
|
+
declare function createPluginRegistrer(): {
|
718
|
+
PLUGINS: Plugins;
|
719
|
+
plugin: (pluginMaker: DomyPlugin) => void;
|
720
|
+
};
|
721
|
+
type ComponentInfos = {
|
722
|
+
componentData: {
|
723
|
+
$props: {
|
724
|
+
[key: string]: any;
|
725
|
+
};
|
726
|
+
$attrs: {
|
727
|
+
[key: string]: string;
|
728
|
+
};
|
729
|
+
};
|
730
|
+
childrens: Element[];
|
731
|
+
names: {
|
732
|
+
[name: string]: Element | undefined;
|
733
|
+
};
|
734
|
+
parentPluginHelper: PluginHelper;
|
735
|
+
};
|
736
|
+
type Component = (props: {
|
737
|
+
name: string;
|
738
|
+
componentElement: HTMLElement;
|
739
|
+
domy: DomyDirectiveHelper;
|
740
|
+
}) => void | (() => Element);
|
741
|
+
type Components = {
|
742
|
+
[name: string]: Component;
|
743
|
+
};
|
744
|
+
type CollapseSettings = {
|
745
|
+
defaultHeight?: number;
|
746
|
+
transition?: string;
|
747
|
+
};
|
748
|
+
declare const collapsePluginDefinition: (settings?: CollapseSettings) => DomyPlugin;
|
749
|
+
|
750
|
+
export { collapsePluginDefinition as default };
|
package/dist/index.js
ADDED
@@ -0,0 +1,2 @@
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).collapse=t()}(this,function(){"use strict";class e{constructor(e={}){this.defaultSettings=e}collapseSettingsPlugin(e){if(!e.block.getEl().getAttribute("d-collapse"))throw new Error('(Collapse) The "d-collapse" directive as to be placed after "d-collapse-settings" directive (and not before).');e.block.setDataForPluginId("collapse-settings",e.evaluate(e.attr.value))}collapsePlugin(e){var t;const l=e.block.getEl(),i=null!==(t=e.block.getDataForPluginId("collapse-settings"))&&void 0!==t?t:{},n=()=>l.style.height="auto";e.onElementMounted(()=>{let t=!1;l.style.overflowY="hidden",e.effect(()=>{var o,s;l.removeEventListener("transitionend",n);const a=e.evaluate(e.attr.value);l.style.transition="",l.style.height="auto";const d=l.getBoundingClientRect().height,r=null!==(s=null!==(o=i.defaultHeight)&&void 0!==o?o:this.defaultSettings.defaultHeight)&&void 0!==s?s:0;l.style.height=a?`${r}px`:`${d}px`,requestAnimationFrame(()=>{var e,o;t&&(l.style.transition=null!==(o=null!==(e=i.transition)&&void 0!==e?e:this.defaultSettings.transition)&&void 0!==o?o:"height 250ms ease-out"),a?(l.style.height=`${d}px`,l.addEventListener("transitionend",n)):l.style.height=`${r}px`,t=!0})})})}}return t=>{const l=new e(t);return e=>{e.directive("collapse",l.collapsePlugin.bind(l)),e.directive("collapse-settings",l.collapseSettingsPlugin.bind(l))}}});
|
2
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import type { DomyDirectiveHelper, DomyDirectiveReturn, DomyPlugin } from '@domyjs/domy';\r\n\r\ntype CollapseSettings = {\r\n defaultHeight?: number;\r\n transition?: string;\r\n};\r\n\r\nclass CollapsePlugin {\r\n constructor(private defaultSettings: CollapseSettings = {}) {}\r\n\r\n /**\r\n * Register collapse settings on the block\r\n * @param domy\r\n *\r\n * @author yoannchb-pro\r\n */\r\n collapseSettingsPlugin(domy: DomyDirectiveHelper): DomyDirectiveReturn {\r\n if (!domy.block.getEl().getAttribute('d-collapse'))\r\n throw new Error(\r\n `(Collapse) The \"d-collapse\" directive as to be placed after \"d-collapse-settings\" directive (and not before).`\r\n );\r\n\r\n domy.block.setDataForPluginId('collapse-settings', domy.evaluate(domy.attr.value));\r\n }\r\n\r\n /**\r\n * Collapse directive\r\n * It will hide the element by setting the height to 0px\r\n * When it have to be show the height will go back to normal height with a transition\r\n * @param domy\r\n * @returns\r\n *\r\n * @author yoannchb-pro\r\n */\r\n collapsePlugin(domy: DomyDirectiveHelper): DomyDirectiveReturn {\r\n const el = domy.block.getEl() as HTMLElement;\r\n const settings: CollapseSettings = domy.block.getDataForPluginId('collapse-settings') ?? {};\r\n const heightAutoEvent = () => (el.style.height = 'auto');\r\n\r\n // We wait the element to be mounted first to get his initial height\r\n domy.onElementMounted(() => {\r\n let isInitialised = false;\r\n el.style.overflowY = 'hidden';\r\n\r\n domy.effect(() => {\r\n el.removeEventListener('transitionend', heightAutoEvent);\r\n\r\n const shouldBeShow = domy.evaluate(domy.attr.value);\r\n\r\n el.style.transition = '';\r\n el.style.height = 'auto';\r\n const height = el.getBoundingClientRect().height;\r\n const defaultHeight = settings.defaultHeight ?? this.defaultSettings.defaultHeight ?? 0;\r\n el.style.height = shouldBeShow ? `${defaultHeight}px` : `${height}px`;\r\n\r\n requestAnimationFrame(() => {\r\n if (isInitialised)\r\n el.style.transition =\r\n settings.transition ?? this.defaultSettings.transition ?? 'height 250ms ease-out';\r\n\r\n if (shouldBeShow) {\r\n el.style.height = `${height}px`;\r\n el.addEventListener('transitionend', heightAutoEvent);\r\n } else {\r\n el.style.height = `${defaultHeight}px`;\r\n }\r\n\r\n isInitialised = true;\r\n });\r\n });\r\n });\r\n }\r\n}\r\n\r\nconst collapsePluginDefinition = (settings?: CollapseSettings) => {\r\n const collapseInstance = new CollapsePlugin(settings);\r\n const pluginSetter: DomyPlugin = domyPluginSetter => {\r\n domyPluginSetter.directive('collapse', collapseInstance.collapsePlugin.bind(collapseInstance));\r\n domyPluginSetter.directive(\r\n 'collapse-settings',\r\n collapseInstance.collapseSettingsPlugin.bind(collapseInstance)\r\n );\r\n };\r\n return pluginSetter;\r\n};\r\n\r\nexport default collapsePluginDefinition;\r\n"],"names":["CollapsePlugin","constructor","defaultSettings","this","collapseSettingsPlugin","domy","block","getEl","getAttribute","Error","setDataForPluginId","evaluate","attr","value","collapsePlugin","el","settings","_a","getDataForPluginId","heightAutoEvent","style","height","onElementMounted","isInitialised","overflowY","effect","removeEventListener","shouldBeShow","transition","getBoundingClientRect","defaultHeight","_b","requestAnimationFrame","addEventListener","collapseInstance","domyPluginSetter","directive","bind"],"mappings":"wOAOA,MAAMA,EACJ,WAAAC,CAAoBC,EAAoC,IAApCC,KAAAD,gBAAAA,EAQpB,sBAAAE,CAAuBC,GACrB,IAAKA,EAAKC,MAAMC,QAAQC,aAAa,cACnC,MAAM,IAAIC,MACR,iHAGJJ,EAAKC,MAAMI,mBAAmB,oBAAqBL,EAAKM,SAASN,EAAKO,KAAKC,QAY7E,cAAAC,CAAeT,SACb,MAAMU,EAAKV,EAAKC,MAAMC,QAChBS,EAA+E,QAAlDC,EAAAZ,EAAKC,MAAMY,mBAAmB,4BAAoB,IAAAD,EAAAA,EAAI,CAAA,EACnFE,EAAkB,IAAOJ,EAAGK,MAAMC,OAAS,OAGjDhB,EAAKiB,iBAAiB,KACpB,IAAIC,GAAgB,EACpBR,EAAGK,MAAMI,UAAY,SAErBnB,EAAKoB,OAAO,aACVV,EAAGW,oBAAoB,gBAAiBP,GAExC,MAAMQ,EAAetB,EAAKM,SAASN,EAAKO,KAAKC,OAE7CE,EAAGK,MAAMQ,WAAa,GACtBb,EAAGK,MAAMC,OAAS,OAClB,MAAMA,EAASN,EAAGc,wBAAwBR,OACpCS,EAA4E,QAA5DC,EAAsB,QAAtBd,EAAAD,EAASc,qBAAa,IAAAb,EAAAA,EAAId,KAAKD,gBAAgB4B,qBAAa,IAAAC,EAAAA,EAAI,EACtFhB,EAAGK,MAAMC,OAASM,EAAe,GAAGG,MAAoB,GAAGT,MAE3DW,sBAAsB,aAChBT,IACFR,EAAGK,MAAMQ,WAC+C,QAAtDG,EAAmB,QAAnBd,EAAAD,EAASY,kBAAU,IAAAX,EAAAA,EAAId,KAAKD,gBAAgB0B,kBAAU,IAAAG,EAAAA,EAAI,yBAE1DJ,GACFZ,EAAGK,MAAMC,OAAS,GAAGA,MACrBN,EAAGkB,iBAAiB,gBAAiBd,IAErCJ,EAAGK,MAAMC,OAAS,GAAGS,MAGvBP,GAAgB,gBAOQP,IAChC,MAAMkB,EAAmB,IAAIlC,EAAegB,GAQ5C,OAPiCmB,IAC/BA,EAAiBC,UAAU,WAAYF,EAAiBpB,eAAeuB,KAAKH,IAC5EC,EAAiBC,UACf,oBACAF,EAAiB9B,uBAAuBiC,KAAKH"}
|
package/package.json
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
{
|
2
|
+
"name": "@domyjs/collapse",
|
3
|
+
"unpkg": "./dist/index.js",
|
4
|
+
"version": "1.0.0",
|
5
|
+
"buildName": "collapse",
|
6
|
+
"description": "Domyjs collapse plugin",
|
7
|
+
"main": "./dist/index.js",
|
8
|
+
"types": "./dist/index.d.ts",
|
9
|
+
"files": [
|
10
|
+
"./dist",
|
11
|
+
"package.json",
|
12
|
+
"README.md"
|
13
|
+
],
|
14
|
+
"repository": {
|
15
|
+
"type": "git",
|
16
|
+
"url": "git+https://github.com/yoannchb-pro/domy.git"
|
17
|
+
},
|
18
|
+
"keywords": [
|
19
|
+
"domyjs",
|
20
|
+
"typescript",
|
21
|
+
"javascript",
|
22
|
+
"framework"
|
23
|
+
],
|
24
|
+
"author": "yoannchb",
|
25
|
+
"license": "MIT",
|
26
|
+
"bugs": {
|
27
|
+
"url": "https://github.com/yoannchb-pro/domy/issues"
|
28
|
+
},
|
29
|
+
"homepage": "https://domyjs.github.io/domy/docs/plugins/collapse"
|
30
|
+
}
|