@operato/p13n 8.0.0-beta.0 β†’ 8.0.0-beta.1

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/CHANGELOG.md CHANGED
@@ -3,6 +3,15 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [8.0.0-beta.1](https://github.com/hatiolab/operato/compare/v8.0.0-beta.0...v8.0.0-beta.1) (2025-01-08)
7
+
8
+
9
+ ### :bug: Bug Fix
10
+
11
+ * missing .npmignore ([be05985](https://github.com/hatiolab/operato/commit/be05985abfae4af53501f718dd52932099f7fbcb))
12
+
13
+
14
+
6
15
  ## [8.0.0-beta.0](https://github.com/hatiolab/operato/compare/v8.0.0-alpha.56...v8.0.0-beta.0) (2025-01-07)
7
16
 
8
17
  **Note:** Version bump only for package @operato/p13n
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@operato/p13n",
3
3
  "description": "Webcomponent personalization following open-wc recommendations",
4
4
  "author": "heartyoh",
5
- "version": "8.0.0-beta.0",
5
+ "version": "8.0.0-beta.1",
6
6
  "main": "dist/src/index.js",
7
7
  "module": "dist/src/index.js",
8
8
  "license": "MIT",
@@ -51,10 +51,10 @@
51
51
  "dependencies": {
52
52
  "@lit/context": "^1.1.2",
53
53
  "@material/web": "^2.0.0",
54
- "@operato/graphql": "^8.0.0-beta.0",
55
- "@operato/i18n": "^8.0.0-beta.0",
56
- "@operato/shell": "^8.0.0-beta.0",
57
- "@operato/utils": "^8.0.0-beta.0",
54
+ "@operato/graphql": "^8.0.0-beta.1",
55
+ "@operato/i18n": "^8.0.0-beta.1",
56
+ "@operato/shell": "^8.0.0-beta.1",
57
+ "@operato/utils": "^8.0.0-beta.1",
58
58
  "lit": "^3.1.2"
59
59
  },
60
60
  "devDependencies": {
@@ -89,5 +89,5 @@
89
89
  "prettier --write"
90
90
  ]
91
91
  },
92
- "gitHead": "c4e9cc245659d050a9ffd66542083a6daad4bcb9"
92
+ "gitHead": "d5b28a2e9deb632c0dc80132f6a7196dd6fe4220"
93
93
  }
package/.editorconfig DELETED
@@ -1,29 +0,0 @@
1
- # EditorConfig helps developers define and maintain consistent
2
- # coding styles between different editors and IDEs
3
- # editorconfig.org
4
-
5
- root = true
6
-
7
-
8
- [*]
9
-
10
- # Change these settings to your own preference
11
- indent_style = space
12
- indent_size = 2
13
-
14
- # We recommend you to keep these unchanged
15
- end_of_line = lf
16
- charset = utf-8
17
- trim_trailing_whitespace = true
18
- insert_final_newline = true
19
-
20
- [*.md]
21
- trim_trailing_whitespace = false
22
-
23
- [*.json]
24
- indent_size = 2
25
-
26
- [*.{html,js,md}]
27
- block_comment_start = /**
28
- block_comment = *
29
- block_comment_end = */
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- stories: ['../dist/stories/**/*.stories.{js,md,mdx}'],
3
- };
@@ -1,52 +0,0 @@
1
- import { i18next } from '@operato/i18n'
2
-
3
- export const globalTypes = {
4
- locale: {
5
- name: 'Locale',
6
- description: 'Internationalization locale',
7
- toolbar: {
8
- icon: 'globe',
9
- items: [
10
- { value: 'en', right: 'πŸ‡ΊπŸ‡Έ', title: 'English' },
11
- { value: 'ko', right: 'πŸ‡°πŸ‡·', title: 'ν•œκ΅­μ–΄' },
12
- { value: 'zh', right: 'πŸ‡¨πŸ‡³', title: 'δΈ­ζ–‡' },
13
- { value: 'ja', right: 'πŸ‡―πŸ‡΅', title: 'ζ—₯本θͺž' },
14
- { value: 'ms', right: 'πŸ‡²πŸ‡Ύ', title: 'Bahasa Melayu' }
15
- ],
16
- showName: true
17
- }
18
- },
19
- theme: {
20
- name: 'Theme',
21
- description: 'Global theme for components',
22
- toolbar: {
23
- icon: 'paintbrush',
24
- items: [
25
- { value: 'light', title: 'Light' },
26
- { value: 'dark', title: 'Dark' }
27
- ],
28
- showName: true
29
- }
30
- }
31
- }
32
-
33
- export const decorators = [
34
- (Story, context) => {
35
- const { locale, theme } = context.globals
36
-
37
- if (locale) {
38
- i18next.changeLanguage(locale)
39
- }
40
-
41
- // Set the theme class for the document
42
- if (theme === 'dark') {
43
- document.documentElement.classList.add('dark')
44
- document.documentElement.classList.remove('light')
45
- } else {
46
- document.documentElement.classList.add('light')
47
- document.documentElement.classList.remove('dark')
48
- }
49
-
50
- return Story()
51
- }
52
- ]
@@ -1,8 +0,0 @@
1
- import { storybookPlugin } from '@web/dev-server-storybook';
2
- import baseConfig from '../web-dev-server.config.mjs';
3
-
4
- export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
5
- ...baseConfig,
6
- open: '/',
7
- plugins: [storybookPlugin({ type: 'web-components' }), ...baseConfig.plugins],
8
- });
package/src/index.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from './types.js'
2
- export * from './p13n-mixin.js'
3
- export * from './ox-user-preferences-context.js'
4
- export * from './ox-user-preferences-provider.js'
5
- export * from './ox-user-preferences-consumer.js'
@@ -1,39 +0,0 @@
1
- import { LitElement, html } from 'lit'
2
- import { customElement, property } from 'lit/decorators.js'
3
- import { consume } from '@lit/context'
4
- import { OxUserPreferencesContext } from './ox-user-preferences-context'
5
-
6
- @customElement('ox-user-preferences-consumer')
7
- export class OxUserPreferenceConsumer extends LitElement {
8
- @property({ type: String }) userPreferenceKey = ''
9
- @property({ type: Object }) userPreference: any = null
10
-
11
- @consume({ context: OxUserPreferencesContext, subscribe: true })
12
- contextUserPreferences!: Map<string, any>
13
-
14
- async connectedCallback() {
15
- super.connectedCallback()
16
- this.userPreference = this.contextUserPreferences.get(this.userPreferenceKey)
17
- }
18
-
19
- updateUserPreference(newPreference: any) {
20
- if (this.contextUserPreferences) {
21
- this.contextUserPreferences.set(this.userPreferenceKey, newPreference)
22
- }
23
- const event = new CustomEvent('user-preference-update', {
24
- detail: { key: this.userPreferenceKey, preference: newPreference },
25
- bubbles: true,
26
- composed: true
27
- })
28
- this.dispatchEvent(event)
29
- }
30
-
31
- render() {
32
- return html`
33
- <div>
34
- ${this.userPreferenceKey}: ${JSON.stringify(this.userPreference?.preference || {})}
35
- <button @click="${() => this.updateUserPreference({ someKey: 'newValue' })}">Update</button>
36
- </div>
37
- `
38
- }
39
- }
@@ -1,3 +0,0 @@
1
- import { createContext } from '@lit/context'
2
-
3
- export const OxUserPreferencesContext = createContext<Map<string, any>>('user-preferences')
@@ -1,58 +0,0 @@
1
- import { LitElement, html, css } from 'lit'
2
- import { customElement, property } from 'lit/decorators.js'
3
- import { provide } from '@lit/context'
4
- import { OxUserPreferencesContext } from './ox-user-preferences-context'
5
- import { UserPreferencesService } from './user-preferences-service'
6
-
7
- @customElement('ox-user-preferences-provider')
8
- export class OxUserPreferencesProvider extends LitElement {
9
- static styles = css`
10
- :host {
11
- display: flex;
12
- }
13
- `
14
-
15
- @property({ type: Object })
16
- @provide({ context: OxUserPreferencesContext })
17
- private userPreferences = new Map<string, any>()
18
-
19
- @property({ type: Boolean, attribute: 'load-initial-preferences' }) loadInitialPreferences = false
20
-
21
- private userPreferencesService = new UserPreferencesService()
22
-
23
- connectedCallback() {
24
- super.connectedCallback()
25
- if (this.loadInitialPreferences) {
26
- this.fetchInitialPreferences()
27
- }
28
- }
29
-
30
- async fetchInitialPreferences() {
31
- await this.userPreferencesService.fetchInitialPreferences()
32
- this.userPreferences = this.userPreferencesService.userPreferences
33
- this.requestUpdate()
34
- }
35
-
36
- async getPreference(key: string): Promise<any> {
37
- const preference = await this.userPreferencesService.getPreference(key)
38
- this.userPreferences = this.userPreferencesService.userPreferences
39
-
40
- this.requestUpdate()
41
- return preference
42
- }
43
-
44
- async updatePreference(key: string, newPreference: any) {
45
- await this.userPreferencesService.updatePreference(key, newPreference)
46
- this.userPreferences = this.userPreferencesService.userPreferences
47
- this.requestUpdate()
48
- }
49
-
50
- handleUserPreferenceUpdate(event: CustomEvent) {
51
- const { key, preference } = event.detail
52
- this.updatePreference(key, preference)
53
- }
54
-
55
- render() {
56
- return html` <slot @user-preference-update="${this.handleUserPreferenceUpdate}"></slot> `
57
- }
58
- }
package/src/p13n-mixin.ts DELETED
@@ -1,142 +0,0 @@
1
- import gql from 'graphql-tag'
2
- import { PageView } from '@operato/shell'
3
- import { i18next } from '@operato/i18n'
4
- import { client } from '@operato/graphql'
5
- import { getPathInfo } from '@operato/utils'
6
- import { PagePreferenceProvider } from './types'
7
-
8
- type Constructor<T> = new (...args: any[]) => T
9
- interface CustomElement {}
10
-
11
- const PagePreferences: {
12
- [page: string]: Promise<{
13
- __timestamp: number
14
- [element: string]: any
15
- }>
16
- } = {}
17
-
18
- export const p13n = <T extends Constructor<CustomElement>>(base: T) =>
19
- class extends base {
20
- __preferenceProviders = {} as { [element: string]: PagePreferenceProvider }
21
-
22
- getPagePreferenceProvider(element: string) {
23
- if (!element) {
24
- return
25
- }
26
-
27
- if (this.__preferenceProviders[element]) {
28
- return this.__preferenceProviders[element]
29
- }
30
-
31
- if (this instanceof PageView) {
32
- var page = (this as PageView).lifecycle.page!
33
- } else {
34
- const { pathname } = window.location
35
- const { path } = getPathInfo(pathname)
36
- var page = path?.split('/')[1] || '/'
37
- }
38
-
39
- this.__preferenceProviders[element] = {
40
- load: async (): Promise<any> => {
41
- /* cacheλ₯Ό ν•˜λ£¨λ§Œ μœ μ§€ν•˜λ„λ‘ 함. (λͺ¨λ°”일은 μ˜€λž«λ™μ•ˆ μ–΄ν”Œλ¦¬μΌ€μ΄μ…˜μ„ λ¦¬ν”„λ ˆμ‹œν•˜μ§€ μ•Šμ„ 수 μžˆμ–΄μ„œ, μΊμ‹œλ₯Ό μ˜€λž«λ™μ•ˆ μœ μ§€ν•  수 μžˆμœΌλ―€λ‘œ) */
42
- if (!PagePreferences[page] || (await PagePreferences[page]).__timestamp < Date.now() - 60 * 60 * 24 * 1000) {
43
- PagePreferences[page] = new Promise<any>(resolve => {
44
- client
45
- .query({
46
- query: gql`
47
- query ($page: String!) {
48
- myPageAllPreferences(page: $page) {
49
- element
50
- preference
51
- }
52
- }
53
- `,
54
- variables: {
55
- page
56
- }
57
- })
58
- .then(response => {
59
- if (!response.errors) {
60
- resolve(
61
- response.data.myPageAllPreferences?.reduce(
62
- (sum: any, pagePreference: { element: string; preference: any }) => {
63
- sum[pagePreference.element] = pagePreference.preference
64
- return sum
65
- },
66
- {
67
- __timestamp: Date.now()
68
- }
69
- )
70
- )
71
- }
72
- })
73
- })
74
- }
75
-
76
- return (await PagePreferences[page])?.[element] || {}
77
- },
78
-
79
- save: async (preference: any): Promise<any> => {
80
- const response = await client.mutate({
81
- mutation: gql`
82
- mutation ($page: String!, $element: String!, $preference: Object!) {
83
- updateMyPagePreference(page: $page, element: $element, preference: $preference) {
84
- preference
85
- }
86
- }
87
- `,
88
- variables: {
89
- page,
90
- element,
91
- preference
92
- }
93
- })
94
-
95
- if (!response.errors) {
96
- document.dispatchEvent(
97
- new CustomEvent('notify', {
98
- detail: { message: i18next.t('text.updated_successfully'), option: { timer: 3000 } }
99
- })
100
- )
101
-
102
- if (!PagePreferences[page]) {
103
- PagePreferences[page] = new Promise<any>(resolve => resolve({}))
104
- }
105
-
106
- const preference = await PagePreferences[page]
107
- if (preference) {
108
- preference[element] = response.data.updateMyPagePreference.preference
109
- }
110
-
111
- return (await PagePreferences[page])?.[element]
112
- }
113
- },
114
-
115
- reset: async (): Promise<void> => {
116
- const response = await client.mutate({
117
- mutation: gql`
118
- mutation ($page: String!, $element: String!) {
119
- deleteMyPagePreference(page: $page, element: $element)
120
- }
121
- `,
122
- variables: {
123
- page,
124
- element
125
- }
126
- })
127
-
128
- if (!response.errors) {
129
- document.dispatchEvent(
130
- new CustomEvent('notify', {
131
- detail: { message: i18next.t('text.updated_successfully'), option: { timer: 3000 } }
132
- })
133
- )
134
-
135
- delete PagePreferences[page] /* cacheλ₯Ό updateν•  기회λ₯Ό μ£ΌκΈ°μœ„ν•΄μ„œ, promiseλ₯Ό clearμ‹œν‚΄ */
136
- }
137
- }
138
- }
139
-
140
- return this.__preferenceProviders[element]
141
- }
142
- }
package/src/types.ts DELETED
@@ -1,9 +0,0 @@
1
- export interface PagePreferenceProvider {
2
- page?: string
3
- element?: string
4
- preference?: any
5
-
6
- load: () => any | Promise<any>
7
- save: (preference: any) => any | Promise<any>
8
- reset: () => void | Promise<void>
9
- }
@@ -1,72 +0,0 @@
1
- import { client } from '@operato/graphql'
2
- import gql from 'graphql-tag'
3
-
4
- const GET_USER_PREFERENCE = gql`
5
- query GetUserPreference($key: String!) {
6
- myUserPreference(key: $key) {
7
- id
8
- key
9
- preference
10
- }
11
- }
12
- `
13
-
14
- const GET_INITIAL_PREFERENCES = gql`
15
- query GetInitialPreferences {
16
- myUserPreferences {
17
- items {
18
- id
19
- key
20
- preference
21
- }
22
- total
23
- }
24
- }
25
- `
26
-
27
- const UPDATE_MY_USER_PREFERENCE = gql`
28
- mutation UpdateMyUserPreference($key: String!, $preference: Object!) {
29
- updateMyUserPreference(key: $key, preference: $preference) {
30
- id
31
- key
32
- preference
33
- }
34
- }
35
- `
36
-
37
- export class UserPreferencesService {
38
- public userPreferences = new Map<string, any>()
39
-
40
- async fetchInitialPreferences() {
41
- const result = await client.query({ query: GET_INITIAL_PREFERENCES })
42
- result.data.myUserPreferences.items.forEach((pref: any) => {
43
- this.userPreferences.set(pref.key, pref.preference)
44
- })
45
- }
46
-
47
- async getPreference(key: string): Promise<any> {
48
- if (this.userPreferences.has(key)) {
49
- return this.userPreferences.get(key)
50
- }
51
-
52
- const result = await client.query({
53
- query: GET_USER_PREFERENCE,
54
- variables: { key }
55
- })
56
-
57
- const { preference } = result.data.myUserPreference
58
- this.userPreferences.set(key, preference)
59
-
60
- return preference
61
- }
62
-
63
- async updatePreference(key: string, newPreference: any) {
64
- const result = await client.mutate({
65
- mutation: UPDATE_MY_USER_PREFERENCE,
66
- variables: { key, preference: newPreference }
67
- })
68
-
69
- const { preference } = result.data.updateMyUserPreference
70
- this.userPreferences.set(key, preference)
71
- }
72
- }
package/tsconfig.json DELETED
@@ -1,24 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2018",
4
- "module": "esnext",
5
- "moduleResolution": "node",
6
- "noEmitOnError": true,
7
- "lib": ["es2017", "dom"],
8
- "strict": true,
9
- "esModuleInterop": false,
10
- "allowSyntheticDefaultImports": true,
11
- "experimentalDecorators": true,
12
- "useDefineForClassFields": false,
13
- "importHelpers": true,
14
- "outDir": "dist",
15
- "sourceMap": true,
16
- "inlineSources": true,
17
- "rootDir": "./",
18
- "declaration": true,
19
- "incremental": true,
20
- "skipLibCheck": true,
21
- "types": ["node", "mocha"]
22
- },
23
- "include": ["**/*.ts"]
24
- }
@@ -1,27 +0,0 @@
1
- // import { hmrPlugin, presets } from '@open-wc/dev-server-hmr';
2
-
3
- /** Use Hot Module replacement by adding --hmr to the start command */
4
- const hmr = process.argv.includes('--hmr');
5
-
6
- export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
7
- open: '/demo/',
8
- /** Use regular watch mode if HMR is not enabled. */
9
- watch: !hmr,
10
- /** Resolve bare module imports */
11
- nodeResolve: {
12
- exportConditions: ['browser', 'development'],
13
- },
14
-
15
- /** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
16
- // esbuildTarget: 'auto'
17
-
18
- /** Set appIndex to enable SPA routing */
19
- // appIndex: 'demo/index.html',
20
-
21
- plugins: [
22
- /** Use Hot Module Replacement by uncommenting. Requires @open-wc/dev-server-hmr plugin */
23
- // hmr && hmrPlugin({ exclude: ['**/*/node_modules/**/*'], presets: [presets.litElement] }),
24
- ],
25
-
26
- // See documentation for all available options
27
- });
@@ -1,41 +0,0 @@
1
- // import { playwrightLauncher } from '@web/test-runner-playwright';
2
-
3
- const filteredLogs = ['Running in dev mode', 'lit-html is in dev mode'];
4
-
5
- export default /** @type {import("@web/test-runner").TestRunnerConfig} */ ({
6
- /** Test files to run */
7
- files: 'dist/test/**/*.test.js',
8
-
9
- /** Resolve bare module imports */
10
- nodeResolve: {
11
- exportConditions: ['browser', 'development'],
12
- },
13
-
14
- /** Filter out lit dev mode logs */
15
- filterBrowserLogs(log) {
16
- for (const arg of log.args) {
17
- if (typeof arg === 'string' && filteredLogs.some(l => arg.includes(l))) {
18
- return false;
19
- }
20
- }
21
- return true;
22
- },
23
-
24
- /** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
25
- // esbuildTarget: 'auto',
26
-
27
- /** Amount of browsers to run concurrently */
28
- // concurrentBrowsers: 2,
29
-
30
- /** Amount of test files per browser to test concurrently */
31
- // concurrency: 1,
32
-
33
- /** Browsers to run tests on */
34
- // browsers: [
35
- // playwrightLauncher({ product: 'chromium' }),
36
- // playwrightLauncher({ product: 'firefox' }),
37
- // playwrightLauncher({ product: 'webkit' }),
38
- // ],
39
-
40
- // See documentation for all available options
41
- });