assign-gingerly 0.0.65 → 0.0.67
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/DX/IterableMixin.js +49 -0
- package/DX/IterableMixin.ts +62 -0
- package/{installForwarding.js → DX/installForwarding.js} +2 -2
- package/{installForwarding.ts → DX/installForwarding.ts} +2 -2
- package/DX/paths.js +381 -0
- package/{paths.ts → DX/paths.ts} +1 -1
- package/README.md +43 -13
- package/assignFrom.js +3 -3
- package/assignFrom.ts +6 -5
- package/assignFromAsync.js +3 -3
- package/assignFromAsync.ts +5 -5
- package/assignGingerly.js +52 -10
- package/assignGingerly.ts +53 -10
- package/assignTentatively.js +8 -0
- package/assignTentatively.ts +6 -0
- package/{builtInEmoji.ts → emojis.js} +46 -34
- package/emojis.ts +52 -0
- package/getValues.js +0 -1
- package/getValues.ts +1 -1
- package/handlers/addEventListener.js +153 -0
- package/handlers/addEventListener.ts +178 -0
- package/handlers/lazyLoad.js +3 -3
- package/handlers/lazyLoad.ts +3 -3
- package/handlers/manageTemplateList.js +47 -20
- package/handlers/manageTemplateList.ts +50 -20
- package/index.js +1 -1
- package/index.ts +1 -1
- package/inferencer/types/assign-gingerly/types.d.ts +62 -4
- package/package.json +12 -7
- package/resolveIdRef.js +1 -1
- package/resolveIdRef.ts +1 -1
- package/types/assign-gingerly/types.d.ts +39 -23
- package/builtInEmoji.js +0 -26
- package/paths.js +0 -231
- /package/{pinCorrector.js → DX/pinCorrector.js} +0 -0
- /package/{pinCorrector.ts → DX/pinCorrector.ts} +0 -0
|
@@ -745,11 +745,11 @@ export interface LazyLoadResolvedParams {
|
|
|
745
745
|
* Used for SSR placeholder content (e.g., "Loading..." text) that disappears once real content loads. */
|
|
746
746
|
placeholder?: string;
|
|
747
747
|
/** Assignment config applied to cloned content before insertion.
|
|
748
|
-
* Same shape as manageTemplateList's fromEachItem: {
|
|
748
|
+
* Same shape as manageTemplateList's fromEachItem: { toClone, withOptions } or { configs: [...] } */
|
|
749
749
|
assign?: {
|
|
750
|
-
|
|
750
|
+
toClone?: Record<string, any>;
|
|
751
751
|
withOptions?: Record<string, any>;
|
|
752
|
-
configs?: Array<{
|
|
752
|
+
configs?: Array<{ toClone?: Record<string, any>; withOptions?: Record<string, any> }>;
|
|
753
753
|
};
|
|
754
754
|
}
|
|
755
755
|
|
|
@@ -795,7 +795,7 @@ export interface LazyLoadSwitchResolvedParams extends Omit<LazyLoadResolvedParam
|
|
|
795
795
|
}
|
|
796
796
|
|
|
797
797
|
export interface FromEachItemConfig {
|
|
798
|
-
|
|
798
|
+
toClone?: Record<string, any>;
|
|
799
799
|
withOptions?: AssignFromOptions;
|
|
800
800
|
resolve?: {
|
|
801
801
|
key?: string;
|
|
@@ -854,28 +854,44 @@ export declare class LazyLoadHandler implements AssignFromHandler {
|
|
|
854
854
|
|
|
855
855
|
//#region Event Handler
|
|
856
856
|
|
|
857
|
-
export interface
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
857
|
+
export interface AssignDispatchVector {
|
|
858
|
+
toTarget?: Record<string, any>,
|
|
859
|
+
toHost?: Record<string, any>,
|
|
860
|
+
toLHS?: Record<string, any>,
|
|
861
861
|
withOptions?: AssignFromOptions,
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
export interface
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
862
|
+
toTargetOptions?: AssignFromOptions,
|
|
863
|
+
toHostOptions?: AssignFromOptions,
|
|
864
|
+
toLHSOptions?: AssignFromOptions,
|
|
865
|
+
dispatch?: DispatchEventConfig
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
export interface DispatchEventConfig{
|
|
869
|
+
type?: string,
|
|
870
|
+
eventCtr?: string | typeof Event | typeof CustomEvent,
|
|
871
|
+
detail?: any,
|
|
872
|
+
bubbles?: boolean,
|
|
873
|
+
cancelable?: boolean,
|
|
874
|
+
composed?: boolean
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
|
|
878
|
+
export interface AddEventListenerConfig extends AssignDispatchVector {
|
|
879
|
+
on: string,
|
|
880
|
+
get?: {
|
|
881
|
+
abortController?: string | AbortController,
|
|
882
|
+
|
|
883
|
+
nudge?: boolean,
|
|
884
|
+
options?: AddEventListenerOptions,
|
|
885
|
+
//make this part of dispatch?
|
|
886
|
+
stopPropagation?: boolean,
|
|
887
|
+
preventDefault?: boolean
|
|
888
|
+
dispatch?: DispatchEventConfig
|
|
874
889
|
},
|
|
875
890
|
|
|
876
|
-
fromLHS?:
|
|
877
|
-
|
|
878
|
-
fromEvent?:
|
|
891
|
+
fromLHS?: AssignDispatchVector,
|
|
892
|
+
fromHost?: AssignDispatchVector,
|
|
893
|
+
fromEvent?: AssignDispatchVector,
|
|
894
|
+
fromTarget?: AssignDispatchVector,
|
|
879
895
|
|
|
880
896
|
|
|
881
897
|
}
|
package/builtInEmoji.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* builtInEmoji.js — Predefined emoji aliases for built-in handlers.
|
|
3
|
-
*
|
|
4
|
-
* Import and spread into the `handlers` option for concise handler configs:
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* import { builtInEmoji } from 'assign-gingerly/builtInEmoji.js';
|
|
8
|
-
*
|
|
9
|
-
* assignFrom(target, {
|
|
10
|
-
* '?.el =>': { do: '🔗', get: { value: ['?.first', ' ', '?.last'] } }
|
|
11
|
-
* }, { from: vm, handlers: builtInEmoji });
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Emoji → built-in handler name mapping.
|
|
16
|
-
*/
|
|
17
|
-
export const builtInEmoji = {
|
|
18
|
-
'📦': 'builtIns.lazyLoad',
|
|
19
|
-
'🎚️': 'builtIns.lazyLoadSwitch',
|
|
20
|
-
'🔗': 'builtIns.join',
|
|
21
|
-
'🏷️': 'builtIns.microDataJoin',
|
|
22
|
-
'📋': 'builtIns.manageTemplateList',
|
|
23
|
-
'📊': 'builtIns.rangeSelector',
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export default builtInEmoji;
|
package/paths.js
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* paths.js — Typed path proxy and template tags for assignFrom authoring.
|
|
3
|
-
*
|
|
4
|
-
* Provides compile-time autocomplete and type safety for `?.`-prefixed path strings.
|
|
5
|
-
* Supports method call syntax, alias reversal, and batch proxy extraction.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Symbol used internally to detect path proxy objects.
|
|
10
|
-
*/
|
|
11
|
-
const PATH_SYMBOL = Symbol('assign-gingerly-path');
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Create a proxy for id-ref paths (#[varName]).
|
|
15
|
-
*/
|
|
16
|
-
function createIdRefProxy(idRef, options) {
|
|
17
|
-
function handler() {}
|
|
18
|
-
return new Proxy(handler, {
|
|
19
|
-
get(_, prop) {
|
|
20
|
-
if (prop === 'path' || prop === PATH_SYMBOL) {
|
|
21
|
-
return idRef;
|
|
22
|
-
}
|
|
23
|
-
if (typeof prop === 'symbol') return undefined;
|
|
24
|
-
const chained = `${idRef}?.${String(prop)}`;
|
|
25
|
-
return createIdRefProxy(chained, options);
|
|
26
|
-
},
|
|
27
|
-
apply(_, __, args) {
|
|
28
|
-
if (args.length > 0) {
|
|
29
|
-
const arg = args[0];
|
|
30
|
-
let argStr;
|
|
31
|
-
if (arg === true) argStr = 'true';
|
|
32
|
-
else if (arg === false) argStr = 'false';
|
|
33
|
-
else if (arg && typeof arg === 'object' && PATH_SYMBOL in arg) {
|
|
34
|
-
const fullPath = arg[PATH_SYMBOL];
|
|
35
|
-
argStr = fullPath.startsWith('?.') ? fullPath.substring(2) : fullPath;
|
|
36
|
-
}
|
|
37
|
-
else argStr = String(arg);
|
|
38
|
-
const chained = `${idRef}?.${argStr}`;
|
|
39
|
-
return createIdRefProxy(chained, options);
|
|
40
|
-
}
|
|
41
|
-
return createIdRefProxy(idRef, options);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Create a recursive proxy that records property access paths.
|
|
48
|
-
*/
|
|
49
|
-
function createPathProxy(prefix, options) {
|
|
50
|
-
const aliasMap = options?.aka;
|
|
51
|
-
|
|
52
|
-
function handler() {}
|
|
53
|
-
|
|
54
|
-
return new Proxy(handler, {
|
|
55
|
-
get(_, prop) {
|
|
56
|
-
if (prop === 'path' || prop === PATH_SYMBOL) {
|
|
57
|
-
return prefix.length > 0 ? `?.${prefix}` : '?.';
|
|
58
|
-
}
|
|
59
|
-
if (typeof prop === 'symbol') return undefined;
|
|
60
|
-
|
|
61
|
-
let segment = String(prop);
|
|
62
|
-
|
|
63
|
-
// #-prefix: $['#firstName'] → '#[firstName]' (cached element ref)
|
|
64
|
-
if (segment.startsWith('#')) {
|
|
65
|
-
const varName = segment.substring(1);
|
|
66
|
-
const idRef = `#[${varName}]`;
|
|
67
|
-
return createIdRefProxy(idRef, options);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (aliasMap) {
|
|
71
|
-
for (const [alias, target] of Object.entries(aliasMap)) {
|
|
72
|
-
if (target === segment) { segment = alias; break; }
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const newPath = prefix ? `${prefix}?.${segment}` : segment;
|
|
77
|
-
return createPathProxy(newPath, options);
|
|
78
|
-
},
|
|
79
|
-
apply(_, __, args) {
|
|
80
|
-
if (args.length > 0) {
|
|
81
|
-
const arg = args[0];
|
|
82
|
-
let argStr;
|
|
83
|
-
if (arg === true) argStr = 'true';
|
|
84
|
-
else if (arg === false) argStr = 'false';
|
|
85
|
-
else if (arg && typeof arg === 'object' && PATH_SYMBOL in arg) {
|
|
86
|
-
const fullPath = arg[PATH_SYMBOL];
|
|
87
|
-
argStr = fullPath.startsWith('?.') ? fullPath.substring(2) : fullPath;
|
|
88
|
-
}
|
|
89
|
-
else argStr = String(arg);
|
|
90
|
-
|
|
91
|
-
const newPath = prefix ? `${prefix}?.${argStr}` : argStr;
|
|
92
|
-
return createPathProxy(newPath, options);
|
|
93
|
-
}
|
|
94
|
-
return createPathProxy(prefix, options);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Create a typed path proxy.
|
|
101
|
-
*/
|
|
102
|
-
export function paths(options) {
|
|
103
|
-
return createPathProxy('', options);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Create an assignment pair: { [lhs.path]: rhs.path }.
|
|
108
|
-
*/
|
|
109
|
-
export function set(lhs) {
|
|
110
|
-
const lhsStr = lhs && typeof lhs === 'object' && PATH_SYMBOL in lhs
|
|
111
|
-
? lhs[PATH_SYMBOL]
|
|
112
|
-
: String(lhs);
|
|
113
|
-
return {
|
|
114
|
-
to(rhs) {
|
|
115
|
-
const rhsStr = rhs && typeof rhs === 'object' && PATH_SYMBOL in rhs
|
|
116
|
-
? rhs[PATH_SYMBOL]
|
|
117
|
-
: rhs;
|
|
118
|
-
return { [lhsStr]: rhsStr };
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Recursively walk a value and convert any path proxy objects to path strings.
|
|
125
|
-
*/
|
|
126
|
-
export function smoothOver(value) {
|
|
127
|
-
if (value && typeof value === 'object' && PATH_SYMBOL in value) {
|
|
128
|
-
return value[PATH_SYMBOL];
|
|
129
|
-
}
|
|
130
|
-
if (Array.isArray(value)) {
|
|
131
|
-
return value.map(smoothOver);
|
|
132
|
-
}
|
|
133
|
-
if (value && typeof value === 'object') {
|
|
134
|
-
const proto = Object.getPrototypeOf(value);
|
|
135
|
-
if (proto === Object.prototype || proto === null) {
|
|
136
|
-
const result = {};
|
|
137
|
-
for (const [k, v] of Object.entries(value)) {
|
|
138
|
-
result[k] = smoothOver(v);
|
|
139
|
-
}
|
|
140
|
-
return result;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return value;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Merge multiple set(...).to(...) pairs into an { assign: {...} } object.
|
|
148
|
-
* Spread the result into a merge config.
|
|
149
|
-
*/
|
|
150
|
-
export function doAssign(...pairs) {
|
|
151
|
-
return { assign: Object.assign({}, ...pairs) };
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Compile-time loop expansion: generates one entry per key from a factory function.
|
|
156
|
-
*/
|
|
157
|
-
export function forEachKeyIn(keys, factory, options) {
|
|
158
|
-
const $ = paths(options);
|
|
159
|
-
return keys.map(key => factory(key, $));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Tagged template literal that splits a template into an array of parts.
|
|
164
|
-
* Path proxy objects are auto-detected and converted to path strings.
|
|
165
|
-
*/
|
|
166
|
-
export function sp(strings, ...values) {
|
|
167
|
-
const result = [];
|
|
168
|
-
for (let i = 0; i < strings.length; i++) {
|
|
169
|
-
if (strings[i]) result.push(strings[i]);
|
|
170
|
-
if (i < values.length) {
|
|
171
|
-
const v = values[i];
|
|
172
|
-
if (v && typeof v === 'object' && PATH_SYMBOL in v) {
|
|
173
|
-
result.push(v[PATH_SYMBOL]);
|
|
174
|
-
}
|
|
175
|
-
else if (Array.isArray(v)) {
|
|
176
|
-
result.push(v.map(el =>
|
|
177
|
-
el && typeof el === 'object' && PATH_SYMBOL in el ? el[PATH_SYMBOL] : el
|
|
178
|
-
));
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
result.push(v);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return result;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Extract the last segment from a `?.`-prefixed path string.
|
|
190
|
-
*/
|
|
191
|
-
function extractPropName(pathStr) {
|
|
192
|
-
const parts = pathStr.split('?.');
|
|
193
|
-
return parts[parts.length - 1];
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Tagged template literal that produces {prop, val} objects for microDataJoin.
|
|
198
|
-
*/
|
|
199
|
-
export function md(strings, ...values) {
|
|
200
|
-
const result = [];
|
|
201
|
-
for (let i = 0; i < strings.length; i++) {
|
|
202
|
-
if (strings[i]) result.push(strings[i]);
|
|
203
|
-
if (i < values.length) {
|
|
204
|
-
const v = values[i];
|
|
205
|
-
if (v && typeof v === 'object' && PATH_SYMBOL in v) {
|
|
206
|
-
const pathStr = v[PATH_SYMBOL];
|
|
207
|
-
result.push({ prop: extractPropName(pathStr), val: pathStr });
|
|
208
|
-
}
|
|
209
|
-
else if (Array.isArray(v)) {
|
|
210
|
-
result.push(v.map(el => {
|
|
211
|
-
if (el && typeof el === 'object' && PATH_SYMBOL in el) {
|
|
212
|
-
const pathStr = el[PATH_SYMBOL];
|
|
213
|
-
return { prop: extractPropName(pathStr), val: pathStr };
|
|
214
|
-
}
|
|
215
|
-
return el;
|
|
216
|
-
}));
|
|
217
|
-
}
|
|
218
|
-
else if (v && typeof v === 'object' && 'prop' in v) {
|
|
219
|
-
const processed = { ...v };
|
|
220
|
-
if (processed.val && typeof processed.val === 'object' && PATH_SYMBOL in processed.val) {
|
|
221
|
-
processed.val = processed.val[PATH_SYMBOL];
|
|
222
|
-
}
|
|
223
|
-
result.push(processed);
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
result.push(v);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
return result;
|
|
231
|
-
}
|
|
File without changes
|
|
File without changes
|