ember-primitives 0.9.0 → 0.10.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.
@@ -1,8 +1,44 @@
1
+ import { waitForPromise } from '@ember/test-waiters';
1
2
  import { cell } from 'ember-resources';
2
3
 
3
4
  const _colorScheme = cell();
5
+ let callbacks = new Set();
6
+ async function runCallbacks(theme) {
7
+ await Promise.resolve();
8
+ for (let ref of callbacks.values()) {
9
+ let callback = ref.deref();
10
+ if (!callback) {
11
+ callbacks.delete(ref);
12
+ } else {
13
+ callback(theme);
14
+ }
15
+ }
16
+ }
17
+
18
+ /**
19
+ * Callback to sync external systems, such as graphing or charting APIs with the theme system.
20
+ *
21
+ * There is no need to remove the callback like you would with `removeEventListener`.
22
+ * It is managed with WeakRefs so memory is cleaned up automatically over time.
23
+ */
24
+ function onUpdate(callback) {
25
+ callbacks.add(new WeakRef(callback));
26
+ }
27
+
28
+ /**
29
+ * Object for managing the color scheme
30
+ */
4
31
  const colorScheme = {
5
- update: value => colorScheme.current = value,
32
+ /**
33
+ * Set's the current color scheme to the passed value
34
+ */
35
+ update: value => {
36
+ colorScheme.current = value;
37
+ waitForPromise(runCallbacks(value));
38
+ },
39
+ /**
40
+ * the current valuel of the "color scheme"
41
+ */
6
42
  get current() {
7
43
  return _colorScheme.current;
8
44
  },
@@ -16,7 +52,18 @@ const colorScheme = {
16
52
  setColorScheme(value);
17
53
  }
18
54
  };
55
+
56
+ /**
57
+ * Synchronizes state of `colorScheme` with the users preferences as well as reconciles with previously set theme in local storage.
58
+ *
59
+ * This may only be called once per app.
60
+ */
19
61
  function sync() {
62
+ /**
63
+ * reset the callbacks
64
+ */
65
+ callbacks = new Set();
66
+
20
67
  /**
21
68
  * If local prefs are set, then we don't care what prefers-color-scheme is
22
69
  */
@@ -39,6 +86,10 @@ function sync() {
39
86
  _colorScheme.current = 'light';
40
87
  }
41
88
  }
