ember-primitives 0.33.0 → 0.35.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/head.d.ts +27 -0
- package/declarations/qp.d.ts +45 -3
- package/dist/head.js +33 -0
- package/dist/head.js.map +1 -0
- package/dist/qp.js +51 -3
- package/dist/qp.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { TOC } from "@ember/component/template-only";
|
|
2
|
+
export interface Signature {
|
|
3
|
+
Blocks: {
|
|
4
|
+
/**
|
|
5
|
+
* Content to render in to the `<head>` element
|
|
6
|
+
*/
|
|
7
|
+
default: [];
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Utility component to place elements in the document `<head>`
|
|
12
|
+
*
|
|
13
|
+
* When this component is unrendered, its contents will be removed as well.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```js
|
|
17
|
+
* import { InHead } from 'ember-primitives/head';
|
|
18
|
+
*
|
|
19
|
+
* <template>
|
|
20
|
+
* {{#if @useBootstrap}}
|
|
21
|
+
* <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js"></script>
|
|
22
|
+
* <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css">
|
|
23
|
+
* {{/if}}
|
|
24
|
+
* </template>
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare const InHead: TOC<Signature>;
|
package/declarations/qp.d.ts
CHANGED
|
@@ -1,19 +1,61 @@
|
|
|
1
1
|
import Helper from '@ember/component/helper';
|
|
2
2
|
import type RouterService from '@ember/routing/router-service';
|
|
3
|
-
|
|
3
|
+
interface Signature {
|
|
4
4
|
Args: {
|
|
5
5
|
Positional: [string];
|
|
6
6
|
};
|
|
7
7
|
Return: string | undefined;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Grabs a query-param off the current route from the router service.
|
|
11
|
+
*
|
|
12
|
+
* ```gjs
|
|
13
|
+
* import { qp } from 'ember-primitives/qp';
|
|
14
|
+
*
|
|
15
|
+
* <template>
|
|
16
|
+
* {{qp "query-param"}}
|
|
17
|
+
* </template>
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class qp extends Helper<Signature> {
|
|
10
21
|
router: RouterService;
|
|
11
22
|
compute([name]: [string]): string | undefined;
|
|
12
23
|
}
|
|
13
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Returns a string for use as an `href` on `<a>` tags, updated with the passed query param
|
|
26
|
+
*
|
|
27
|
+
* ```gjs
|
|
28
|
+
* import { withQP } from 'ember-primitives/qp';
|
|
29
|
+
*
|
|
30
|
+
* <template>
|
|
31
|
+
* <a href={{withQP "foo" "2"}}>
|
|
32
|
+
* ...
|
|
33
|
+
* </a>
|
|
34
|
+
* </template>
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare class withQP extends Helper<{
|
|
38
|
+
Args: {
|
|
39
|
+
Positional: [string, string];
|
|
40
|
+
};
|
|
41
|
+
Return: string;
|
|
42
|
+
}> {
|
|
43
|
+
router: RouterService;
|
|
44
|
+
compute([qpName, nextValue]: [string, string]): string;
|
|
45
|
+
}
|
|
14
46
|
/**
|
|
15
47
|
* Cast a query-param string value to a boolean
|
|
16
48
|
*
|
|
49
|
+
* ```gjs
|
|
50
|
+
* import { castToBoolean, qp } from 'ember-primitives/qp';
|
|
51
|
+
*
|
|
52
|
+
* <template>
|
|
53
|
+
* {{#if (castToBoolean (qp 'the-qp'))}}
|
|
54
|
+
* ...
|
|
55
|
+
* {{/if}}
|
|
56
|
+
* </template>
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
17
59
|
* The following values are considered "false"
|
|
18
60
|
* - undefined
|
|
19
61
|
* - ""
|
package/dist/head.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { precompileTemplate } from '@ember/template-compilation';
|
|
2
|
+
import { setComponentTemplate } from '@ember/component';
|
|
3
|
+
import templateOnly from '@ember/component/template-only';
|
|
4
|
+
|
|
5
|
+
function getHead() {
|
|
6
|
+
return document.head;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Utility component to place elements in the document `<head>`
|
|
10
|
+
*
|
|
11
|
+
* When this component is unrendered, its contents will be removed as well.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```js
|
|
15
|
+
* import { InHead } from 'ember-primitives/head';
|
|
16
|
+
*
|
|
17
|
+
* <template>
|
|
18
|
+
* {{#if @useBootstrap}}
|
|
19
|
+
* <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js"></script>
|
|
20
|
+
* <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css">
|
|
21
|
+
* {{/if}}
|
|
22
|
+
* </template>
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
const InHead = setComponentTemplate(precompileTemplate("\n {{#in-element (getHead) insertBefore=null}}\n {{yield}}\n {{/in-element}}\n", {
|
|
26
|
+
strictMode: true,
|
|
27
|
+
scope: () => ({
|
|
28
|
+
getHead
|
|
29
|
+
})
|
|
30
|
+
}), templateOnly());
|
|
31
|
+
|
|
32
|
+
export { InHead };
|
|
33
|
+
//# sourceMappingURL=head.js.map
|
package/dist/head.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"head.js","sources":["../src/head.gts"],"sourcesContent":["import type { TOC } from \"@ember/component/template-only\";\n\nexport interface Signature {\n Blocks: {\n /**\n * Content to render in to the `<head>` element\n */\n default: [];\n };\n}\n\nfunction getHead() {\n return document.head;\n}\n\n/**\n * Utility component to place elements in the document `<head>`\n *\n * When this component is unrendered, its contents will be removed as well.\n *\n * @example\n * ```js\n * import { InHead } from 'ember-primitives/head';\n *\n * <template>\n * {{#if @useBootstrap}}\n * <script src=\"https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js\"></script>\n * <link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css\">\n * {{/if}}\n * </template>\n * ```\n */\nexport const InHead: TOC<Signature> = <template>\n {{#in-element (getHead) insertBefore=null}}\n {{yield}}\n {{/in-element}}\n</template>;\n"],"names":["getHead","document","head","InHead","setComponentTemplate","precompileTemplate","strictMode","scope","templateOnly"],"mappings":";;;;AAWA,SAASA,OAAAA,GAAA;EACP,OAAOC,SAASC,IAAI;AACtB;AAEA;;;;;;;;;;;;;;;;AAgBC;MACYC,MAAY,GAAAC,oBAAA,CAAaC,kBAAA,CAAA,qFAAA,EAItC;EAAAC,UAAA,EAAA,IAAA;AAAAC,EAAAA,KAAA,EAAAA,OAAA;AAAAP,IAAAA;AAAA,GAAA;AAAU,CAAA,CAAA,EAAAQ,YAAA,EAAA;;;;"}
|
package/dist/qp.js
CHANGED
|
@@ -3,7 +3,18 @@ import { assert } from '@ember/debug';
|
|
|
3
3
|
import { service } from '@ember/service';
|
|
4
4
|
import { g, i } from 'decorator-transforms/runtime';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Grabs a query-param off the current route from the router service.
|
|
8
|
+
*
|
|
9
|
+
* ```gjs
|
|
10
|
+
* import { qp } from 'ember-primitives/qp';
|
|
11
|
+
*
|
|
12
|
+
* <template>
|
|
13
|
+
* {{qp "query-param"}}
|
|
14
|
+
* </template>
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
class qp extends Helper {
|
|
7
18
|
static {
|
|
8
19
|
g(this.prototype, "router", [service]);
|
|
9
20
|
}
|
|
@@ -13,11 +24,48 @@ class QP extends Helper {
|
|
|
13
24
|
return this.router.currentRoute?.queryParams?.[name];
|
|
14
25
|
}
|
|
15
26
|
}
|
|
16
|
-
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Returns a string for use as an `href` on `<a>` tags, updated with the passed query param
|
|
30
|
+
*
|
|
31
|
+
* ```gjs
|
|
32
|
+
* import { withQP } from 'ember-primitives/qp';
|
|
33
|
+
*
|
|
34
|
+
* <template>
|
|
35
|
+
* <a href={{withQP "foo" "2"}}>
|
|
36
|
+
* ...
|
|
37
|
+
* </a>
|
|
38
|
+
* </template>
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
class withQP extends Helper {
|
|
42
|
+
static {
|
|
43
|
+
g(this.prototype, "router", [service]);
|
|
44
|
+
}
|
|
45
|
+
#router = (i(this, "router"), void 0);
|
|
46
|
+
compute([qpName, nextValue]) {
|
|
47
|
+
const existing = this.router.currentURL;
|
|
48
|
+
assert('A queryParam name is required', qpName);
|
|
49
|
+
assert('There is no currentURL', existing);
|
|
50
|
+
const url = new URL(existing, location.origin);
|
|
51
|
+
url.searchParams.set(qpName, nextValue);
|
|
52
|
+
return url.href;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
17
55
|
|
|
18
56
|
/**
|
|
19
57
|
* Cast a query-param string value to a boolean
|
|
20
58
|
*
|
|
59
|
+
* ```gjs
|
|
60
|
+
* import { castToBoolean, qp } from 'ember-primitives/qp';
|
|
61
|
+
*
|
|
62
|
+
* <template>
|
|
63
|
+
* {{#if (castToBoolean (qp 'the-qp'))}}
|
|
64
|
+
* ...
|
|
65
|
+
* {{/if}}
|
|
66
|
+
* </template>
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
21
69
|
* The following values are considered "false"
|
|
22
70
|
* - undefined
|
|
23
71
|
* - ""
|
|
@@ -40,5 +88,5 @@ function castToBoolean(x) {
|
|
|
40
88
|
return true;
|
|
41
89
|
}
|
|
42
90
|
|
|
43
|
-
export { castToBoolean, qp };
|
|
91
|
+
export { castToBoolean, qp, withQP };
|
|
44
92
|
//# sourceMappingURL=qp.js.map
|
package/dist/qp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qp.js","sources":["../src/qp.ts"],"sourcesContent":["import Helper from '@ember/component/helper';\nimport { assert } from '@ember/debug';\nimport { service } from '@ember/service';\n\nimport type RouterService from '@ember/routing/router-service';\n\
|
|
1
|
+
{"version":3,"file":"qp.js","sources":["../src/qp.ts"],"sourcesContent":["import Helper from '@ember/component/helper';\nimport { assert } from '@ember/debug';\nimport { service } from '@ember/service';\n\nimport type RouterService from '@ember/routing/router-service';\n\ninterface Signature {\n Args: {\n Positional: [string];\n };\n Return: string | undefined;\n}\n\n/**\n * Grabs a query-param off the current route from the router service.\n *\n * ```gjs\n * import { qp } from 'ember-primitives/qp';\n *\n * <template>\n * {{qp \"query-param\"}}\n * </template>\n * ```\n */\nexport class qp extends Helper<Signature> {\n @service declare router: RouterService;\n\n compute([name]: [string]): string | undefined {\n assert('A queryParam name is required', name);\n\n return this.router.currentRoute?.queryParams?.[name] as string | undefined;\n }\n}\n\n/**\n * Returns a string for use as an `href` on `<a>` tags, updated with the passed query param\n *\n * ```gjs\n * import { withQP } from 'ember-primitives/qp';\n *\n * <template>\n * <a href={{withQP \"foo\" \"2\"}}>\n * ...\n * </a>\n * </template>\n * ```\n */\nexport class withQP extends Helper<{ Args: { Positional: [string, string] }; Return: string }> {\n @service declare router: RouterService;\n\n compute([qpName, nextValue]: [string, string]) {\n const existing = this.router.currentURL;\n\n assert('A queryParam name is required', qpName);\n assert('There is no currentURL', existing);\n\n const url = new URL(existing, location.origin);\n\n url.searchParams.set(qpName, nextValue);\n\n return url.href;\n }\n}\n\n/**\n * Cast a query-param string value to a boolean\n *\n * ```gjs\n * import { castToBoolean, qp } from 'ember-primitives/qp';\n *\n * <template>\n * {{#if (castToBoolean (qp 'the-qp'))}}\n * ...\n * {{/if}}\n * </template>\n * ```\n *\n * The following values are considered \"false\"\n * - undefined\n * - \"\"\n * - \"0\"\n * - false\n * - \"f\"\n * - \"off\"\n * - \"no\"\n * - \"null\"\n * - \"undefined\"\n *\n * All other values are considered truthy\n */\nexport function castToBoolean(x: string | undefined) {\n if (!x) return false;\n\n const isFalsey =\n x === '0' ||\n x === 'false' ||\n x === 'f' ||\n x === 'null' ||\n x === 'off' ||\n x === 'undefined' ||\n x === 'no';\n\n if (isFalsey) return false;\n\n // All other values are considered truthy\n return true;\n}\n"],"names":["qp","Helper","g","prototype","service","i","void 0","compute","name","assert","router","currentRoute","queryParams","withQP","qpName","nextValue","existing","currentURL","url","URL","location","origin","searchParams","set","href","castToBoolean","x","isFalsey"],"mappings":";;;;;AAaA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,EAAE,SAASC,MAAM,CAAY;AAAA,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,QAAA,EAAA,CACvCC,OAAO,CAAA,CAAA;AAAA;AAAA,EAAA,OAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,QAAA,CAAA,EAAAC,MAAA;AAERC,EAAAA,OAAOA,CAAC,CAACC,IAAI,CAAW,EAAsB;AAC5CC,IAAAA,MAAM,CAAC,+BAA+B,EAAED,IAAI,CAAC;IAE7C,OAAO,IAAI,CAACE,MAAM,CAACC,YAAY,EAAEC,WAAW,GAAGJ,IAAI,CAAC;AACtD;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMK,MAAM,SAASZ,MAAM,CAA6D;AAAA,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,QAAA,EAAA,CAC5FC,OAAO,CAAA,CAAA;AAAA;AAAA,EAAA,OAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,QAAA,CAAA,EAAAC,MAAA;AAERC,EAAAA,OAAOA,CAAC,CAACO,MAAM,EAAEC,SAAS,CAAmB,EAAE;AAC7C,IAAA,MAAMC,QAAQ,GAAG,IAAI,CAACN,MAAM,CAACO,UAAU;AAEvCR,IAAAA,MAAM,CAAC,+BAA+B,EAAEK,MAAM,CAAC;AAC/CL,IAAAA,MAAM,CAAC,wBAAwB,EAAEO,QAAQ,CAAC;IAE1C,MAAME,GAAG,GAAG,IAAIC,GAAG,CAACH,QAAQ,EAAEI,QAAQ,CAACC,MAAM,CAAC;IAE9CH,GAAG,CAACI,YAAY,CAACC,GAAG,CAACT,MAAM,EAAEC,SAAS,CAAC;IAEvC,OAAOG,GAAG,CAACM,IAAI;AACjB;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,aAAaA,CAACC,CAAqB,EAAE;AACnD,EAAA,IAAI,CAACA,CAAC,EAAE,OAAO,KAAK;AAEpB,EAAA,MAAMC,QAAQ,GACZD,CAAC,KAAK,GAAG,IACTA,CAAC,KAAK,OAAO,IACbA,CAAC,KAAK,GAAG,IACTA,CAAC,KAAK,MAAM,IACZA,CAAC,KAAK,KAAK,IACXA,CAAC,KAAK,WAAW,IACjBA,CAAC,KAAK,IAAI;EAEZ,IAAIC,QAAQ,EAAE,OAAO,KAAK;;AAE1B;AACA,EAAA,OAAO,IAAI;AACb;;;;"}
|