@hyperfixi/behaviors 2.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/all.browser.global.js +116 -0
- package/dist/all.browser.global.js.map +1 -0
- package/dist/behaviors/draggable.cjs +109 -0
- package/dist/behaviors/draggable.cjs.map +1 -0
- package/dist/behaviors/draggable.d.cts +15 -0
- package/dist/behaviors/draggable.d.ts +15 -0
- package/dist/behaviors/draggable.js +14 -0
- package/dist/behaviors/draggable.js.map +1 -0
- package/dist/behaviors/removable.cjs +120 -0
- package/dist/behaviors/removable.cjs.map +1 -0
- package/dist/behaviors/removable.d.cts +15 -0
- package/dist/behaviors/removable.d.ts +15 -0
- package/dist/behaviors/removable.js +14 -0
- package/dist/behaviors/removable.js.map +1 -0
- package/dist/behaviors/resizable.cjs +146 -0
- package/dist/behaviors/resizable.cjs.map +1 -0
- package/dist/behaviors/resizable.d.cts +15 -0
- package/dist/behaviors/resizable.d.ts +15 -0
- package/dist/behaviors/resizable.js +14 -0
- package/dist/behaviors/resizable.js.map +1 -0
- package/dist/behaviors/sortable.cjs +119 -0
- package/dist/behaviors/sortable.cjs.map +1 -0
- package/dist/behaviors/sortable.d.cts +15 -0
- package/dist/behaviors/sortable.d.ts +15 -0
- package/dist/behaviors/sortable.js +14 -0
- package/dist/behaviors/sortable.js.map +1 -0
- package/dist/behaviors/toggleable.cjs +105 -0
- package/dist/behaviors/toggleable.cjs.map +1 -0
- package/dist/behaviors/toggleable.d.cts +15 -0
- package/dist/behaviors/toggleable.d.ts +15 -0
- package/dist/behaviors/toggleable.js +14 -0
- package/dist/behaviors/toggleable.js.map +1 -0
- package/dist/chunk-272NKUJ3.js +63 -0
- package/dist/chunk-272NKUJ3.js.map +1 -0
- package/dist/chunk-2NQHIHD5.js +37 -0
- package/dist/chunk-2NQHIHD5.js.map +1 -0
- package/dist/chunk-3DVDS7CT.js +170 -0
- package/dist/chunk-3DVDS7CT.js.map +1 -0
- package/dist/chunk-3Q652JQB.js +37 -0
- package/dist/chunk-3Q652JQB.js.map +1 -0
- package/dist/chunk-BWZ6EGII.js +62 -0
- package/dist/chunk-BWZ6EGII.js.map +1 -0
- package/dist/chunk-G6WR2AYR.js +52 -0
- package/dist/chunk-G6WR2AYR.js.map +1 -0
- package/dist/chunk-HMRPQWQU.js +37 -0
- package/dist/chunk-HMRPQWQU.js.map +1 -0
- package/dist/chunk-MEP6B7XW.js +37 -0
- package/dist/chunk-MEP6B7XW.js.map +1 -0
- package/dist/chunk-URBOGGW6.js +32 -0
- package/dist/chunk-URBOGGW6.js.map +1 -0
- package/dist/chunk-V5IWDPDP.js +89 -0
- package/dist/chunk-V5IWDPDP.js.map +1 -0
- package/dist/chunk-WU37DFAL.js +37 -0
- package/dist/chunk-WU37DFAL.js.map +1 -0
- package/dist/chunk-WUHHMDAA.js +48 -0
- package/dist/chunk-WUHHMDAA.js.map +1 -0
- package/dist/core.browser.global.js +39 -0
- package/dist/core.browser.global.js.map +1 -0
- package/dist/draggable.browser.global.js +25 -0
- package/dist/draggable.browser.global.js.map +1 -0
- package/dist/index.cjs +907 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +134 -0
- package/dist/index.d.ts +134 -0
- package/dist/index.js +193 -0
- package/dist/index.js.map +1 -0
- package/dist/loaders.cjs +562 -0
- package/dist/loaders.cjs.map +1 -0
- package/dist/loaders.d.cts +2 -0
- package/dist/loaders.d.ts +2 -0
- package/dist/loaders.js +8 -0
- package/dist/loaders.js.map +1 -0
- package/dist/registry.cjs +214 -0
- package/dist/registry.cjs.map +1 -0
- package/dist/registry.d.cts +116 -0
- package/dist/registry.d.ts +116 -0
- package/dist/registry.js +47 -0
- package/dist/registry.js.map +1 -0
- package/dist/removable.browser.global.js +23 -0
- package/dist/removable.browser.global.js.map +1 -0
- package/dist/resizable.browser.global.js +35 -0
- package/dist/resizable.browser.global.js.map +1 -0
- package/dist/schemas/index.cjs +353 -0
- package/dist/schemas/index.cjs.map +1 -0
- package/dist/schemas/index.d.cts +75 -0
- package/dist/schemas/index.d.ts +75 -0
- package/dist/schemas/index.js +41 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/sortable.browser.global.js +25 -0
- package/dist/sortable.browser.global.js.map +1 -0
- package/dist/toggleable.browser.global.js +16 -0
- package/dist/toggleable.browser.global.js.map +1 -0
- package/dist/types-CCc_2wAb.d.cts +100 -0
- package/dist/types-CCc_2wAb.d.ts +100 -0
- package/package.json +109 -0
- package/src/behaviors/draggable.ts +60 -0
- package/src/behaviors/index.ts +40 -0
- package/src/behaviors/integration.test.ts +80 -0
- package/src/behaviors/removable.ts +55 -0
- package/src/behaviors/resizable.ts +55 -0
- package/src/behaviors/sortable.ts +56 -0
- package/src/behaviors/toggleable.ts +55 -0
- package/src/core-bundle.ts +35 -0
- package/src/generated/index.ts +9 -0
- package/src/generated/metadata.ts +78 -0
- package/src/generated/types.ts +51 -0
- package/src/index.test.ts +180 -0
- package/src/index.ts +222 -0
- package/src/loaders.ts +39 -0
- package/src/registry.test.ts +207 -0
- package/src/registry.ts +304 -0
- package/src/schemas/draggable.schema.ts +54 -0
- package/src/schemas/index.ts +60 -0
- package/src/schemas/removable.schema.ts +69 -0
- package/src/schemas/resizable.schema.ts +91 -0
- package/src/schemas/sortable.schema.ts +68 -0
- package/src/schemas/toggleable.schema.ts +50 -0
- package/src/schemas/types.ts +107 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { BehaviorSchema } from './types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resizable Behavior Schema
|
|
5
|
+
*
|
|
6
|
+
* Makes elements resizable by dragging edges or corners.
|
|
7
|
+
* Supports minimum/maximum dimensions and resize handles.
|
|
8
|
+
*/
|
|
9
|
+
export const resizableSchema: BehaviorSchema = {
|
|
10
|
+
name: 'Resizable',
|
|
11
|
+
category: 'ui',
|
|
12
|
+
tier: 'optional',
|
|
13
|
+
version: '1.0.0',
|
|
14
|
+
description: 'Makes elements resizable by dragging',
|
|
15
|
+
parameters: [
|
|
16
|
+
{
|
|
17
|
+
name: 'handle',
|
|
18
|
+
type: 'selector',
|
|
19
|
+
optional: true,
|
|
20
|
+
default: 'me',
|
|
21
|
+
description: 'CSS selector for the resize handle (defaults to the element itself)',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'minWidth',
|
|
25
|
+
type: 'number',
|
|
26
|
+
optional: true,
|
|
27
|
+
default: 50,
|
|
28
|
+
description: 'Minimum width in pixels',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'minHeight',
|
|
32
|
+
type: 'number',
|
|
33
|
+
optional: true,
|
|
34
|
+
default: 50,
|
|
35
|
+
description: 'Minimum height in pixels',
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'maxWidth',
|
|
39
|
+
type: 'number',
|
|
40
|
+
optional: true,
|
|
41
|
+
default: 9999,
|
|
42
|
+
description: 'Maximum width in pixels',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'maxHeight',
|
|
46
|
+
type: 'number',
|
|
47
|
+
optional: true,
|
|
48
|
+
default: 9999,
|
|
49
|
+
description: 'Maximum height in pixels',
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
events: [
|
|
53
|
+
{ name: 'resizable:start', description: 'Fired when resize begins' },
|
|
54
|
+
{ name: 'resizable:resize', description: 'Fired during resize' },
|
|
55
|
+
{ name: 'resizable:end', description: 'Fired when resize completes' },
|
|
56
|
+
],
|
|
57
|
+
source: `
|
|
58
|
+
behavior Resizable(handle, minWidth, minHeight, maxWidth, maxHeight)
|
|
59
|
+
init
|
|
60
|
+
if no handle set handle to me
|
|
61
|
+
if no minWidth set minWidth to 50
|
|
62
|
+
if no minHeight set minHeight to 50
|
|
63
|
+
if no maxWidth set maxWidth to 9999
|
|
64
|
+
if no maxHeight set maxHeight to 9999
|
|
65
|
+
end
|
|
66
|
+
on pointerdown(clientX, clientY) from handle
|
|
67
|
+
halt the event
|
|
68
|
+
trigger resizable:start
|
|
69
|
+
measure width
|
|
70
|
+
set startWidth to it
|
|
71
|
+
measure height
|
|
72
|
+
set startHeight to it
|
|
73
|
+
set startX to clientX
|
|
74
|
+
set startY to clientY
|
|
75
|
+
repeat until event pointerup from document
|
|
76
|
+
wait for pointermove(clientX, clientY) or
|
|
77
|
+
pointerup from document
|
|
78
|
+
set newWidth to startWidth + (clientX - startX)
|
|
79
|
+
set newHeight to startHeight + (clientY - startY)
|
|
80
|
+
if newWidth < minWidth set newWidth to minWidth
|
|
81
|
+
if newWidth > maxWidth set newWidth to maxWidth
|
|
82
|
+
if newHeight < minHeight set newHeight to minHeight
|
|
83
|
+
if newHeight > maxHeight set newHeight to maxHeight
|
|
84
|
+
add { width: \${newWidth}px; height: \${newHeight}px; }
|
|
85
|
+
trigger resizable:resize
|
|
86
|
+
end
|
|
87
|
+
trigger resizable:end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
`.trim(),
|
|
91
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { BehaviorSchema } from './types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sortable Behavior Schema
|
|
5
|
+
*
|
|
6
|
+
* Drag-and-drop reordering of list items.
|
|
7
|
+
* Apply to a container element; children become sortable.
|
|
8
|
+
*
|
|
9
|
+
* Note: This behavior fires lifecycle events but does NOT automatically
|
|
10
|
+
* reorder DOM elements. Users must handle actual reordering in their
|
|
11
|
+
* `sortable:move` event handlers.
|
|
12
|
+
*/
|
|
13
|
+
export const sortableSchema: BehaviorSchema = {
|
|
14
|
+
name: 'Sortable',
|
|
15
|
+
category: 'ui',
|
|
16
|
+
tier: 'common',
|
|
17
|
+
version: '1.0.0',
|
|
18
|
+
description: 'Makes child elements reorderable via drag-and-drop',
|
|
19
|
+
parameters: [
|
|
20
|
+
{
|
|
21
|
+
name: 'handle',
|
|
22
|
+
type: 'selector',
|
|
23
|
+
optional: true,
|
|
24
|
+
default: 'none',
|
|
25
|
+
description: 'CSS selector for drag handles within items',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'dragClass',
|
|
29
|
+
type: 'string',
|
|
30
|
+
optional: true,
|
|
31
|
+
default: 'sorting',
|
|
32
|
+
description: 'CSS class added to item during drag',
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
events: [
|
|
36
|
+
{ name: 'sortable:start', description: 'Fired when drag begins' },
|
|
37
|
+
{
|
|
38
|
+
name: 'sortable:move',
|
|
39
|
+
description: 'Fired during drag — handle this event to reorder DOM elements',
|
|
40
|
+
},
|
|
41
|
+
{ name: 'sortable:end', description: 'Fired when drag completes' },
|
|
42
|
+
],
|
|
43
|
+
requirements: ['Users must handle DOM reordering in sortable:move event handlers'],
|
|
44
|
+
source: `
|
|
45
|
+
behavior Sortable(handle, dragClass)
|
|
46
|
+
init
|
|
47
|
+
if no dragClass set dragClass to "sorting"
|
|
48
|
+
end
|
|
49
|
+
on pointerdown(target, clientY) from me
|
|
50
|
+
set item to closest <li/> in target
|
|
51
|
+
if no item exit
|
|
52
|
+
if handle
|
|
53
|
+
set handleEl to target.closest(handle)
|
|
54
|
+
if no handleEl exit
|
|
55
|
+
end
|
|
56
|
+
halt the event
|
|
57
|
+
add dragClass to item
|
|
58
|
+
trigger sortable:start on me
|
|
59
|
+
repeat until event pointerup from document
|
|
60
|
+
wait for pointermove(clientY) from document
|
|
61
|
+
trigger sortable:move on me
|
|
62
|
+
end
|
|
63
|
+
remove dragClass from item
|
|
64
|
+
trigger sortable:end on me
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
`.trim(),
|
|
68
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { BehaviorSchema } from './types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Toggleable Behavior Schema
|
|
5
|
+
*
|
|
6
|
+
* Toggles a CSS class on click.
|
|
7
|
+
* Useful for accordions, dropdowns, and toggle buttons.
|
|
8
|
+
*/
|
|
9
|
+
export const toggleableSchema: BehaviorSchema = {
|
|
10
|
+
name: 'Toggleable',
|
|
11
|
+
category: 'form',
|
|
12
|
+
tier: 'core',
|
|
13
|
+
version: '1.0.0',
|
|
14
|
+
description: 'Toggles a CSS class on click',
|
|
15
|
+
parameters: [
|
|
16
|
+
{
|
|
17
|
+
name: 'cls',
|
|
18
|
+
type: 'string',
|
|
19
|
+
optional: true,
|
|
20
|
+
default: 'active',
|
|
21
|
+
description: 'CSS class to toggle',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'target',
|
|
25
|
+
type: 'selector',
|
|
26
|
+
optional: true,
|
|
27
|
+
default: 'me',
|
|
28
|
+
description: 'Element to toggle the class on',
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
events: [
|
|
32
|
+
{ name: 'toggleable:on', description: 'Fired when class is added' },
|
|
33
|
+
{ name: 'toggleable:off', description: 'Fired when class is removed' },
|
|
34
|
+
],
|
|
35
|
+
source: `
|
|
36
|
+
behavior Toggleable(cls, target)
|
|
37
|
+
init
|
|
38
|
+
if cls is undefined
|
|
39
|
+
set cls to "active"
|
|
40
|
+
end
|
|
41
|
+
if target is undefined
|
|
42
|
+
set target to me
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
on click
|
|
46
|
+
toggle .{cls} on target
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
`.trim(),
|
|
50
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Behavior Schema Types
|
|
3
|
+
*
|
|
4
|
+
* Defines the structure for behavior metadata used for:
|
|
5
|
+
* - Code generation (TypeScript types, documentation)
|
|
6
|
+
* - Runtime categorization and lazy loading
|
|
7
|
+
* - Tooling and IDE integration
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Behavior categories for organization.
|
|
12
|
+
* - ui: Visual interaction behaviors (drag, resize, sort)
|
|
13
|
+
* - data: Data manipulation behaviors (remove, transform)
|
|
14
|
+
* - animation: Animation and transition behaviors
|
|
15
|
+
* - form: Form-related behaviors (validation, toggle states)
|
|
16
|
+
* - layout: Layout behaviors (sticky, scrollspy)
|
|
17
|
+
*/
|
|
18
|
+
export type BehaviorCategory = 'ui' | 'data' | 'animation' | 'form' | 'layout';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Loading tiers for lazy loading optimization.
|
|
22
|
+
* - core: Always loaded (essential behaviors)
|
|
23
|
+
* - common: High usage (loaded for typical apps)
|
|
24
|
+
* - optional: Low usage (loaded on demand)
|
|
25
|
+
*/
|
|
26
|
+
export type BehaviorTier = 'core' | 'common' | 'optional';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Schema for a behavior parameter.
|
|
30
|
+
*/
|
|
31
|
+
export interface ParameterSchema {
|
|
32
|
+
name: string;
|
|
33
|
+
type: 'string' | 'number' | 'boolean' | 'selector' | 'element';
|
|
34
|
+
optional?: boolean;
|
|
35
|
+
default?: string | number | boolean;
|
|
36
|
+
/** Allowed values for constrained parameters */
|
|
37
|
+
enum?: string[];
|
|
38
|
+
description: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Schema for a behavior event.
|
|
43
|
+
*/
|
|
44
|
+
export interface EventSchema {
|
|
45
|
+
name: string;
|
|
46
|
+
description: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Complete schema for a behavior.
|
|
51
|
+
* This is the source of truth for all behavior metadata.
|
|
52
|
+
*/
|
|
53
|
+
export interface BehaviorSchema {
|
|
54
|
+
/** Behavior name (PascalCase) */
|
|
55
|
+
name: string;
|
|
56
|
+
/** Category for organization */
|
|
57
|
+
category: BehaviorCategory;
|
|
58
|
+
/** Loading tier for lazy loading */
|
|
59
|
+
tier: BehaviorTier;
|
|
60
|
+
/** Semantic version */
|
|
61
|
+
version: string;
|
|
62
|
+
/** Human-readable description */
|
|
63
|
+
description: string;
|
|
64
|
+
/** Parameter definitions */
|
|
65
|
+
parameters: ParameterSchema[];
|
|
66
|
+
/** Event definitions */
|
|
67
|
+
events: EventSchema[];
|
|
68
|
+
/** The hyperscript behavior source code */
|
|
69
|
+
source: string;
|
|
70
|
+
/** Optional requirements or notes */
|
|
71
|
+
requirements?: string[];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Runtime behavior module interface.
|
|
76
|
+
* This is what gets registered with the hyperfixi runtime.
|
|
77
|
+
*/
|
|
78
|
+
export interface BehaviorModule {
|
|
79
|
+
source: string;
|
|
80
|
+
metadata: BehaviorSchema;
|
|
81
|
+
register: (hyperfixi?: LokaScriptInstance) => Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Minimal LokaScript instance interface for behavior registration.
|
|
86
|
+
*/
|
|
87
|
+
export interface LokaScriptInstance {
|
|
88
|
+
compileSync: (
|
|
89
|
+
code: string,
|
|
90
|
+
options?: { traditional?: boolean; language?: string }
|
|
91
|
+
) => {
|
|
92
|
+
ok: boolean;
|
|
93
|
+
ast?: unknown;
|
|
94
|
+
errors?: Array<{ message: string; line?: number; column?: number }>;
|
|
95
|
+
};
|
|
96
|
+
execute: (ast: unknown, ctx: unknown) => Promise<unknown>;
|
|
97
|
+
createContext?: () => { locals: Map<string, unknown>; globals: Map<string, unknown> };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Typed window interface for behavior auto-registration.
|
|
102
|
+
* Avoids `(window as any)` casts throughout the codebase.
|
|
103
|
+
*/
|
|
104
|
+
export interface LokaScriptWindow {
|
|
105
|
+
lokascript?: LokaScriptInstance;
|
|
106
|
+
__lokascript_behaviors_ready?: Promise<void> | undefined;
|
|
107
|
+
}
|