89
+
90
+ /**
91
+ * Helper methods to determining what the user's preferred color scheme is
92
+ */
42
93
  const prefers = {
43
94
  dark: () => window.matchMedia('(prefers-color-scheme: dark)').matches,
44
95
  light: () => window.matchMedia('(prefers-color-scheme: light)').matches,
@@ -46,12 +97,20 @@ const prefers = {
46
97
  none: () => window.matchMedia('(prefers-color-scheme: no-preference)').matches
47
98
  };
48
99
  const LOCAL_PREF_KEY = 'ember-primitives/color-scheme#local-preference';
100
+
101
+ /**
102
+ * Helper methods for working with the color scheme preference in local storage
103
+ */
49
104
  const localPreference = {
50
105
  isSet: () => Boolean(localPreference.read()),
51
106
  read: () => localStorage.getItem(LOCAL_PREF_KEY),
52
107
  update: value => localStorage.setItem(LOCAL_PREF_KEY, value),
53
108
  delete: () => localStorage.removeItem(LOCAL_PREF_KEY)
54
109
  };
110
+
111
+ /**
112
+ * For the given element, returns the `color-scheme` of that element.
113
+ */
55
114
  function getColorScheme(element) {
56
115
  let style = styleOf(element);
57
116
  return style.getPropertyValue('color-scheme');
@@ -63,9 +122,14 @@ function setColorScheme(...args) {
63
122
  }
64
123
  if (typeof args[1] === 'string') {
65
124
  styleOf(args[0]).setProperty('color-scheme', args[1]);
125
+ return;
66
126
  }
67
127
  throw new Error(`Invalid arity, expected up to 2 args, received ${args.length}`);
68
128
  }
129
+
130
+ /**
131
+ * Removes the `color-scheme` from the given element
132
+ */
69
133
  function removeColorScheme(element) {
70
134
  let style = styleOf(element);
71
135
  style.removeProperty('color-scheme');
@@ -77,5 +141,5 @@ function styleOf(element) {
77
141
  return document.documentElement.style;
78
142
  }
79
143
 
80
- export { colorScheme, getColorScheme, localPreference, prefers, removeColorScheme, setColorScheme, sync };
144
+ export { colorScheme, getColorScheme, localPreference, onUpdate, prefers, removeColorScheme, setColorScheme, sync };
81
145
  //# sourceMappingURL=color-scheme.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"color-scheme.js","sources":["../src/color-scheme.ts"],"sourcesContent":["import { cell } from 'ember-resources';\n\nconst _colorScheme = cell<string | undefined>();\n\nexport const colorScheme = {\n update: (value: string) => (colorScheme.current = value),\n\n get current(): string | undefined {\n return _colorScheme.current;\n },\n set current(value: string | undefined) {\n _colorScheme.current = value;\n\n if (!value) {\n localPreference.delete();\n\n return;\n }\n\n localPreference.update(value);\n setColorScheme(value);\n },\n};\n\nexport function sync() {\n /**\n * If local prefs are set, then we don't care what prefers-color-scheme is\n */\n if (localPreference.isSet()) {\n let pref = localPreference.read();\n\n if (pref === 'dark') {\n setColorScheme('dark');\n\n _colorScheme.current = 'dark';\n\n return;\n }\n\n setColorScheme('light');\n _colorScheme.current = 'light';\n\n return;\n }\n\n if (prefers.dark()) {\n setColorScheme('dark');\n _colorScheme.current = 'dark';\n } else if (prefers.light()) {\n setColorScheme('light');\n _colorScheme.current = 'light';\n }\n}\n\nexport const prefers = {\n dark: () => window.matchMedia('(prefers-color-scheme: dark)').matches,\n light: () => window.matchMedia('(prefers-color-scheme: light)').matches,\n custom: (name: string) => window.matchMedia(`(prefers-color-scheme: ${name})`).matches,\n none: () => window.matchMedia('(prefers-color-scheme: no-preference)').matches,\n};\n\nconst LOCAL_PREF_KEY = 'ember-primitives/color-scheme#local-preference';\n\nexport const localPreference = {\n isSet: () => Boolean(localPreference.read()),\n read: () => localStorage.getItem(LOCAL_PREF_KEY),\n update: (value: string) => localStorage.setItem(LOCAL_PREF_KEY, value),\n delete: () => localStorage.removeItem(LOCAL_PREF_KEY),\n};\n\nexport function getColorScheme(element?: HTMLElement) {\n let style = styleOf(element);\n\n return style.getPropertyValue('color-scheme');\n}\n\nexport function setColorScheme(element: HTMLElement, value: string): void;\nexport function setColorScheme(value: string): void;\n\nexport function setColorScheme(...args: [string] | [HTMLElement, string]): void {\n if (typeof args[0] === 'string') {\n styleOf().setProperty('color-scheme', args[0]);\n\n return;\n }\n\n if (typeof args[1] === 'string') {\n styleOf(args[0]).setProperty('color-scheme', args[1]);\n }\n\n throw new Error(`Invalid arity, expected up to 2 args, received ${args.length}`);\n}\n\nexport function removeColorScheme(element?: HTMLElement) {\n let style = styleOf(element);\n\n style.removeProperty('color-scheme');\n}\n\nfunction styleOf(element?: HTMLElement) {\n if (element) {\n return element.style;\n }\n\n return document.documentElement.style;\n}\n"],"names":["_colorScheme","cell","colorScheme","update","value","current","localPreference","delete","setColorScheme","sync","isSet","pref","read","prefers","dark","light","window","matchMedia","matches","custom","name","none","LOCAL_PREF_KEY","Boolean","localStorage","getItem","setItem","removeItem","getColorScheme","element","style","styleOf","getPropertyValue","args","setProperty","Error","length","removeColorScheme","removeProperty","document","documentElement"],"mappings":";;AAEA,MAAMA,YAAY,GAAGC,IAAI,EAAsB,CAAA;AAExC,MAAMC,WAAW,GAAG;AACzBC,EAAAA,MAAM,EAAGC,KAAa,IAAMF,WAAW,CAACG,OAAO,GAAGD,KAAM;EAExD,IAAIC,OAAOA,GAAuB;IAChC,OAAOL,YAAY,CAACK,OAAO,CAAA;GAC5B;EACD,IAAIA,OAAOA,CAACD,KAAyB,EAAE;IACrCJ,YAAY,CAACK,OAAO,GAAGD,KAAK,CAAA;IAE5B,IAAI,CAACA,KAAK,EAAE;MACVE,eAAe,CAACC,MAAM,EAAE,CAAA;AAExB,MAAA,OAAA;AACF,KAAA;AAEAD,IAAAA,eAAe,CAACH,MAAM,CAACC,KAAK,CAAC,CAAA;IAC7BI,cAAc,CAACJ,KAAK,CAAC,CAAA;AACvB,GAAA;AACF,EAAC;AAEM,SAASK,IAAIA,GAAG;AACrB;AACF;AACA;AACE,EAAA,IAAIH,eAAe,CAACI,KAAK,EAAE,EAAE;AAC3B,IAAA,IAAIC,IAAI,GAAGL,eAAe,CAACM,IAAI,EAAE,CAAA;IAEjC,IAAID,IAAI,KAAK,MAAM,EAAE;MACnBH,cAAc,CAAC,MAAM,CAAC,CAAA;MAEtBR,YAAY,CAACK,OAAO,GAAG,MAAM,CAAA;AAE7B,MAAA,OAAA;AACF,KAAA;IAEAG,cAAc,CAAC,OAAO,CAAC,CAAA;IACvBR,YAAY,CAACK,OAAO,GAAG,OAAO,CAAA;AAE9B,IAAA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AC,cAAc,CAAC,CAAA;AAC/C,CAAA;AAKO,SAASxB,cAAcA,CAAC,GAAGyB,IAAsC,EAAQ;AAC9E,EAAA,IAAI,OAAOA,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;IAC/BF,OAAO,EAAE,CAACG,WAAW,CAAC,cAAc,EAAED,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;AAE9C,IAAA,OAAA;AACF,GAAA;AAEA,EAAA,IAAI,OAAOA,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;AAC/BF,IAAAA,OAAO,CAACE,IAAI,CAAC,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,cAAc,EAAED,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;AACvD,GAAA;EAEA,MAAM,IAAIE,KAAK,CAAE,CAAA,+CAAA,EAAiDF,IAAI,CAACG,MAAO,EAAC,CAAC,CAAA;AAClF,CAAA;AAEO,SAASC,iBAAiBA,CAACR,OAAqB,EAAE;AACvD,EAAA,IAAIC,KAAK,GAAGC,OAAO,CAACF,OAAO,CAAC,CAAA;AAE5BC,EAAAA,KAAK,CAACQ,cAAc,CAAC,cAAc,CAAC,CAAA;AACtC,CAAA;AAEA,SAASP,OAAOA,CAACF,OAAqB,EAAE;AACtC,EAAA,IAAIA,OAAO,EAAE;IACX,OAAOA,OAAO,CAACC,KAAK,CAAA;AACtB,GAAA;AAEA,EAAA,OAAOS,QAAQ,CAACC,eAAe,CAACV,KAAK,CAAA;AACvC;;;;"}
1
+ {"version":3,"file":"color-scheme.js","sources":["../src/color-scheme.ts"],"sourcesContent":["import { waitForPromise } from '@ember/test-waiters';\n\nimport { cell } from 'ember-resources';\n\nconst _colorScheme = cell<string | undefined>();\n\nlet callbacks: Set<WeakRef<(colorScheme: string) => void>> = new Set();\n\nasync function runCallbacks(theme: string) {\n await Promise.resolve();\n\n for (let ref of callbacks.values()) {\n let callback = ref.deref();\n\n if (!callback) {\n callbacks.delete(ref);\n } else {\n callback(theme);\n }\n }\n}\n\n/**\n * Callback to sync external systems, such as graphing or charting APIs with the theme system.\n *\n * There is no need to remove the callback like you would with `removeEventListener`.\n * It is managed with WeakRefs so memory is cleaned up automatically over time.\n */\nexport function onUpdate(callback: (colorScheme: string) => void) {\n callbacks.add(new WeakRef(callback));\n}\n\n/**\n * Object for managing the color scheme\n */\nexport const colorScheme = {\n /**\n * Set's the current color scheme to the passed value\n */\n update: (value: string) => {\n colorScheme.current = value;\n\n waitForPromise(runCallbacks(value));\n },\n\n /**\n * the current valuel of the \"color scheme\"\n */\n get current(): string | undefined {\n return _colorScheme.current;\n },\n set current(value: string | undefined) {\n _colorScheme.current = value;\n\n if (!value) {\n localPreference.delete();\n\n return;\n }\n\n localPreference.update(value);\n setColorScheme(value);\n },\n};\n\n/**\n * Synchronizes state of `colorScheme` with the users preferences as well as reconciles with previously set theme in local storage.\n *\n * This may only be called once per app.\n */\nexport function sync() {\n /**\n * reset the callbacks\n */\n callbacks = new Set();\n\n /**\n * If local prefs are set, then we don't care what prefers-color-scheme is\n */\n if (localPreference.isSet()) {\n let pref = localPreference.read();\n\n if (pref === 'dark') {\n setColorScheme('dark');\n\n _colorScheme.current = 'dark';\n\n return;\n }\n\n setColorScheme('light');\n _colorScheme.current = 'light';\n\n return;\n }\n\n if (prefers.dark()) {\n setColorScheme('dark');\n _colorScheme.current = 'dark';\n } else if (prefers.light()) {\n setColorScheme('light');\n _colorScheme.current = 'light';\n }\n}\n\n/**\n * Helper methods to determining what the user's preferred color scheme is\n */\nexport const prefers = {\n dark: () => window.matchMedia('(prefers-color-scheme: dark)').matches,\n light: () => window.matchMedia('(prefers-color-scheme: light)').matches,\n custom: (name: string) => window.matchMedia(`(prefers-color-scheme: ${name})`).matches,\n none: () => window.matchMedia('(prefers-color-scheme: no-preference)').matches,\n};\n\nconst LOCAL_PREF_KEY = 'ember-primitives/color-scheme#local-preference';\n\n/**\n * Helper methods for working with the color scheme preference in local storage\n */\nexport const localPreference = {\n isSet: () => Boolean(localPreference.read()),\n read: () => localStorage.getItem(LOCAL_PREF_KEY),\n update: (value: string) => localStorage.setItem(LOCAL_PREF_KEY, value),\n delete: () => localStorage.removeItem(LOCAL_PREF_KEY),\n};\n\n/**\n * For the given element, returns the `color-scheme` of that element.\n */\nexport function getColorScheme(element?: HTMLElement) {\n let style = styleOf(element);\n\n return style.getPropertyValue('color-scheme');\n}\n\nexport function setColorScheme(element: HTMLElement, value: string): void;\nexport function setColorScheme(value: string): void;\n\nexport function setColorScheme(...args: [string] | [HTMLElement, string]): void {\n if (typeof args[0] === 'string') {\n styleOf().setProperty('color-scheme', args[0]);\n\n return;\n }\n\n if (typeof args[1] === 'string') {\n styleOf(args[0]).setProperty('color-scheme', args[1]);\n\n return;\n }\n\n throw new Error(`Invalid arity, expected up to 2 args, received ${args.length}`);\n}\n\n/**\n * Removes the `color-scheme` from the given element\n */\nexport function removeColorScheme(element?: HTMLElement) {\n let style = styleOf(element);\n\n style.removeProperty('color-scheme');\n}\n\nfunction styleOf(element?: HTMLElement) {\n if (element) {\n return element.style;\n }\n\n return document.documentElement.style;\n}\n"],"names":["_colorScheme","cell","callbacks","Set","runCallbacks","theme","Promise","resolve","ref","values","callback","deref","delete","onUpdate","add","WeakRef","colorScheme","update","value","current","waitForPromise","localPreference","setColorScheme","sync","isSet","pref","read","prefers","dark","light","window","matchMedia","matches","custom","name","none","LOCAL_PREF_KEY","Boolean","localStorage","getItem","setItem","removeItem","getColorScheme","element","style","styleOf","getPropertyValue","args","setProperty","Error","length","removeColorScheme","removeProperty","document","documentElement"],"mappings":";;;AAIA,MAAMA,YAAY,GAAGC,IAAI,EAAsB,CAAA;AAE/C,IAAIC,SAAsD,GAAG,IAAIC,GAAG,EAAE,CAAA;AAEtE,eAAeC,YAAYA,CAACC,KAAa,EAAE;AACzC,EAAA,MAAMC,OAAO,CAACC,OAAO,EAAE,CAAA;EAEvB,KAAK,IAAIC,GAAG,IAAIN,SAAS,CAACO,MAAM,EAAE,EAAE;AAClC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Ae,CAACV,KAAK,CAAA;AACvC;;;;"}
@@ -1,22 +1,55 @@
1
+ /**
2
+ * Callback to sync external systems, such as graphing or charting APIs with the theme system.
3
+ *
4
+ * There is no need to remove the callback like you would with `removeEventListener`.
5
+ * It is managed with WeakRefs so memory is cleaned up automatically over time.
6
+ */
7
+ export declare function onUpdate(callback: (colorScheme: string) => void): void;
8
+ /**
9
+ * Object for managing the color scheme
10
+ */
1
11
  export declare const colorScheme: {
2
- update: (value: string) => string;
12
+ /**
13
+ * Set's the current color scheme to the passed value
14
+ */
15
+ update: (value: string) => void;
16
+ /**
17
+ * the current valuel of the "color scheme"
18
+ */
3
19
  current: string | undefined;
4
20
  };
21
+ /**
22
+ * Synchronizes state of `colorScheme` with the users preferences as well as reconciles with previously set theme in local storage.
23
+ *
24
+ * This may only be called once per app.
25
+ */
5
26
  export declare function sync(): void;
27
+ /**
28
+ * Helper methods to determining what the user's preferred color scheme is
29
+ */
6
30
  export declare const prefers: {
7
31
  dark: () => boolean;
8
32
  light: () => boolean;
9
33
  custom: (name: string) => boolean;
10
34
  none: () => boolean;
11
35
  };
36
+ /**
37
+ * Helper methods for working with the color scheme preference in local storage
38
+ */
12
39
  export declare const localPreference: {
13
40
  isSet: () => boolean;
14
41
  read: () => string | null;
15
42
  update: (value: string) => void;
16
43
  delete: () => void;
17
44
  };
45
+ /**
46
+ * For the given element, returns the `color-scheme` of that element.
47
+ */
18
48
  export declare function getColorScheme(element?: HTMLElement): string;
19
49
  export declare function setColorScheme(element: HTMLElement, value: string): void;
20
50
  export declare function setColorScheme(value: string): void;
51
+ /**
52
+ * Removes the `color-scheme` from the given element
53
+ */
21
54
  export declare function removeColorScheme(element?: HTMLElement): void;
22
55
  //# sourceMappingURL=color-scheme.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"color-scheme.d.ts","sourceRoot":"","sources":["../src/color-scheme.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW;oBACN,MAAM;;CAiBvB,CAAC;AAEF,wBAAgB,IAAI,SA4BnB;AAED,eAAO,MAAM,OAAO;;;mBAGH,MAAM;;CAEtB,CAAC;AAIF,eAAO,MAAM,eAAe;;;oBAGV,MAAM;;CAEvB,CAAC;AAEF,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,WAAW,UAInD;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;AAC1E,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;AAgBpD,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE,WAAW,QAItD"}
1
+ {"version":3,"file":"color-scheme.d.ts","sourceRoot":"","sources":["../src/color-scheme.ts"],"names":[],"mappings":"AAsBA;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,QAE/D;AAED;;GAEG;AACH,eAAO,MAAM,WAAW;IACtB;;OAEG;oBACa,MAAM;IAMtB;;OAEG;;CAgBJ,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,IAAI,SAiCnB;AAED;;GAEG;AACH,eAAO,MAAM,OAAO;;;mBAGH,MAAM;;CAEtB,CAAC;AAIF;;GAEG;AACH,eAAO,MAAM,eAAe;;;oBAGV,MAAM;;CAEvB,CAAC;AAEF;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,WAAW,UAInD;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;AAC1E,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;AAkBpD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE,WAAW,QAItD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-primitives",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Making apps easier to build",
5
5
  "sideEffects": [
6
6
  "*.css"
@@ -57,7 +57,7 @@
57
57
  "concurrently": "^8.2.2",
58
58
  "ember-modifier": "^4.1.0",
59
59
  "ember-resources": "^6.4.0",
60
- "ember-source": "~5.3.0",
60
+ "ember-source": "~5.4.0",
61
61
  "ember-template-imports": "^3.4.2",
62
62
  "ember-template-lint": "^5.11.2",
63
63
  "eslint": "^8.48.0",