ember-primitives 0.30.1 → 0.31.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.
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initial inspo:
|
|
3
|
+
* - https://github.com/ef4/ember-set-body-class/blob/master/addon/services/body-class.js
|
|
4
|
+
* - https://github.com/ef4/ember-set-body-class/blob/master/addon/helpers/set-body-class.js
|
|
5
|
+
*/
|
|
6
|
+
import Helper from '@ember/component/helper';
|
|
7
|
+
export interface Signature {
|
|
8
|
+
Args: {
|
|
9
|
+
Positional: [
|
|
10
|
+
/**
|
|
11
|
+
* a space-delimited list of classes to apply when this helper is called.
|
|
12
|
+
*
|
|
13
|
+
* When the helper is removed from rendering, the clasess will be removed as well.
|
|
14
|
+
*/
|
|
15
|
+
classes: string
|
|
16
|
+
];
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* This helper returns nothing, as it is a side-effect that mutates and manages external state.
|
|
20
|
+
*/
|
|
21
|
+
Return: undefined;
|
|
22
|
+
}
|
|
23
|
+
export default class BodyClass extends Helper<Signature> {
|
|
24
|
+
localId: number;
|
|
25
|
+
compute([classes]: [string]): undefined;
|
|
26
|
+
willDestroy(): void;
|
|
27
|
+
}
|
|
28
|
+
export declare const bodyClass: typeof BodyClass;
|
|
29
|
+
//# sourceMappingURL=body-class.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body-class.d.ts","sourceRoot":"","sources":["../../src/helpers/body-class.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAsD7C,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE;QACJ,UAAU,EAAE;YACV;;;;eAIG;YACH,OAAO,EAAE,MAAM;SAChB,CAAC;KACH,CAAC;IACF;;OAEG;IACH,MAAM,EAAE,SAAS,CAAC;CACnB;AAED,MAAM,CAAC,OAAO,OAAO,SAAU,SAAQ,MAAM,CAAC,SAAS,CAAC;IACtD,OAAO,SAAQ;IAEf,OAAO,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,SAAS;IAQvC,WAAW;CAIZ;AAED,eAAO,MAAM,SAAS,kBAAY,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import Helper from '@ember/component/helper';
|
|
2
|
+
import { buildWaiter } from '@ember/test-waiters';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Initial inspo:
|
|
6
|
+
* - https://github.com/ef4/ember-set-body-class/blob/master/addon/services/body-class.js
|
|
7
|
+
* - https://github.com/ef4/ember-set-body-class/blob/master/addon/helpers/set-body-class.js
|
|
8
|
+
*/
|
|
9
|
+
const waiter = buildWaiter('ember-primitives:body-class:raf');
|
|
10
|
+
let id = 0;
|
|
11
|
+
const registrations = new Map();
|
|
12
|
+
let previousRegistrations = [];
|
|
13
|
+
function classNames() {
|
|
14
|
+
const allNames = new Set();
|
|
15
|
+
for (const classNames of registrations.values()) {
|
|
16
|
+
for (const className of classNames) {
|
|
17
|
+
allNames.add(className);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return [...allNames];
|
|
21
|
+
}
|
|
22
|
+
let frame;
|
|
23
|
+
let waiterToken;
|
|
24
|
+
function queueUpdate() {
|
|
25
|
+
waiterToken ||= waiter.beginAsync();
|
|
26
|
+
cancelAnimationFrame(frame);
|
|
27
|
+
frame = requestAnimationFrame(() => {
|
|
28
|
+
updateBodyClass();
|
|
29
|
+
waiter.endAsync(waiterToken);
|
|
30
|
+
waiterToken = undefined;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* This should only add/remove classes that we tried to maintain via the body-class helper.
|
|
36
|
+
*
|
|
37
|
+
* Folks can set classes in their html and we don't want to mess with those
|
|
38
|
+
*/
|
|
39
|
+
function updateBodyClass() {
|
|
40
|
+
const toAdd = classNames();
|
|
41
|
+
for (const name of previousRegistrations) {
|
|
42
|
+
document.body.classList.remove(name);
|
|
43
|
+
}
|
|
44
|
+
for (const name of toAdd) {
|
|
45
|
+
document.body.classList.add(name);
|
|
46
|
+
}
|
|
47
|
+
previousRegistrations = toAdd;
|
|
48
|
+
}
|
|
49
|
+
class BodyClass extends Helper {
|
|
50
|
+
localId = id++;
|
|
51
|
+
compute([classes]) {
|
|
52
|
+
const classNames = classes ? classes.split(/\s+/) : [];
|
|
53
|
+
registrations.set(this.localId, classNames);
|
|
54
|
+
queueUpdate();
|
|
55
|
+
}
|
|
56
|
+
willDestroy() {
|
|
57
|
+
registrations.delete(this.localId);
|
|
58
|
+
queueUpdate();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const bodyClass = BodyClass;
|
|
62
|
+
|
|
63
|
+
export { bodyClass, BodyClass as default };
|
|
64
|
+
//# sourceMappingURL=body-class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body-class.js","sources":["../../src/helpers/body-class.ts"],"sourcesContent":["/**\n * Initial inspo:\n * - https://github.com/ef4/ember-set-body-class/blob/master/addon/services/body-class.js\n * - https://github.com/ef4/ember-set-body-class/blob/master/addon/helpers/set-body-class.js\n */\nimport Helper from '@ember/component/helper';\nimport { buildWaiter } from '@ember/test-waiters';\n\nconst waiter = buildWaiter('ember-primitives:body-class:raf');\n\nlet id = 0;\nconst registrations = new Map<number, string[]>();\nlet previousRegistrations: string[] = [];\n\nfunction classNames(): string[] {\n const allNames = new Set<string>();\n\n for (const classNames of registrations.values()) {\n for (const className of classNames) {\n allNames.add(className);\n }\n }\n\n return [...allNames];\n}\n\nlet frame: number;\nlet waiterToken: unknown;\n\nfunction queueUpdate() {\n waiterToken ||= waiter.beginAsync();\n\n cancelAnimationFrame(frame);\n frame = requestAnimationFrame(() => {\n updateBodyClass();\n waiter.endAsync(waiterToken);\n waiterToken = undefined;\n });\n}\n\n/**\n * This should only add/remove classes that we tried to maintain via the body-class helper.\n *\n * Folks can set classes in their html and we don't want to mess with those\n */\nfunction updateBodyClass() {\n const toAdd = classNames();\n\n for (const name of previousRegistrations) {\n document.body.classList.remove(name);\n }\n\n for (const name of toAdd) {\n document.body.classList.add(name);\n }\n\n previousRegistrations = toAdd;\n}\n\nexport interface Signature {\n Args: {\n Positional: [\n /**\n * a space-delimited list of classes to apply when this helper is called.\n *\n * When the helper is removed from rendering, the clasess will be removed as well.\n */\n classes: string,\n ];\n };\n /**\n * This helper returns nothing, as it is a side-effect that mutates and manages external state.\n */\n Return: undefined;\n}\n\nexport default class BodyClass extends Helper<Signature> {\n localId = id++;\n\n compute([classes]: [string]): undefined {\n const classNames = classes ? classes.split(/\\s+/) : [];\n\n registrations.set(this.localId, classNames);\n\n queueUpdate();\n }\n\n willDestroy() {\n registrations.delete(this.localId);\n queueUpdate();\n }\n}\n\nexport const bodyClass = BodyClass;\n"],"names":["waiter","buildWaiter","id","registrations","Map","previousRegistrations","classNames","allNames","Set","values","className","add","frame","waiterToken","queueUpdate","beginAsync","cancelAnimationFrame","requestAnimationFrame","updateBodyClass","endAsync","undefined","toAdd","name","document","body","classList","remove","BodyClass","Helper","localId","compute","classes","split","set","willDestroy","delete","bodyClass"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AAIA,MAAMA,MAAM,GAAGC,WAAW,CAAC,iCAAiC,CAAC;AAE7D,IAAIC,EAAE,GAAG,CAAC;AACV,MAAMC,aAAa,GAAG,IAAIC,GAAG,EAAoB;AACjD,IAAIC,qBAA+B,GAAG,EAAE;AAExC,SAASC,UAAUA,GAAa;AAC9B,EAAA,MAAMC,QAAQ,GAAG,IAAIC,GAAG,EAAU;EAElC,KAAK,MAAMF,UAAU,IAAIH,aAAa,CAACM,MAAM,EAAE,EAAE;AAC/C,IAAA,KAAK,MAAMC,SAAS,IAAIJ,UAAU,EAAE;AAClCC,MAAAA,QAAQ,CAACI,GAAG,CAACD,SAAS,CAAC;AACzB;AACF;EAEA,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MAAMsB,SAAS,GAAGT;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ember-primitives",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"description": "Making apps easier to build",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"*.css"
|
|
@@ -17,37 +17,37 @@
|
|
|
17
17
|
"declarations"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@babel/runtime": "^7.27.
|
|
21
|
-
"@embroider/addon-shim": "^1.
|
|
22
|
-
"@embroider/macros": "^1.17.
|
|
23
|
-
"@floating-ui/dom": "^1.
|
|
20
|
+
"@babel/runtime": "^7.27.1",
|
|
21
|
+
"@embroider/addon-shim": "^1.10.0",
|
|
22
|
+
"@embroider/macros": "^1.17.3",
|
|
23
|
+
"@floating-ui/dom": "^1.7.0",
|
|
24
24
|
"decorator-transforms": "^2.3.0",
|
|
25
|
-
"ember-element-helper": "
|
|
25
|
+
"ember-element-helper": "^0.8.7",
|
|
26
26
|
"form-data-utils": "^0.6.0",
|
|
27
27
|
"reactiveweb": "^1.4.2",
|
|
28
28
|
"should-handle-link": "^1.2.2",
|
|
29
|
-
"tabster": "^8.5.
|
|
29
|
+
"tabster": "^8.5.5",
|
|
30
30
|
"tracked-built-ins": "^4.0.0",
|
|
31
31
|
"tracked-toolbox": "^2.0.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@arethetypeswrong/cli": "^0.17.4",
|
|
35
|
-
"@babel/core": "^7.
|
|
35
|
+
"@babel/core": "^7.27.1",
|
|
36
36
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
37
37
|
"@babel/plugin-proposal-decorators": "^7.25.9",
|
|
38
38
|
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
39
|
-
"@babel/plugin-syntax-decorators": "^7.
|
|
40
|
-
"@babel/plugin-transform-class-static-block": "^7.
|
|
41
|
-
"@babel/plugin-transform-private-methods": "^7.
|
|
42
|
-
"@babel/preset-typescript": "^7.27.
|
|
39
|
+
"@babel/plugin-syntax-decorators": "^7.27.1",
|
|
40
|
+
"@babel/plugin-transform-class-static-block": "^7.27.1",
|
|
41
|
+
"@babel/plugin-transform-private-methods": "^7.27.1",
|
|
42
|
+
"@babel/preset-typescript": "^7.27.1",
|
|
43
43
|
"@ember/test-helpers": "^5.2.0",
|
|
44
44
|
"@ember/test-waiters": "^4.1.0",
|
|
45
45
|
"@embroider/addon-dev": "^7.0.1",
|
|
46
46
|
"@glimmer/component": "^2.0.0",
|
|
47
47
|
"@glimmer/tracking": "^1.1.2",
|
|
48
48
|
"@glint/core": "1.5.2",
|
|
49
|
-
"@glint/environment-ember-loose": "1.
|
|
50
|
-
"@glint/environment-ember-template-imports": "1.
|
|
49
|
+
"@glint/environment-ember-loose": "1.5.2",
|
|
50
|
+
"@glint/environment-ember-template-imports": "1.4.1-unstable.5564fc2",
|
|
51
51
|
"@glint/template": "^1.5.2",
|
|
52
52
|
"@nullvoxpopuli/eslint-configs": "^5.1.1",
|
|
53
53
|
"@rollup/plugin-babel": "^6.0.4",
|
|
@@ -56,16 +56,16 @@
|
|
|
56
56
|
"concurrently": "^9.1.0",
|
|
57
57
|
"ember-modifier": "^4.1.0",
|
|
58
58
|
"ember-resources": "^7.0.4",
|
|
59
|
-
"ember-source": "6.5.0-
|
|
60
|
-
"ember-template-lint": "^7.0
|
|
61
|
-
"eslint": "^9.
|
|
59
|
+
"ember-source": "6.5.0-beta.1",
|
|
60
|
+
"ember-template-lint": "^7.6.0",
|
|
61
|
+
"eslint": "^9.26.0",
|
|
62
62
|
"fix-bad-declaration-output": "^1.1.4",
|
|
63
63
|
"prettier": "^3.2.5",
|
|
64
|
-
"prettier-plugin-ember-template-tag": "^2.0.
|
|
64
|
+
"prettier-plugin-ember-template-tag": "^2.0.5",
|
|
65
65
|
"publint": "^0.3.9",
|
|
66
|
-
"rollup": "~4.40.
|
|
66
|
+
"rollup": "~4.40.2",
|
|
67
67
|
"rollup-plugin-copy": "^3.5.0",
|
|
68
|
-
"typescript": "^5.8.
|
|
68
|
+
"typescript": "^5.8.3"
|
|
69
69
|
},
|
|
70
70
|
"publishConfig": {
|
|
71
71
|
"registry": "https://registry.npmjs.org"
|