ember-primitives 0.13.0 → 0.14.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/declarations/components/-private/utils.d.ts +1 -1
- package/declarations/components/-private/utils.d.ts.map +1 -1
- package/declarations/components/toggle-group.d.ts +88 -6
- package/declarations/components/toggle-group.d.ts.map +1 -1
- package/declarations/components/toggle.d.ts +1 -1
- package/declarations/components/toggle.d.ts.map +1 -1
- package/dist/components/-private/utils.js +3 -1
- package/dist/components/-private/utils.js.map +1 -1
- package/dist/components/toggle-group.js +64 -9
- package/dist/components/toggle-group.js.map +1 -1
- package/dist/components/toggle.js +1 -0
- package/dist/components/toggle.js.map +1 -1
- package/package.json +2 -1
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* If the user provides an onChange or similar function, use that,
|
|
3
3
|
* otherwise fallback to the uncontrolled toggle
|
|
4
4
|
*/
|
|
5
|
-
export declare function toggleWithFallback(uncontrolledToggle: (...args: unknown[]) => void, controlledToggle?: (...args:
|
|
5
|
+
export declare function toggleWithFallback(uncontrolledToggle: (...args: unknown[]) => void, controlledToggle?: (...args: any[]) => void, ...args: unknown[]): void;
|
|
6
6
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/-private/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,kBAAkB,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/-private/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,kBAAkB,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,EAEhD,gBAAgB,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,EAC3C,GAAG,IAAI,EAAE,OAAO,EAAE,QAOnB"}
|
|
@@ -25,7 +25,7 @@ export interface ItemSignature<Value = any> {
|
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
export type Item<Value = any> = ComponentLike<ItemSignature<Value>>;
|
|
28
|
-
export
|
|
28
|
+
export interface SingleSignature<Value> {
|
|
29
29
|
Element: HTMLDivElement;
|
|
30
30
|
Args: {
|
|
31
31
|
/**
|
|
@@ -40,18 +40,100 @@ export declare class ToggleGroup<Value = any> extends Component<{
|
|
|
40
40
|
*
|
|
41
41
|
* When none of the toggles are selected, undefined will be passed.
|
|
42
42
|
*/
|
|
43
|
-
onChange
|
|
43
|
+
onChange?: (value: Value | undefined) => void;
|
|
44
44
|
};
|
|
45
45
|
Blocks: {
|
|
46
46
|
default: [
|
|
47
47
|
{
|
|
48
|
+
/**
|
|
49
|
+
* The Toggle Switch
|
|
50
|
+
*/
|
|
48
51
|
Item: Item;
|
|
49
52
|
}
|
|
50
53
|
];
|
|
51
54
|
};
|
|
52
|
-
}> {
|
|
53
|
-
activePressed?: Value;
|
|
54
|
-
handleToggle: (value: Value) => void;
|
|
55
|
-
isPressed: (value: Value | undefined) => boolean;
|
|
56
55
|
}
|
|
56
|
+
export interface MultiSignature<Value = any> {
|
|
57
|
+
Element: HTMLDivElement;
|
|
58
|
+
Args: {
|
|
59
|
+
/**
|
|
60
|
+
* Optionally set the initial toggle state
|
|
61
|
+
*/
|
|
62
|
+
value?: Value[] | Set<Value> | Value;
|
|
63
|
+
/**
|
|
64
|
+
* Callback for when the toggle-group's state is changed.
|
|
65
|
+
*
|
|
66
|
+
* Can be used to control the state of the component.
|
|
67
|
+
*
|
|
68
|
+
*
|
|
69
|
+
* When none of the toggles are selected, undefined will be passed.
|
|
70
|
+
*/
|
|
71
|
+
onChange?: (value: Set<Value>) => void;
|
|
72
|
+
};
|
|
73
|
+
Blocks: {
|
|
74
|
+
default: [
|
|
75
|
+
{
|
|
76
|
+
/**
|
|
77
|
+
* The Toggle Switch
|
|
78
|
+
*/
|
|
79
|
+
Item: Item;
|
|
80
|
+
}
|
|
81
|
+
];
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
interface PrivateSingleSignature<Value = any> {
|
|
85
|
+
Element: HTMLDivElement;
|
|
86
|
+
Args: {
|
|
87
|
+
type?: 'single';
|
|
88
|
+
/**
|
|
89
|
+
* Optionally set the initial toggle state
|
|
90
|
+
*/
|
|
91
|
+
value?: Value;
|
|
92
|
+
/**
|
|
93
|
+
* Callback for when the toggle-group's state is changed.
|
|
94
|
+
*
|
|
95
|
+
* Can be used to control the state of the component.
|
|
96
|
+
*
|
|
97
|
+
*
|
|
98
|
+
* When none of the toggles are selected, undefined will be passed.
|
|
99
|
+
*/
|
|
100
|
+
onChange?: (value: Value | undefined) => void;
|
|
101
|
+
};
|
|
102
|
+
Blocks: {
|
|
103
|
+
default: [
|
|
104
|
+
{
|
|
105
|
+
Item: Item;
|
|
106
|
+
}
|
|
107
|
+
];
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
interface PrivateMultiSignature<Value = any> {
|
|
111
|
+
Element: HTMLDivElement;
|
|
112
|
+
Args: {
|
|
113
|
+
type: 'multi';
|
|
114
|
+
/**
|
|
115
|
+
* Optionally set the initial toggle state
|
|
116
|
+
*/
|
|
117
|
+
value?: Value[] | Set<Value> | Value;
|
|
118
|
+
/**
|
|
119
|
+
* Callback for when the toggle-group's state is changed.
|
|
120
|
+
*
|
|
121
|
+
* Can be used to control the state of the component.
|
|
122
|
+
*
|
|
123
|
+
*
|
|
124
|
+
* When none of the toggles are selected, undefined will be passed.
|
|
125
|
+
*/
|
|
126
|
+
onChange?: (value: Set<Value>) => void;
|
|
127
|
+
};
|
|
128
|
+
Blocks: {
|
|
129
|
+
default: [
|
|
130
|
+
{
|
|
131
|
+
Item: Item;
|
|
132
|
+
}
|
|
133
|
+
];
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
export declare class ToggleGroup<Value = any> extends Component<PrivateSingleSignature<Value> | PrivateMultiSignature<Value>> {
|
|
137
|
+
}
|
|
138
|
+
export {};
|
|
57
139
|
//# sourceMappingURL=toggle-group.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-group.d.ts","sourceRoot":"","sources":["../../src/components/toggle-group.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"toggle-group.d.ts","sourceRoot":"","sources":["../../src/components/toggle-group.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAc3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AASrD,MAAM,WAAW,aAAa,CAAC,KAAK,GAAG,GAAG;IACxC;;OAEG;IACH,OAAO,EAAE,iBAAiB,CAAC;IAC3B,IAAI,EAAE;QACJ;;;;WAIG;QACH,KAAK,CAAC,EAAE,KAAK,CAAC;KACf,CAAC;IACF,MAAM,EAAE;QACN,OAAO,EAAE;YACP;;;;eAIG;YACH,OAAO,EAAE,OAAO;SACjB,CAAC;KACH,CAAC;CACH;AAED,MAAM,MAAM,IAAI,CAAC,KAAK,GAAG,GAAG,IAAI,aAAa,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;AAEpE,MAAM,WAAW,eAAe,CAAC,KAAK;IACpC,OAAO,EAAE,cAAc,CAAC;IACxB,IAAI,EAAE;QACJ;;WAEG;QACH,KAAK,CAAC,EAAE,KAAK,CAAC;QACd;;;;;;;WAOG;QACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,KAAK,IAAI,CAAC;KAC/C,CAAC;IACF,MAAM,EAAE;QACN,OAAO,EAAE;YACP;gBACE;;mBAEG;gBACH,IAAI,EAAE,IAAI,CAAC;aACZ;SACF,CAAC;KACH,CAAC;CACH;AAED,MAAM,WAAW,cAAc,CAAC,KAAK,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AC,KAAK,GAAG,GAAG,CAAE,SAAQ,SAAS,CACrD,sBAAsB,CAAC,KAAK,CAAC,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAC7D;CA0BA"}
|
|
@@ -19,7 +19,7 @@ export interface Signature<Value = any> {
|
|
|
19
19
|
* This can be useful when using the same function for the `@onChange`
|
|
20
20
|
* handler with multiple `<Toggle>` components.
|
|
21
21
|
*/
|
|
22
|
-
onChange?: (value
|
|
22
|
+
onChange?: (value: Value | undefined, pressed: boolean) => void;
|
|
23
23
|
/**
|
|
24
24
|
* When used in a group of Toggles, this option will be helpful to
|
|
25
25
|
* know which toggle was pressed if you're using the same @onChange
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle.d.ts","sourceRoot":"","sources":["../../src/components/toggle.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"toggle.d.ts","sourceRoot":"","sources":["../../src/components/toggle.ts"],"names":[],"mappings":";AAQA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gCAAgC,CAAC;AAG1D,MAAM,WAAW,SAAS,CAAC,KAAK,GAAG,GAAG;IACpC,OAAO,EAAE,iBAAiB,CAAC;IAC3B,IAAI,EAAE;QACJ;;;;WAIG;QACH,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB;;;;;;;;;;WAUG;QACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;QAEhE;;;;WAIG;QACH,KAAK,CAAC,EAAE,KAAK,CAAC;QAEd;;WAEG;QACH,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,KAAK,OAAO,CAAC;KACpD,CAAC;IACF,MAAM,EAAE;QACN,OAAO,EAAE;YACP;;;;eAIG;YACH,OAAO,EAAE,OAAO;SACjB,CAAC;KACH,CAAC;CACH;AAaD,eAAO,MAAM,MAAM,EAAE,GAAG,CAAC,SAAS,CAmBhC,CAAC;AAEH,eAAe,MAAM,CAAC"}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* If the user provides an onChange or similar function, use that,
|
|
3
3
|
* otherwise fallback to the uncontrolled toggle
|
|
4
4
|
*/
|
|
5
|
-
function toggleWithFallback(uncontrolledToggle,
|
|
5
|
+
function toggleWithFallback(uncontrolledToggle,
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
controlledToggle, ...args) {
|
|
6
8
|
if (controlledToggle) {
|
|
7
9
|
return controlledToggle(...args);
|
|
8
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../src/components/-private/utils.ts"],"sourcesContent":["/**\n * If the user provides an onChange or similar function, use that,\n * otherwise fallback to the uncontrolled toggle\n */\nexport function toggleWithFallback(\n uncontrolledToggle: (...args: unknown[]) => void,\n controlledToggle?: (...args:
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../src/components/-private/utils.ts"],"sourcesContent":["/**\n * If the user provides an onChange or similar function, use that,\n * otherwise fallback to the uncontrolled toggle\n */\nexport function toggleWithFallback(\n uncontrolledToggle: (...args: unknown[]) => void,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n controlledToggle?: (...args: any[]) => void,\n ...args: unknown[]\n) {\n if (controlledToggle) {\n return controlledToggle(...args);\n }\n\n uncontrolledToggle(...args);\n}\n"],"names":["toggleWithFallback","uncontrolledToggle","controlledToggle","args"],"mappings":"AAAA;AACA;AACA;AACA;AACO,SAASA,kBAAkBA,CAChCC,kBAAgD;AAChD;AACAC,gBAA2C,EAC3C,GAAGC,IAAe,EAClB;AACA,EAAA,IAAID,gBAAgB,EAAE;AACpB,IAAA,OAAOA,gBAAgB,CAAC,GAAGC,IAAI,CAAC,CAAA;AAClC,GAAA;EAEAF,kBAAkB,CAAC,GAAGE,IAAI,CAAC,CAAA;AAC7B;;;;"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import Component from '@glimmer/component';
|
|
2
|
+
import { cached } from '@glimmer/tracking';
|
|
2
3
|
import { Types } from 'tabster';
|
|
4
|
+
import { TrackedSet } from 'tracked-built-ins';
|
|
3
5
|
import { localCopy } from 'tracked-toolbox';
|
|
4
|
-
import { g, i } from 'decorator-transforms/runtime';
|
|
5
|
-
import { hash } from '@ember/helper';
|
|
6
|
-
import { Toggle } from './toggle.js';
|
|
7
6
|
import { precompileTemplate } from '@ember/template-compilation';
|
|
8
7
|
import { setComponentTemplate } from '@ember/component';
|
|
8
|
+
import { g, i, n } from 'decorator-transforms/runtime';
|
|
9
|
+
import { hash } from '@ember/helper';
|
|
10
|
+
import { Toggle } from './toggle.js';
|
|
9
11
|
|
|
10
12
|
const TABSTER_CONFIG = JSON.stringify({
|
|
11
13
|
mover: {
|
|
@@ -13,12 +15,23 @@ const TABSTER_CONFIG = JSON.stringify({
|
|
|
13
15
|
cyclic: true
|
|
14
16
|
}
|
|
15
17
|
});
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
function isMulti(x1) {
|
|
19
|
+
return x1 === 'multi';
|
|
20
|
+
}
|
|
21
21
|
class ToggleGroup extends Component {
|
|
22
|
+
// See: https://github.com/typed-ember/glint/issues/715
|
|
23
|
+
static {
|
|
24
|
+
setComponentTemplate(precompileTemplate("\n {{#if (isMulti this.args.type)}}\n <MultiToggleGroup @value={{this.args.value}} @onChange={{this.args.onChange}} ...attributes as |x|>\n {{yield x}}\n </MultiToggleGroup>\n {{else}}\n <SingleToggleGroup @value={{this.args.value}} @onChange={{this.args.onChange}} ...attributes as |x|>\n {{yield x}}\n </SingleToggleGroup>\n {{/if}}\n ", {
|
|
25
|
+
scope: () => ({
|
|
26
|
+
isMulti,
|
|
27
|
+
MultiToggleGroup,
|
|
28
|
+
SingleToggleGroup
|
|
29
|
+
}),
|
|
30
|
+
strictMode: true
|
|
31
|
+
}), this);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
let SingleToggleGroup = class SingleToggleGroup extends Component {
|
|
22
35
|
static {
|
|
23
36
|
g(this.prototype, "activePressed", [localCopy('args.value')]);
|
|
24
37
|
}
|
|
@@ -42,7 +55,49 @@ class ToggleGroup extends Component {
|
|
|
42
55
|
strictMode: true
|
|
43
56
|
}), this);
|
|
44
57
|
}
|
|
45
|
-
}
|
|
58
|
+
};
|
|
59
|
+
let MultiToggleGroup = class MultiToggleGroup extends Component {
|
|
60
|
+
/**
|
|
61
|
+
* Normalizes @value to a Set
|
|
62
|
+
* and makes sure that even if the input Set is reactive,
|
|
63
|
+
* we don't mistakenly dirty it.
|
|
64
|
+
*/
|
|
65
|
+
get activePressed() {
|
|
66
|
+
let value1 = this.args.value;
|
|
67
|
+
if (!value1) {
|
|
68
|
+
return new TrackedSet();
|
|
69
|
+
}
|
|
70
|
+
if (Array.isArray(value1)) {
|
|
71
|
+
return new TrackedSet(value1);
|
|
72
|
+
}
|
|
73
|
+
if (value1 instanceof Set) {
|
|
74
|
+
return new TrackedSet(value1);
|
|
75
|
+
}
|
|
76
|
+
return new TrackedSet([value1]);
|
|
77
|
+
}
|
|
78
|
+
static {
|
|
79
|
+
n(this.prototype, "activePressed", [cached]);
|
|
80
|
+
}
|
|
81
|
+
handleToggle = value1 => {
|
|
82
|
+
if (this.activePressed.has(value1)) {
|
|
83
|
+
this.activePressed.delete(value1);
|
|
84
|
+
} else {
|
|
85
|
+
this.activePressed.add(value1);
|
|
86
|
+
}
|
|
87
|
+
this.args.onChange?.(new Set(this.activePressed.values()));
|
|
88
|
+
};
|
|
89
|
+
isPressed = value1 => this.activePressed.has(value1);
|
|
90
|
+
static {
|
|
91
|
+
setComponentTemplate(precompileTemplate("\n <div data-tabster={{TABSTER_CONFIG}} ...attributes>\n {{yield (hash Item=(component Toggle onChange=this.handleToggle isPressed=this.isPressed))}}\n </div>\n ", {
|
|
92
|
+
scope: () => ({
|
|
93
|
+
TABSTER_CONFIG,
|
|
94
|
+
hash,
|
|
95
|
+
Toggle
|
|
96
|
+
}),
|
|
97
|
+
strictMode: true
|
|
98
|
+
}), this);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
46
101
|
|
|
47
102
|
export { ToggleGroup };
|
|
48
103
|
//# sourceMappingURL=toggle-group.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-group.js","sources":["../../src/components/toggle-group.gts"],"sourcesContent":["import { template } from \"@ember/template-compiler\";\nimport Component from '@glimmer/component';\nimport { hash } from '@ember/helper';\nimport { Types } from 'tabster';\n// The consumer will need to provide types for tracked-toolbox.\n// Or.. better yet, we PR to trakcked-toolbox to provide them\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport { localCopy } from 'tracked-toolbox';\nimport { Toggle } from './toggle.gts';\nimport type { ComponentLike } from '@glint/template';\nconst TABSTER_CONFIG = JSON.stringify({\n mover: {\n direction: Types.MoverDirections.Both,\n cyclic: true\n }\n});\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface ItemSignature<Value = any> {\n /**\n * The button element will have aria-pressed=\"true\" on it when the button is in the pressed state.\n */ Element: HTMLButtonElement;\n Args: {\n /**\n * When used in a group of Toggles, this option will be helpful to\n * know which toggle was pressed if you're using the same @onChange\n * handler for multiple toggles.\n */ value?: Value;\n };\n Blocks: {\n default: [/**\n * the current pressed state of the toggle button\n *\n * Useful when using the toggle button as an uncontrolled component\n */ pressed: boolean];\n };\n}\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Item<Value = any> = ComponentLike<ItemSignature<Value>>;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class ToggleGroup<Value = any> extends Component<{\n Element: HTMLDivElement;\n Args: {\n /**\n * Optionally set the initial toggle state\n */ value?: Value;\n /**\n * Callback for when the toggle-group's state is changed.\n *\n * Can be used to control the state of the component.\n *\n *\n * When none of the toggles are selected, undefined will be passed.\n */ onChange: (value: Value | undefined) => void;\n };\n Blocks: {\n default: [{\n Item: Item;\n }];\n };\n}> {\n @localCopy('args.value')\n activePressed?: Value;\n handleToggle = (value1: Value)=>{\n if (this.activePressed === value1) {\n this.activePressed = undefined;\n return;\n }\n this.activePressed = value1;\n this.args.onChange?.(this.activePressed);\n };\n isPressed = (value1: Value | undefined)=>value1 === this.activePressed;\n static{\n template(`\n <div data-tabster={{TABSTER_CONFIG}} ...attributes>\n {{yield (hash Item=(component Toggle onChange=this.handleToggle isPressed=this.isPressed))}}\n </div>\n `, {\n component: this,\n eval () {\n return eval(arguments[0]);\n }\n });\n }\n}\n"],"names":["TABSTER_CONFIG","JSON","stringify","mover","direction","Types","MoverDirections","Both","cyclic","ToggleGroup","Component","g","this","prototype","localCopy","i","void 0","handleToggle","value1","activePressed","undefined","args","onChange","isPressed","setComponentTemplate","precompileTemplate","scope","hash","Toggle","strictMode"],"mappings":";;;;;;;;;AAWA,MAAMA,cAAc,GAAGC,IAAI,CAACC,SAAS,CAAC;AAClCC,EAAAA,KAAK,EAAE;AACHC,IAAAA,SAAS,EAAEC,KAAK,CAACC,eAAe,CAACC,IAAI;AACrCC,IAAAA,MAAM,EAAE,IAAA;AACZ,GAAA;AACJ,CAAC,CAAC,CAAA;AACF;;AAoBA;;AAEA;AACO,MAAMC,WAAW,SAAsBC,SAAS,CAoBpD;AAAA,EAAA;IAAAC,CAAA,CAAAC,IAAA,CAAAC,SAAA,oBACEC,SAAS,CAAC,YAAY,CAAC,CAAA,CAAA,CAAA;AAAA,GAAA;AAAA,EAAA,cAAA,IAAAC,CAAA,CAAAH,IAAA,oBAAAI,KAAA,CAAA,EAAA;EAExBC,YAAY,GAAIC,MAAa,IAAG;AAC5B,IAAA,IAAI,IAAI,CAACC,aAAa,KAAKD,MAAM,EAAE;MAC/B,IAAI,CAACC,aAAa,GAAGC,SAAS,CAAA;AAC9B,MAAA,OAAA;AACJ,KAAA;IACA,IAAI,CAACD,aAAa,GAAGD,MAAM,CAAA;IAC3B,IAAI,CAACG,IAAI,CAACC,QAAQ,GAAG,IAAI,CAACH,aAAa,CAAC,CAAA;GAC3C,CAAA;AACDI,EAAAA,SAAS,GAAIL,MAAyB,IAAGA,MAAM,KAAK,IAAI,CAACC,aAAa,CAAA;AACtE,EAAA;IACIK,oBAAA,CAAAC,kBAAA,CAIH,+KAAA,EAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAA1B,cAAA;QAAA2B,IAAA;AAAAC,QAAAA,MAAAA;AAAA,OAAA,CAAA;MAAAC,UAAA,EAAA,IAAA;KAKI,CAAC,EAJa,IAAI,CAAA,CAAA;AAKvB,GAAA;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"toggle-group.js","sources":["../../src/components/toggle-group.gts"],"sourcesContent":["import { template } from \"@ember/template-compiler\";\nimport Component from '@glimmer/component';\nimport { cached } from '@glimmer/tracking';\nimport { hash } from '@ember/helper';\nimport { Types } from 'tabster';\nimport { TrackedSet } from 'tracked-built-ins';\n// The consumer will need to provide types for tracked-toolbox.\n// Or.. better yet, we PR to trakcked-toolbox to provide them\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport { localCopy } from 'tracked-toolbox';\nimport { Toggle } from './toggle.gts';\nimport type { ComponentLike } from '@glint/template';\nconst TABSTER_CONFIG = JSON.stringify({\n mover: {\n direction: Types.MoverDirections.Both,\n cyclic: true\n }\n});\nexport interface ItemSignature<Value = any> {\n /**\n * The button element will have aria-pressed=\"true\" on it when the button is in the pressed state.\n */ Element: HTMLButtonElement;\n Args: {\n /**\n * When used in a group of Toggles, this option will be helpful to\n * know which toggle was pressed if you're using the same @onChange\n * handler for multiple toggles.\n */ value?: Value;\n };\n Blocks: {\n default: [/**\n * the current pressed state of the toggle button\n *\n * Useful when using the toggle button as an uncontrolled component\n */ pressed: boolean];\n };\n}\nexport type Item<Value = any> = ComponentLike<ItemSignature<Value>>;\nexport interface SingleSignature<Value> {\n Element: HTMLDivElement;\n Args: {\n /**\n * Optionally set the initial toggle state\n */ value?: Value;\n /**\n * Callback for when the toggle-group's state is changed.\n *\n * Can be used to control the state of the component.\n *\n *\n * When none of the toggles are selected, undefined will be passed.\n */ onChange?: (value: Value | undefined) => void;\n };\n Blocks: {\n default: [{\n /**\n * The Toggle Switch\n */ Item: Item;\n }];\n };\n}\nexport interface MultiSignature<Value = any> {\n Element: HTMLDivElement;\n Args: {\n /**\n * Optionally set the initial toggle state\n */ value?: Value[] | Set<Value> | Value;\n /**\n * Callback for when the toggle-group's state is changed.\n *\n * Can be used to control the state of the component.\n *\n *\n * When none of the toggles are selected, undefined will be passed.\n */ onChange?: (value: Set<Value>) => void;\n };\n Blocks: {\n default: [{\n /**\n * The Toggle Switch\n */ Item: Item;\n }];\n };\n}\ninterface PrivateSingleSignature<Value = any> {\n Element: HTMLDivElement;\n Args: {\n type?: 'single';\n /**\n * Optionally set the initial toggle state\n */ value?: Value;\n /**\n * Callback for when the toggle-group's state is changed.\n *\n * Can be used to control the state of the component.\n *\n *\n * When none of the toggles are selected, undefined will be passed.\n */ onChange?: (value: Value | undefined) => void;\n };\n Blocks: {\n default: [{\n Item: Item;\n }];\n };\n}\ninterface PrivateMultiSignature<Value = any> {\n Element: HTMLDivElement;\n Args: {\n type: 'multi';\n /**\n * Optionally set the initial toggle state\n */ value?: Value[] | Set<Value> | Value;\n /**\n * Callback for when the toggle-group's state is changed.\n *\n * Can be used to control the state of the component.\n *\n *\n * When none of the toggles are selected, undefined will be passed.\n */ onChange?: (value: Set<Value>) => void;\n };\n Blocks: {\n default: [{\n Item: Item;\n }];\n };\n}\nfunction isMulti(x1: 'single' | 'multi' | undefined): x is 'multi' {\n return x1 === 'multi';\n}\nexport class ToggleGroup<Value = any> extends Component<PrivateSingleSignature<Value> | PrivateMultiSignature<Value>> {\n // See: https://github.com/typed-ember/glint/issues/715\n static{\n template(`\n {{#if (isMulti this.args.type)}}\n <MultiToggleGroup\n @value={{this.args.value}}\n @onChange={{this.args.onChange}}\n ...attributes\n as |x|\n >\n {{yield x}}\n </MultiToggleGroup>\n {{else}}\n <SingleToggleGroup\n @value={{this.args.value}}\n @onChange={{this.args.onChange}}\n ...attributes\n as |x|\n >\n {{yield x}}\n </SingleToggleGroup>\n {{/if}}\n `, {\n component: this,\n eval () {\n return eval(arguments[0]);\n }\n });\n }\n}\nlet SingleToggleGroup = class SingleToggleGroup<Value = any> extends Component<SingleSignature<Value>> {\n @localCopy('args.value')\n activePressed?: Value;\n handleToggle = (value1: Value)=>{\n if (this.activePressed === value1) {\n this.activePressed = undefined;\n return;\n }\n this.activePressed = value1;\n this.args.onChange?.(this.activePressed);\n };\n isPressed = (value1: Value | undefined)=>value1 === this.activePressed;\n static{\n template(`\n <div data-tabster={{TABSTER_CONFIG}} ...attributes>\n {{yield (hash Item=(component Toggle onChange=this.handleToggle isPressed=this.isPressed))}}\n </div>\n `, {\n component: this,\n eval () {\n return eval(arguments[0]);\n }\n });\n }\n};\nlet MultiToggleGroup = class MultiToggleGroup<Value = any> extends Component<MultiSignature<Value>> {\n /**\n * Normalizes @value to a Set\n * and makes sure that even if the input Set is reactive,\n * we don't mistakenly dirty it.\n */ @cached\n get activePressed(): TrackedSet<Value> {\n let value1 = this.args.value;\n if (!value1) {\n return new TrackedSet();\n }\n if (Array.isArray(value1)) {\n return new TrackedSet(value1);\n }\n if (value1 instanceof Set) {\n return new TrackedSet(value1);\n }\n return new TrackedSet([\n value1\n ]);\n }\n handleToggle = (value1: Value)=>{\n if (this.activePressed.has(value1)) {\n this.activePressed.delete(value1);\n } else {\n this.activePressed.add(value1);\n }\n this.args.onChange?.(new Set<Value>(this.activePressed.values()));\n };\n isPressed = (value1: Value)=>this.activePressed.has(value1);\n static{\n template(`\n <div data-tabster={{TABSTER_CONFIG}} ...attributes>\n {{yield (hash Item=(component Toggle onChange=this.handleToggle isPressed=this.isPressed))}}\n </div>\n `, {\n component: this,\n eval () {\n return eval(arguments[0]);\n }\n });\n }\n};\n"],"names":["TABSTER_CONFIG","JSON","stringify","mover","direction","Types","MoverDirections","Both","cyclic","isMulti","x1","ToggleGroup","Component","setComponentTemplate","precompileTemplate","scope","MultiToggleGroup","SingleToggleGroup","strictMode","g","this","prototype","localCopy","i","void 0","handleToggle","value1","activePressed","undefined","args","onChange","isPressed","hash","Toggle","value","TrackedSet","Array","isArray","Set","n","cached","has","delete","add","values"],"mappings":";;;;;;;;;;;AAaA,MAAMA,cAAc,GAAGC,IAAI,CAACC,SAAS,CAAC;AAClCC,EAAAA,KAAK,EAAE;AACHC,IAAAA,SAAS,EAAEC,KAAK,CAACC,eAAe,CAACC,IAAI;AACrCC,IAAAA,MAAM,EAAE,IAAA;AACZ,GAAA;AACJ,CAAC,CAAC,CAAA;AA+GF,SAASC,OAAOA,CAACC,EAAkC,EAAgB;EAC/D,OAAOA,EAAE,KAAK,OAAO,CAAA;AACzB,CAAA;AACO,MAAMC,WAAW,SAAsBC,SAAS,CAA+D;AAClH;AACA,EAAA;IACIC,oBAAA,CAAAC,kBAAA,CAoBH,+XAAA,EAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAN,OAAA;QAAAO,gBAAA;AAAAC,QAAAA,iBAAAA;AAAA,OAAA,CAAA;MAAAC,UAAA,EAAA,IAAA;KAKI,CAAC,EAJa,IAAI,CAAA,CAAA;AAKvB,GAAA;AACJ,CAAA;AACA,IAAID,iBAAiB,GAAG,MAAMA,iBAAiB,SAAsBL,SAAS,CAAyB;AAAA,EAAA;IAAAO,CAAA,CAAAC,IAAA,CAAAC,SAAA,oBAClGC,SAAS,CAAC,YAAY,CAAC,CAAA,CAAA,CAAA;AAAA,GAAA;AAAA,EAAA,cAAA,IAAAC,CAAA,CAAAH,IAAA,oBAAAI,KAAA,CAAA,EAAA;EAExBC,YAAY,GAAIC,MAAa,IAAG;AAC5B,IAAA,IAAI,IAAI,CAACC,aAAa,KAAKD,MAAM,EAAE;MAC/B,IAAI,CAACC,aAAa,GAAGC,SAAS,CAAA;AAC9B,MAAA,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,CAACf,MAAM,CAAC,EAAE;AAChC,MAAA,IAAI,CAACC,aAAa,CAACe,MAAM,CAAChB,MAAM,CAAC,CAAA;AACrC,KAAC,MAAM;AACH,MAAA,IAAI,CAACC,aAAa,CAACgB,GAAG,CAACjB,MAAM,CAAC,CAAA;AAClC,KAAA;AACA,IAAA,IAAI,CAACG,IAAI,CAACC,QAAQ,GAAG,IAAIQ,GAAG,CAAQ,IAAI,CAACX,aAAa,CAACiB,MAAM,EAAE,CAAC,CAAC,CAAA;GACpE,CAAA;EACDb,SAAS,GAAIL,MAAa,IAAG,IAAI,CAACC,aAAa,CAACc,GAAG,CAACf,MAAM,CAAC,CAAA;AAC3D,EAAA;IACIb,oBAAA,CAAAC,kBAAA,CAIH,+KAAA,EAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAf,cAAA;QAAAgC,IAAA;AAAAC,QAAAA,MAAAA;AAAA,OAAA,CAAA;MAAAf,UAAA,EAAA,IAAA;KAKI,CAAC,EAJa,IAAI,CAAA,CAAA;AAKvB,GAAA;AACJ,CAAC;;;;"}
|
|
@@ -6,6 +6,7 @@ import { precompileTemplate } from '@ember/template-compilation';
|
|
|
6
6
|
import { setComponentTemplate } from '@ember/component';
|
|
7
7
|
import templateOnly from '@ember/component/template-only';
|
|
8
8
|
|
|
9
|
+
// import Component from '@glimmer/component';
|
|
9
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
11
|
function isPressed(pressed1, value1, isPressed1) {
|
|
11
12
|
if (!value1) return Boolean(pressed1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle.js","sources":["../../src/components/toggle.gts"],"sourcesContent":["import { template } from \"@ember/template-compiler\";\nimport { fn } from '@ember/helper';\nimport { on } from '@ember/modifier';\nimport { cell } from 'ember-resources';\nimport { toggleWithFallback } from './-private/utils.ts';\nimport type { TOC } from '@ember/component/template-only';\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface Signature<Value = any> {\n Element: HTMLButtonElement;\n Args: {\n /**\n * The pressed-state of the toggle.\n *\n * Can be used to control the state of the component.\n */ pressed?: boolean;\n /**\n * Callback for when the toggle's state is changed.\n *\n * Can be used to control the state of the component.\n *\n * if a `@value` is passed to this `<Toggle>`, that @value will\n * be passed to the `@onChange` handler.\n *\n * This can be useful when using the same function for the `@onChange`\n * handler with multiple `<Toggle>` components.\n */ onChange?: (value
|
|
1
|
+
{"version":3,"file":"toggle.js","sources":["../../src/components/toggle.gts"],"sourcesContent":["// import Component from '@glimmer/component';\nimport { template } from \"@ember/template-compiler\";\nimport { fn } from '@ember/helper';\nimport { on } from '@ember/modifier';\nimport { cell } from 'ember-resources';\nimport { toggleWithFallback } from './-private/utils.ts';\nimport type { TOC } from '@ember/component/template-only';\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface Signature<Value = any> {\n Element: HTMLButtonElement;\n Args: {\n /**\n * The pressed-state of the toggle.\n *\n * Can be used to control the state of the component.\n */ pressed?: boolean;\n /**\n * Callback for when the toggle's state is changed.\n *\n * Can be used to control the state of the component.\n *\n * if a `@value` is passed to this `<Toggle>`, that @value will\n * be passed to the `@onChange` handler.\n *\n * This can be useful when using the same function for the `@onChange`\n * handler with multiple `<Toggle>` components.\n */ onChange?: (value: Value | undefined, pressed: boolean) => void;\n /**\n * When used in a group of Toggles, this option will be helpful to\n * know which toggle was pressed if you're using the same @onChange\n * handler for multiple toggles.\n */ value?: Value;\n /**\n * When controlling state in a wrapping component, this function can be used in conjunction with `@value` to determine if this `<Toggle>` should appear pressed.\n */ isPressed?: (value?: Value | undefined) => boolean;\n };\n Blocks: {\n default: [/**\n * the current pressed state of the toggle button\n *\n * Useful when using the toggle button as an uncontrolled component\n */ pressed: boolean];\n };\n}\nfunction isPressed(pressed1?: boolean, value1?: unknown, isPressed1?: (value?: unknown) => boolean): boolean {\n if (!value1) return Boolean(pressed1);\n if (!isPressed1) return Boolean(pressed1);\n return isPressed1(value1);\n}\nexport const Toggle: TOC<Signature> = template(`\n {{#let (cell (isPressed @pressed @value @isPressed)) as |pressed|}}\n <button\n type=\"button\"\n aria-pressed=\"{{pressed.current}}\"\n {{on \"click\" (fn toggleWithFallback pressed.toggle @onChange @value)}}\n ...attributes\n >\n {{yield pressed.current}}\n </button>\n {{/let}}\n`, {\n eval () {\n return eval(arguments[0]);\n }\n});\nexport default Toggle;\n"],"names":["isPressed","pressed1","value1","isPressed1","Boolean","Toggle","setComponentTemplate","precompileTemplate","scope","cell","on","fn","toggleWithFallback","strictMode","templateOnly"],"mappings":";;;;;;;;AAAA;AAOA;AAqCA,SAASA,SAASA,CAACC,QAAkB,EAAEC,MAAgB,EAAEC,UAAyC,EAAW;AACzG,EAAA,IAAI,CAACD,MAAM,EAAE,OAAOE,OAAO,CAACH,QAAQ,CAAC,CAAA;AACrC,EAAA,IAAI,CAACE,UAAU,EAAE,OAAOC,OAAO,CAACH,QAAQ,CAAC,CAAA;EACzC,OAAOE,UAAU,CAACD,MAAM,CAAC,CAAA;AAC7B,CAAA;MACaG,MAAsB,GAAAC,oBAAA,CAAGC,kBAAA,CAWnC,iSAAA,EAAA;AAAAC,EAAAA,KAAA,EAAAA,OAAA;IAAAC,IAAA;IAAAT,SAAA;IAAAU,EAAA;IAAAC,EAAA;AAAAC,IAAAA,kBAAAA;AAAA,GAAA,CAAA;EAAAC,UAAA,EAAA,IAAA;AAIH,CAAC,CAAC,EAAAC,YAAA,EAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ember-primitives",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Making apps easier to build",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"*.css"
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"ember-velcro": "^2.1.3",
|
|
27
27
|
"reactiveweb": "^1.2.0",
|
|
28
28
|
"tabster": "^7.0.1",
|
|
29
|
+
"tracked-built-ins": "^3.2.0",
|
|
29
30
|
"tracked-toolbox": "^2.0.0"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|